Пример #1
0
		#pragma warning disable 0169
		
		int TransparencyKeySnooper (IntPtr widget, IntPtr rawEvnt, IntPtr data)
		{
			if (rawEvnt != IntPtr.Zero) {
				Gdk.EventKey evnt = new Gdk.EventKey (rawEvnt);
				if (evnt != null && evnt.Key == Gdk.Key.Control_L || evnt.Key == Gdk.Key.Control_R)
					SemiTransparent = (evnt.Type == Gdk.EventType.KeyPress);
			}
			return 0; //gboolean FALSE
		}
Пример #2
0
 /// <summary>
 /// Checks whether a keypress is a control+space event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 /// <returns>True iff the event represents a control+space click.</returns>
 private bool IsControlSpace(Gdk.EventKey e)
 {
     return(Gdk.Keyval.ToUnicode(e.KeyValue) == ' ' && (e.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask);
 }
Пример #3
0
		protected override bool OnTextEvent (GLib.Object  sender,
		                                     Gdk.Event    ev,
		                                     Gtk.TextIter iter)
		{
			NoteEditor editor = (NoteEditor) sender;
			Gtk.TextIter start, end;

			if (!CanActivate)
				return false;

			switch (ev.Type) {
			case Gdk.EventType.ButtonPress:
				Gdk.EventButton button_ev = new Gdk.EventButton (ev.Handle);

				// Do not insert selected text when activating links with
				// middle mouse button
				if (button_ev.Button == 2) {
					allow_middle_activate = true;
					return true;
				}

				return false;

			case Gdk.EventType.ButtonRelease:
				button_ev = new Gdk.EventButton (ev.Handle);

				if (button_ev.Button != 1 && button_ev.Button != 2)
					return false;

				/* Don't activate if Shift or Control is pressed */
				if ((int) (button_ev.State & (Gdk.ModifierType.ShiftMask |
				                              Gdk.ModifierType.ControlMask)) != 0)
					return false;

				// Prevent activation when selecting links with the mouse
				if (editor.Buffer.HasSelection)
					return false;

				// Don't activate if the link has just been pasted with the
				// middle mouse button (no preceding ButtonPress event)
				if (button_ev.Button == 2 && !allow_middle_activate)
					return false;
				else
					allow_middle_activate = false;

				GetExtents (iter, out start, out end);
				bool success = OnActivate (editor, start, end);

				// Hide note if link is activated with middle mouse button
				if (success && button_ev.Button == 2) {
					Gtk.Widget widget = (Gtk.Widget) sender;
					widget.Toplevel.Hide ();
				}

				return false;

			case Gdk.EventType.KeyPress:
				Gdk.EventKey key_ev = new Gdk.EventKey (ev.Handle);

				// Control-Enter activates the link at point...
				if ((int) (key_ev.State & Gdk.ModifierType.ControlMask) == 0)
					return false;

				if (key_ev.Key != Gdk.Key.Return &&
				                key_ev.Key != Gdk.Key.KP_Enter)
					return false;

				GetExtents (iter, out start, out end);
				return OnActivate (editor, start, end);
			}

			return false;
		}
Пример #4
0
        bool ProcessKeyPressEvent(Gdk.EventKey ev)
        {
            // Short circuit to avoid getting moved back to the input line
            // when paging up and down in the shell output
            if (ev.Key == Gdk.Key.Page_Up || ev.Key == Gdk.Key.Page_Down)
            {
                return(false);
            }

            // Needed so people can copy and paste, but always end up
            // typing in the prompt.
            if (Cursor.Compare(InputLineBegin) < 0)
            {
                Buffer.MoveMark(Buffer.SelectionBound, InputLineEnd);
                Buffer.MoveMark(Buffer.InsertMark, InputLineEnd);
            }

//			if (ev.State == Gdk.ModifierType.ControlMask && ev.Key == Gdk.Key.space)
//				TriggerCodeCompletion ();

            if (ev.Key == Gdk.Key.Return)
            {
                if (inBlock)
                {
                    if (InputLine == "")
                    {
                        ProcessInput(blockText);
                        blockText = "";
                        inBlock   = false;
                    }
                    else
                    {
                        blockText += "\n" + InputLine;
                        string whiteSpace = null;
                        if (AutoIndent)
                        {
                            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\s+).*");
                            whiteSpace = r.Replace(InputLine, "$1");
                            if (InputLine.EndsWith(BlockStart))
                            {
                                whiteSpace += "\t";
                            }
                        }
                        Prompt(true, true);
                        if (AutoIndent)
                        {
                            InputLine += whiteSpace;
                        }
                    }
                }
                else
                {
                    // Special case for start of new code block
                    if (!string.IsNullOrEmpty(BlockStart) && InputLine.Trim().EndsWith(BlockStart))
                    {
                        inBlock   = true;
                        blockText = InputLine;
                        Prompt(true, true);
                        if (AutoIndent)
                        {
                            InputLine += "\t";
                        }
                        return(true);
                    }
                    // Bookkeeping
                    if (InputLine != "")
                    {
                        // Everything but the last item (which was input),
                        //in the future stack needs to get put back into the
                        // past stack
                        while (commandHistoryFuture.Count > 1)
                        {
                            commandHistoryPast.Push(commandHistoryFuture.Pop());
                        }
                        // Clear the pesky junk input line
                        commandHistoryFuture.Clear();

                        // Record our input line
                        commandHistoryPast.Push(InputLine);
                        if (scriptLines == "")
                        {
                            scriptLines += InputLine;
                        }
                        else
                        {
                            scriptLines += "\n" + InputLine;
                        }

                        ProcessInput(InputLine);
                    }
                }
                return(true);
            }

            // The next two cases handle command history
            else if (ev.Key == Gdk.Key.Up)
            {
                if (!inBlock && commandHistoryPast.Count > 0)
                {
                    if (commandHistoryFuture.Count == 0)
                    {
                        commandHistoryFuture.Push(InputLine);
                    }
                    else
                    {
                        if (commandHistoryPast.Count == 1)
                        {
                            return(true);
                        }
                        commandHistoryFuture.Push(commandHistoryPast.Pop());
                    }
                    InputLine = commandHistoryPast.Peek();
                }
                return(true);
            }
            else if (ev.Key == Gdk.Key.Down)
            {
                if (!inBlock && commandHistoryFuture.Count > 0)
                {
                    if (commandHistoryFuture.Count == 1)
                    {
                        InputLine = commandHistoryFuture.Pop();
                    }
                    else
                    {
                        commandHistoryPast.Push(commandHistoryFuture.Pop());
                        InputLine = commandHistoryPast.Peek();
                    }
                }
                return(true);
            }
            else if (ev.Key == Gdk.Key.Left)
            {
                // Keep our cursor inside the prompt area
                if (Cursor.Compare(InputLineBegin) <= 0)
                {
                    return(true);
                }
            }
            else if (ev.Key == Gdk.Key.Home)
            {
                Buffer.MoveMark(Buffer.InsertMark, InputLineBegin);
                // Move the selection mark too, if shift isn't held
                if ((ev.State & Gdk.ModifierType.ShiftMask) == ev.State)
                {
                    Buffer.MoveMark(Buffer.SelectionBound, InputLineBegin);
                }
                return(true);
            }
            else if (ev.Key == Gdk.Key.period)
            {
                return(false);
            }

            // Short circuit to avoid getting moved back to the input line
            // when paging up and down in the shell output
            else if (ev.Key == Gdk.Key.Page_Up || ev.Key == Gdk.Key.Page_Down)
            {
                return(false);
            }

            return(false);
        }
Пример #5
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            if (Cursor.Compare(InputLineBegin) < 0)
            {
                Buffer.MoveMark(Buffer.SelectionBound, InputLineEnd);
                Buffer.MoveMark(Buffer.InsertMark, InputLineEnd);
            }

            switch (evnt.Key)
            {
            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                string input_line = InputLine;
                history [history.Count - 1] = input_line;
                history_cursor = history.Count;

                string expr_copy = expr = GetCurrentExpression();

                // Insert a new line before we evaluate.
                TextIter end = Buffer.EndIter;
                Buffer.InsertWithTagsByName(ref end, "\n", "Stdout");

                if (Evaluate(expr))
                {
                    if (expr_copy != input_line)
                    {
                        history.Add(expr_copy);
                        history_cursor = history.Count;
                    }
                }
                history.Add("");
                DumpHistory();
                if (InteractiveBase.QuitRequested && QuitRequested != null)
                {
                    QuitRequested(this, EventArgs.Empty);
                }
                return(true);

            case Gdk.Key.Up:
                if (history_cursor == 0)
                {
                    DumpHistory();
                    return(true);
                }
                string input = InputLine;
                if (!String.IsNullOrEmpty(input))
                {
                    DumpHistory();
                    history [history_cursor] = input;
                }
                history_cursor--;
                InputLine = (string)history [history_cursor];
                DumpHistory();
                return(true);

            case Gdk.Key.Down:
                if (history_cursor + 1 >= history.Count)
                {
                    DumpHistory();
                    return(true);
                }
                history_cursor++;
                InputLine = (string)history [history_cursor];
                DumpHistory();
                return(true);

            case Gdk.Key.Left:
                if (Cursor.Compare(InputLineBegin) <= 0)
                {
                    return(true);
                }
                break;

            case Gdk.Key.Home:
                Buffer.MoveMark(Buffer.InsertMark, InputLineBegin);
                if ((evnt.State & Gdk.ModifierType.ShiftMask) != Gdk.ModifierType.ShiftMask)
                {
                    Buffer.MoveMark(Buffer.SelectionBound, InputLineBegin);
                }
                return(true);

            case Gdk.Key.Tab:
                string    saved_text = InputLine;
                string    prefix;
                string [] completions = evaluator.GetCompletions(LineUntilCursor, out prefix);
                if (completions == null)
                {
                    return(true);
                }

                if (completions.Length == 1)
                {
                    TextIter cursor = Cursor;
                    Buffer.Insert(ref cursor, completions [0]);
                    return(true);
                }

                Console.WriteLine();
                foreach (var s in completions)
                {
                    Console.Write(prefix);
                    Console.Write(s);
                    Console.Write(" ");
                }
                // Insert a new line before we evaluate.
                end = Buffer.EndIter;
                Buffer.InsertWithTagsByName(ref end, "\n", "Stdout");
                ShowPrompt(false);
                InputLine = saved_text;
#if false
                Gtk.TextIter start = Cursor;
                if (prefix.Length != 0)
                {
                    MoveVisually(ref start, -prefix.Length);
                }
                int x, y;
                GdkWindow.GetOrigin(out x, out y);
                var r = GetIterLocation(start);
                x += r.X;
                y += r.Y;
                var w = new Gtk.Window(WindowType.Popup);
                w.SetUposition(x, y);
                w.SetUsize(100, 100);
                foreach (var s in completions)
                {
                    Console.WriteLine("{0}[{1}]", prefix, s);
                }
                w.ShowAll();
                Console.WriteLine("Position: x={0} y={1}", x + r.X, y + r.Y);
#endif
                return(true);

            default:
                break;
            }

            return(base.OnKeyPressEvent(evnt));
        }
Пример #6
0
 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
 {
     return(false);
 }
Пример #7
0
 internal bool HandleKeyPress(Gdk.EventKey evnt)
 {
     return(this.OnKeyPressEvent(evnt));
 }
Пример #8
0
        private void OnPopupKeyPressed(object sender, KeyPressEventArgs args)
        {
            bool search_forward  = false;
            bool search_backward = false;

            Gdk.EventKey press = args.Event;
            Gdk.Key      key   = press.Key;

            switch (key)
            {
            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                search_backward = true;
                break;

            case Gdk.Key.g:
            case Gdk.Key.G:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                    {
                        search_backward = true;
                    }
                    else
                    {
                        search_forward = true;
                    }
                }
                break;

            case Gdk.Key.F3:
            case Gdk.Key.KP_F3:
                if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    search_backward = true;
                }
                else
                {
                    search_forward = true;
                }
                break;

            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                search_forward = true;
                break;
            }

            if (search_forward)
            {
                previous_search_offset = search_offset++;
                if (!PerformSearch(search_popup.Text))
                {
                    search_offset = previous_search_offset;
                }
            }
            else if (search_backward)
            {
                search_offset = search_offset == 0 ? 0 : search_offset - 1;
                PerformSearch(search_popup.Text);
            }

            args.RetVal = search_forward || search_backward;
        }
Пример #9
0
 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
 {
     return(entry.HandleKeyPress(evnt));
 }
Пример #10
0
        void OnKeyDefault(Gdk.EventKey e, ref Position cur, ref Position next, out bool specialKey)
        {
            if (!dataView.Buffer.ModifyAllowed)
            {
                specialKey = true;
                return;
            }

            // if the buffer isn't resizable, ignore non-overwriting keypresses
            if (!dataView.Buffer.IsResizable && !dataView.Overwrite)
            {
                specialKey = true;
                return;
            }

            if (dataView.Selection.IsEmpty())
            {
                if (imContext.FilterKeypress(e) && okp_focusArea.HandleKey(e.Key, dataView.Overwrite) == true)
                {
                    OnKeyRight(ref cur, ref next);
                    dataView.CursorUndoDeque.AddFront(new CursorState(cur.Second, cur.Digit, next.Second, next.Digit));

                    dataView.CursorRedoDeque.Clear();

                    selStartPos = selEndPos = next;
                    specialKey  = false;
                }
                else
                {
                    specialKey = true;
                }
            }
            else
            {
                dataView.Buffer.BeginActionChaining();

                // Insert the new data and delete the old
                if (imContext.FilterKeypress(e) && okp_focusArea.HandleKey(e.Key, false) == true)
                {
                    Util.Range curSel    = dataView.Selection;
                    long       curOffset = dataView.CursorOffset;

                    // move cursor to the right
                    OnKeyRight(ref cur, ref next);

                    next.First = next.Second = curSel.Start;
                    selEndPos  = selStartPos = next;

                    // the new data could have been inserted either just after the end
                    // or at the beginning of the selection. Handle each case
                    // and delete the old data.
                    if (curOffset > curSel.End)               // new data just after end
                    {
                        dataView.Delete();
                    }
                    else               // curOffset == curSel.Start, new data at the beginning
                                       // shift selection one position to the right
                    {
                        dataView.SetSelection(curSel.Start + 1, curSel.End + 1);
                        dataView.Delete();
                    }

                    specialKey = false;
                }
                else
                {
                    specialKey = true;
                }

                dataView.Buffer.EndActionChaining();
            }
            // any other key pass it to focused area
            // if area handled it move one position right
        }
Пример #11
0
        ///<summary>Handle key presses</summary>
        internal void OnKeyPress(object o, KeyPressEventArgs args)
        {
            Gdk.EventKey e = args.Event;

            okp_focusArea = null;
            bool shiftPressed = false;

            // find focused area
            okp_focusArea = dvDisplay.Layout.AreaGroup.FocusedArea;

            // if no area has the focus, give it to the first one applicable
            if (okp_focusArea == null)
            {
                dvDisplay.Layout.AreaGroup.CycleFocus();
                okp_focusArea = dvDisplay.Layout.AreaGroup.FocusedArea;
            }


            // if still no area got the focus give up
            if (okp_focusArea == null)
            {
                return;
            }

            okp_bpr      = okp_focusArea.BytesPerRow;
            okp_dpb      = okp_focusArea.DigitsPerByte;
            okp_showType = DataViewDisplay.ShowType.Closest;

            if ((e.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask)
            {
                shiftPressed = true;
            }

            UpdateSelection(true);

            Position cur = new Position();

            if (shiftPressed || !dvDisplay.Layout.AreaGroup.Selection.IsEmpty())
            {
                cur       = selEndPos;
                cur.Digit = 0;
            }
            else
            {
                cur = selStartPos;
            }

            Position next = new Position();

            // set next to cur in case it is not set by a keypress handler
            next = cur;

            // handle keys
            bool specialKey = false;

            switch (e.Key)
            {
            case Gdk.Key.Up:
                OnKeyUp(ref cur, ref next);
                break;

            case Gdk.Key.Down:
                OnKeyDown(ref cur, ref next);
                break;

            case Gdk.Key.Left:
                OnKeyLeft(ref cur, ref next);
                break;

            case Gdk.Key.Right:
                if (shiftPressed)
                {
                    cur.Digit = okp_dpb - 1;
                }
                OnKeyRight(ref cur, ref next);
                break;

            case Gdk.Key.Page_Up:
                OnKeyPageUp(ref cur, ref next);
                break;

            case Gdk.Key.Page_Down:
                OnKeyPageDown(ref cur, ref next);
                break;

            case Gdk.Key.Home:
                OnKeyHome(ref cur, ref next);
                break;

            case Gdk.Key.End:
                OnKeyEnd(ref cur, ref next);
                break;

            case Gdk.Key.Insert:
                OnKeyInsert();
                break;

            case Gdk.Key.Tab:
                OnKeyTab();
                // cycling through the areas may change the current cursor digit
                // (note however that we don't want to call EvaluateSelection()->SetCursor()
                //  because that will reset the digit of all areas. So we just update
                //  selStartPos.Digit here and set specialKey = true to avoid calling SetCursor()...)
                selStartPos.Digit = dvDisplay.Layout.AreaGroup.CursorDigit;
                specialKey        = true;
                break;

            case Gdk.Key.BackSpace:
                OnKeyBackspace();
                return;                 // OnKeyBackspace() handles drawing

            default:
                OnKeyDefault(e, ref cur, ref next, out specialKey);
                break;
            }     // end switch()
                  //System.Console.WriteLine("Current: {0},{1},{2} Next: {3},{4},{5}", cur.First, cur.Second, cur.Digit, next.First, next.Second, next.Digit);

            // if just a special key was pressed (eg shift, ctrl, tab or a digit the area doesn't understand don't do anything)
            if (specialKey)
            {
                return;
            }

            if (shiftPressed)
            {
                next.Digit = 0;
                if (selStartPos.First == selStartPos.Second)
                {
                    selStartPos.First--;
                }
                selEndPos = next;
            }
            else
            {
                selEndPos   = next;
                selStartPos = next;
            }
            //System.Console.WriteLine("Start: {0},{1},{2} End: {3},{4},{5}", selStartPos.First, selStartPos.Second, selStartPos.Digit, selEndPos.First, selEndPos.Second, selEndPos.Digit);
            EvaluateSelection(okp_showType);
        }
Пример #12
0
 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
 {
     SSH.ShellSend(evnt.Key);
     return(base.OnKeyPressEvent(evnt));
 }
Пример #13
0
        bool Space(Gdk.EventKey ev)
        {
//          if (ev.State == Gdk.ModifierType.ControlMask && ev.Key == Gdk.Key.space)
//              TriggerCodeCompletion ();
            return(false);
        }
Пример #14
0
 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
 {
     ProcessKey(evnt.Key, evnt.State);
     return(base.OnKeyPressEvent(evnt));
 }
Пример #15
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            int  index    = -1;
            int  sel_stop = -1;
            bool ret      = false;

            this.GetSelectionBounds(out index, out sel_stop);
            //disable multi-selection
            if (sel_stop != index)
            {
                return(false);
            }
            bool enter_val = false;

            //verify if cursor is between 0 and formatTypes.count
            if (index >= 0 && index < FormatTypes.Count)
            {
                //verify inserted value
                CharType type = FormatTypes[index];
                if (type != CharType.Fixed)
                {
                    char key = (char)evnt.KeyValue;
                    if (type == CharType.AnyLetterDigit && this.isAnyLetterDigit(key))
                    {
                        enter_val = true;
                    }
                    if (type == CharType.Digit && this.isDigit(key))
                    {
                        enter_val = true;
                    }
                    if (type == CharType.Double && this.isDouble(key))
                    {
                        enter_val = true;
                    }
                    if (type == CharType.Letter && this.isLetter(key))
                    {
                        enter_val = true;
                    }
                    if (type == CharType.LowerCaseLetter && this.isLowerCaseLetter(key))
                    {
                        enter_val = true;
                    }
                    if (type == CharType.UpperCaseLetter && this.isUpperCaseLetter(key))
                    {
                        enter_val = true;
                    }
                    if (enter_val)
                    {
                        ret       = base.OnKeyPressEvent(evnt);
                        this.Text = this.Text.Remove(index + 1, 1);
                    }
                }
                else
                {
                    enter_val = true;
                }
                //skip into next non-fixed
                if (enter_val)
                {
                    for (int i = index + 1; i < FormatTypes.Count; i++)
                    {
                        type = FormatTypes[i];
                        if (type != CharType.Fixed)
                        {
                            this.SelectRegion(i, i);
                            break;
                        }
                    }
                }
            }
            return(ret);
        }
Пример #16
0
 bool Left(Gdk.EventKey ev)
 {
     // Keep our cursor inside the prompt area
     return(Cursor.Compare(InputLineBegin) <= 0);
 }
Пример #17
0
        protected override bool OnKeyPressEvent(Gdk.EventKey ev)
        {
            if (model == null)
            {
                return(false);
            }

            int      r, c;
            TreePath tmp;

            // Lame workaround for GtkBinding not being bound
            switch (ev.Key)
            {
            // Activate keycodes
            case Gdk.Key.space:
            case Gdk.Key.Return:
            case Gdk.Key.ISO_Enter:
            case Gdk.Key.KP_Enter:
                // Remove this when we can use OnActivate ()
                if (focused_path == null)
                {
                    return(false);
                }

                if ((ev.State & Gdk.ModifierType.ControlMask) == 0)
                {
                    UnselectAll();
                }

                if (selected_paths.Contains(focused_path))
                {
                    UnselectPath(focused_path);
                }
                else
                {
                    SelectPath(focused_path);
                }

                if (ItemActivated != null)
                {
                    ItemActivatedArgs activated_args = new ItemActivatedArgs();
                    activated_args.Args = new object[] { focused_path };
                    ItemActivated(this, activated_args);
                }

                return(true);

            case Gdk.Key.a:
                // if control down, select all
                if (selection_mode == SelectionMode.Multiple &&
                    (ev.State & Gdk.ModifierType.ControlMask) > 0)
                {
                    SelectAll();
                }
                return(true);

            case Gdk.Key.A:
                // if control down and shift down, unselect all
                if (selection_mode == SelectionMode.Multiple &&
                    (ev.State & Gdk.ModifierType.ControlMask) > 0 &&
                    (ev.State & Gdk.ModifierType.ShiftMask) > 0)
                {
                    UnselectAll();
                }
                return(true);

            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                // Move focus or selection up
                if (layout_mode == LayoutMode.Vertical ||
                    layout_mode == LayoutMode.Grid)
                {
                    // find out the currently focused r and c
                    GetRowAndColForPath(focused_path, out r, out c);

                    // decrement the row by 1
                    if (r > 0)
                    {
                        r--;

                        // find the path at new r, c
                        if (GetPathAtRowAndCol(r, c, out tmp))
                        {
                            focused_path = tmp;
                        }
                    }
                }
                break;

            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                // move down
                if (layout_mode == LayoutMode.Vertical ||
                    layout_mode == LayoutMode.Grid)
                {
                    // find out the currently focused r and c
                    GetRowAndColForPath(focused_path, out r, out c);

                    // increment the row by 1
                    r++;

                    // find the path at new r, c
                    if (GetPathAtRowAndCol(r, c, out tmp))
                    {
                        focused_path = tmp;
                    }
                }
                break;

            case Gdk.Key.Left:
            case Gdk.Key.KP_Left:
                // move left
                if (layout_mode == LayoutMode.Horizontal ||
                    layout_mode == LayoutMode.Grid)
                {
                    tmp = focused_path.Copy();

                    // don't wrap around
                    if (tmp.Prev())
                    {
                        focused_path = tmp;
                    }
                }
                break;

            case Gdk.Key.Right:
            case Gdk.Key.KP_Right:
                // move right
                if (layout_mode == LayoutMode.Horizontal ||
                    layout_mode == LayoutMode.Grid)
                {
                    tmp = focused_path.Copy();
                    tmp.Next();

                    if (PathIsValid(tmp))
                    {
                        focused_path = tmp;
                    }
                }
                break;

            case Gdk.Key.Home:
            case Gdk.Key.KP_Home:
                // select and focus the first item, dropping
                // current selection
                tmp = TreePath.NewFirst();

                // verify that the path is valid
                if (PathIsValid(tmp))
                {
                    selected_paths.Clear();
                    focused_path = tmp;
                    SelectPath(focused_path);
                }
                return(true);

            case Gdk.Key.End:
            case Gdk.Key.KP_End:
                // select and focus the first item, dropping
                // current selection
                tmp = new TreePath(new int[] { n_cells - 1 });

                // verify that the path is valid
                if (PathIsValid(tmp))
                {
                    selected_paths.Clear();
                    focused_path = tmp;
                    SelectPath(focused_path);
                }
                return(true);
            }

            if (selection_mode == SelectionMode.Multiple &&
                (ev.State & Gdk.ModifierType.ShiftMask) > 0)
            {
                selected_paths.Clear();
                SelectAllBetween(selection_anchor, focused_path);
                return(true);
            }

            if (selection_mode == SelectionMode.Browse)
            {
                SelectPath(focused_path);
            }
            else
            {
                // TODO: Constrain this to only the previous focus and
                QueueDraw();
            }

            return(true);
        }
Пример #18
0
        protected override bool OnKeyPressEvent(Gdk.EventKey press)
        {
            bool handled = false;

            switch (press.Key)
            {
            case Gdk.Key.a:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    SelectionProxy.Selection.SelectAll();
                    handled = true;
                }
                break;

            case Gdk.Key.A:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    SelectionProxy.Selection.Clear();
                    handled = true;
                }
                break;

            case Gdk.Key.k:
            case Gdk.Key.K:
            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, -1, true);
                }
                break;

            case Gdk.Key.j:
            case Gdk.Key.J:
            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, 1, true);
                }
                else if (HeaderFocused)
                {
                    handled       = true;
                    HeaderFocused = false;
                }
                break;

            case Gdk.Key.Right:
            case Gdk.Key.KP_Right:
                if (ActiveColumn + 1 < column_cache.Length)
                {
                    ActiveColumn++;
                    InvalidateHeader();
                }
                handled = true;
                break;

            case Gdk.Key.Left:
            case Gdk.Key.KP_Left:
                if (ActiveColumn - 1 >= 0)
                {
                    ActiveColumn--;
                    InvalidateHeader();
                }
                handled = true;
                break;

            case Gdk.Key.Page_Up:
            case Gdk.Key.KP_Page_Up:
                if (!HeaderFocused)
                {
                    handled = vadjustment != null && KeyboardScroll(press.State,
                                                                    (int)(-vadjustment.PageIncrement / (double)RowHeight), false);
                }
                break;

            case Gdk.Key.Page_Down:
            case Gdk.Key.KP_Page_Down:
                if (!HeaderFocused)
                {
                    handled = vadjustment != null && KeyboardScroll(press.State,
                                                                    (int)(vadjustment.PageIncrement / (double)RowHeight), false);
                }
                break;

            case Gdk.Key.Home:
            case Gdk.Key.KP_Home:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, -10000000, false);
                }
                break;

            case Gdk.Key.End:
            case Gdk.Key.KP_End:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, 10000000, false);
                }
                break;

            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if (!HeaderFocused)
                {
                    handled = ActivateSelection();
                }
                else if (HeaderFocused && ActiveColumn >= 0)
                {
                    OnColumnLeftClicked(
                        column_cache[ActiveColumn].Column);
                    handled = true;
                }
                break;

            case Gdk.Key.Escape:
                handled = CancelColumnDrag();
                break;

            case Gdk.Key.space:
                if (Selection != null && Selection.FocusedIndex != 1 &&
                    !HeaderFocused)
                {
                    Selection.ToggleSelect(Selection.FocusedIndex);
                    handled = true;
                }
                break;

            case Gdk.Key.F10:
                if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    goto case Gdk.Key.Menu;
                }
                break;

            case Gdk.Key.Menu:
                // OnPopupMenu() is reserved for list items in derived classes.
                if (HeaderFocused)
                {
                    InvokeColumnHeaderMenu(ActiveColumn);
                    handled = true;
                }
                break;
            }

            if (handled)
            {
                return(true);
            }

            return(base.OnKeyPressEvent(press));
        }
Пример #19
0
        static MappedKeys MapKeys(Gdk.EventKey evt)
        {
            MappedKeys mapped;
            ushort     keycode = evt.HardwareKeycode;

            Gdk.ModifierType modifier = evt.State;
            byte             grp      = evt.Group;

            if (GtkMinorVersion >= 20)
            {
                gdk_keymap_add_virtual_modifiers(keymap.Handle, ref modifier);
            }

            // Workaround for bug "Bug 688247 - Ctrl+Alt key not work on windows7 with bootcamp on a Mac Book Pro"
            // Ctrl+Alt should behave like right alt key - unfortunately TranslateKeyboardState doesn't handle it.
            if (Platform.IsWindows)
            {
                const Gdk.ModifierType ctrlAlt = Gdk.ModifierType.ControlMask | Gdk.ModifierType.Mod1Mask;
                if ((modifier & ctrlAlt) == ctrlAlt)
                {
                    modifier = (modifier & ~ctrlAlt) | Gdk.ModifierType.Mod2Mask;
                    grp      = 1;
                }
            }

            //full key mapping
            uint keyval;
            int  effectiveGroup, level;

            Gdk.ModifierType consumedModifiers;
            keymap.TranslateKeyboardState(keycode, modifier, grp, out keyval, out effectiveGroup,
                                          out level, out consumedModifiers);
            mapped.Key   = (Gdk.Key)keyval;
            mapped.State = FixMacModifiers(evt.State & ~consumedModifiers, grp);

            //decompose the key into accel combinations
            var accelList = new List <KeyboardShortcut> ();

            const Gdk.ModifierType accelMods = Gdk.ModifierType.ShiftMask | Gdk.ModifierType.Mod1Mask
                                               | Gdk.ModifierType.ControlMask | Gdk.ModifierType.SuperMask | Gdk.ModifierType.MetaMask;

            //all accels ignore the lock key
            modifier &= ~Gdk.ModifierType.LockMask;

            //fully decomposed
            keymap.TranslateKeyboardState(evt.HardwareKeycode, Gdk.ModifierType.None, 0,
                                          out keyval, out effectiveGroup, out level, out consumedModifiers);
            accelList.Add(new KeyboardShortcut((Gdk.Key)keyval, FixMacModifiers(modifier, grp) & accelMods));

            //with shift composed
            if ((modifier & Gdk.ModifierType.ShiftMask) != 0)
            {
                keymap.TranslateKeyboardState(evt.HardwareKeycode, Gdk.ModifierType.ShiftMask, 0,
                                              out keyval, out effectiveGroup, out level, out consumedModifiers);
                var m = FixMacModifiers((modifier & ~consumedModifiers), grp) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //with group 1 composed
            if (grp == 1)
            {
                keymap.TranslateKeyboardState(evt.HardwareKeycode, modifier & ~Gdk.ModifierType.ShiftMask, 1,
                                              out keyval, out effectiveGroup, out level, out consumedModifiers);
                //somehow GTK on mac manages to consume a shift that we don't even pass to it
                if (oldMacKeyHacks)
                {
                    consumedModifiers &= ~Gdk.ModifierType.ShiftMask;
                }
                var m = FixMacModifiers((modifier & ~consumedModifiers), 0) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //with group 1 and shift composed
            if (grp == 1 && (modifier & Gdk.ModifierType.ShiftMask) != 0)
            {
                keymap.TranslateKeyboardState(evt.HardwareKeycode, modifier, 1,
                                              out keyval, out effectiveGroup, out level, out consumedModifiers);
                var m = FixMacModifiers((modifier & ~consumedModifiers), 0) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //and also allow the fully mapped key as an accel
            AddIfNotDuplicate(accelList, new KeyboardShortcut(mapped.Key, mapped.State & accelMods));

            mapped.Accels = accelList.ToArray();
            return(mapped);
        }
Пример #20
0
        public override bool HandleEvent(Gdk.Event evnt)
        {
            Gdk.EventButton eventButton = evnt as Gdk.EventButton;
            if (eventButton != null)
            {
                if (eventButton.Type == Gdk.EventType.ButtonPress)
                {
                    isDragging = true;
                    //selected = false;
                    FocusedRectangle  = default(Rectangle);
                    firstX            = eventButton.X;
                    firstY            = eventButton.Y;
                    intercationObject = new FocusRectangleShape(new Rectangle(firstX, firstY, 0, 0));
                    //
                    InteractionStateModel interState = this.Model.GetSubModel <InteractionStateModel>();
                    this.Model.BeginUpdate();
                    interState.Interaction.Add(intercationObject);
                    this.Model.EndUpdate();
                    //
                    return(true);
                }
                else if (eventButton.Type == Gdk.EventType.ButtonRelease)
                {
                    if (isDragging)
                    {
                        isDragging = false;
                        this.Model.BeginUpdate();
                        this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                        this.Model.EndUpdate();
                        FocusedRectangle  = intercationObject.Rectangle;
                        intercationObject = null;
                        //selected = true;
                        OnFocusedRectangleFinish();
                        return(true);
                    }
                }
            }

            Gdk.EventMotion eventMotion = evnt as Gdk.EventMotion;
            if (eventMotion != null)
            {
                if (isDragging)
                {
                    this.Model.BeginUpdate();

                    /*using (Context context = Gdk.CairoHelper.Create(evnt.Window)) {
                     * foreach (Shape shape in this.Model.GetSubModel<InteractionStateModel>().Interaction) {
                     *  context.Save();
                     *  context.Matrix = shape.Matrix;
                     *  Distance dist = shape.DistanceToLocal(new Distance(eventMotion.X - lastX, eventMotion.Y - lastY), context);
                     *  shape.Matrix.Translate(dist.Dx, dist.Dy);
                     *  context.Restore();
                     * }
                     * }*/
                    intercationObject.Width  = eventMotion.X - firstX;
                    intercationObject.Height = eventMotion.Y - firstY;
                    //intercationObject.Rectangle = new Rectangle(
                    //  intercationObject.Rectangle.X, intercationObject.Rectangle.Y,
                    //  eventMotion.X - intercationObject.Rectangle.X, eventMotion.Y - intercationObject.Rectangle.Y
                    //);
                    this.Model.EndUpdate();
                    return(true);
                }
            }

            Gdk.EventKey eventKey = evnt as Gdk.EventKey;
            if (eventKey != null)
            {
                if (isDragging && eventKey.Key == Gdk.Key.Escape)
                {
                    this.Model.BeginUpdate();
                    this.Model.GetSubModel <InteractionStateModel>().Interaction.Clear();
                    this.Model.EndUpdate();
                    intercationObject = null;
                    isDragging        = false;
                    //selected = false;
                    return(true);
                }
            }

            return(false);
        }
Пример #21
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            bool focus_search = false;

            bool disable_keybindings = Focus is Gtk.Entry;

            if (!disable_keybindings)
            {
                var widget = Focus;
                while (widget != null)
                {
                    if (widget is IDisableKeybindings)
                    {
                        disable_keybindings = true;
                        break;
                    }
                    widget = widget.Parent;
                }
            }

            // Don't disable them if ctrl is pressed, unless ctrl-a is pressed
            if (evnt.Key != Gdk.Key.a)
            {
                disable_keybindings &= (evnt.State & Gdk.ModifierType.ControlMask) == 0 &&
                                       evnt.Key != Gdk.Key.Control_L && evnt.Key != Gdk.Key.Control_R;
            }

            if (disable_keybindings)
            {
                if (accel_group_active)
                {
                    RemoveAccelGroup(ActionService.UIManager.AccelGroup);
                    accel_group_active = false;

                    // Reinstate the AccelGroup as soon as the focus leaves the entry
                    Focus.FocusOutEvent += OnEntryFocusOutEvent;
                }
            }
            else
            {
                if (!accel_group_active)
                {
                    AddAccelGroup(ActionService.UIManager.AccelGroup);
                    accel_group_active = true;
                }
            }

            switch (evnt.Key)
            {
            case Gdk.Key.f:
                if (Gdk.ModifierType.ControlMask == (evnt.State & Gdk.ModifierType.ControlMask))
                {
                    focus_search = true;
                }
                break;

            case Gdk.Key.S:
            case Gdk.Key.s:
            case Gdk.Key.slash:
                if (!disable_keybindings)
                {
                    focus_search = true;
                }
                break;

            case Gdk.Key.F3:
                focus_search = true;
                break;

            case Gdk.Key.F11:
                ActionService.ViewActions["FullScreenAction"].Activate();
                break;
            }

            // The source might have its own custom search entry - use it if so
            var src          = ServiceManager.SourceManager.ActiveSource;
            var search_entry = src.Properties.Get <SearchEntry> ("Nereid.SearchEntry") ?? view_container.SearchEntry;

            if (focus_search && search_entry.Visible && !source_view.EditingRow)
            {
                search_entry.GrabFocus();
                search_entry.HasFocus = true;
                return(true);
            }

            return(base.OnKeyPressEvent(evnt));
        }
Пример #22
0
        protected override bool OnTextEvent(GLib.Object sender,
                                            Gdk.Event ev,
                                            Gtk.TextIter iter)
        {
            NoteEditor editor = (NoteEditor)sender;

            Gtk.TextIter start, end;

            if (!CanActivate)
            {
                return(false);
            }

            switch (ev.Type)
            {
            case Gdk.EventType.ButtonPress:
                Gdk.EventButton button_ev = new Gdk.EventButton(ev.Handle);

                // Do not insert selected text when activating links with
                // middle mouse button
                if (button_ev.Button == 2)
                {
                    allow_middle_activate = true;
                    return(true);
                }

                return(false);

            case Gdk.EventType.ButtonRelease:
                button_ev = new Gdk.EventButton(ev.Handle);

                if (button_ev.Button != 1 && button_ev.Button != 2)
                {
                    return(false);
                }

                /* Don't activate if Shift or Control is pressed */
                if ((int)(button_ev.State & (Gdk.ModifierType.ShiftMask |
                                             Gdk.ModifierType.ControlMask)) != 0)
                {
                    return(false);
                }

                // Prevent activation when selecting links with the mouse
                if (editor.Buffer.HasSelection)
                {
                    return(false);
                }

                // Don't activate if the link has just been pasted with the
                // middle mouse button (no preceding ButtonPress event)
                if (button_ev.Button == 2 && !allow_middle_activate)
                {
                    return(false);
                }
                else
                {
                    allow_middle_activate = false;
                }

                GetExtents(iter, out start, out end);
                bool success = OnActivate(editor, start, end);

                // Hide note if link is activated with middle mouse button
                if (success && button_ev.Button == 2)
                {
                    Gtk.Widget widget = (Gtk.Widget)sender;
                    widget.Toplevel.Hide();
                }

                return(false);

            case Gdk.EventType.KeyPress:
                Gdk.EventKey key_ev = new Gdk.EventKey(ev.Handle);

                // Control-Enter activates the link at point...
                if ((int)(key_ev.State & Gdk.ModifierType.ControlMask) == 0)
                {
                    return(false);
                }

                if (key_ev.Key != Gdk.Key.Return &&
                    key_ev.Key != Gdk.Key.KP_Enter)
                {
                    return(false);
                }

                GetExtents(iter, out start, out end);
                return(OnActivate(editor, start, end));
            }

            return(false);
        }
Пример #23
0
        public static string AccelLabelFromKey(Gdk.EventKey raw)
        {
            bool complete;

            return(AccelLabelFromKey(raw, out complete));
        }
Пример #24
0
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            PlayerEngineService player = ServiceManager.PlayerEngine;

            bool control = (evnt.State & Gdk.ModifierType.ShiftMask) != 0;
            bool shift   = (evnt.State & Gdk.ModifierType.ControlMask) != 0;
            bool mod     = control || shift;

            uint fixed_seek = 15000;                                                         // 15 seconds
            uint fast_seek  = player.Length > 0 ? (uint)(player.Length * 0.15) : fixed_seek; // 15% or fixed
            uint slow_seek  = player.Length > 0 ? (uint)(player.Length * 0.05) : fixed_seek; // 5% or fixed

            switch (evnt.Key)
            {
            case Gdk.Key.F11:
            case Gdk.Key.Escape:
                Hide();
                return(true);

            case Gdk.Key.C:
            case Gdk.Key.c:
            case Gdk.Key.V:
            case Gdk.Key.v:
            case Gdk.Key.Tab:
                if (controls == null || !controls.Visible)
                {
                    ShowControls();
                }
                else
                {
                    HideControls();
                }
                return(true);

            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if (ServiceManager.PlayerEngine.InDvdMenu)
                {
                    ServiceManager.PlayerEngine.ActivateCurrentMenu();
                }
                else if (controls == null || !controls.Visible)
                {
                    ShowControls();
                }
                else
                {
                    HideControls();
                }
                return(true);

            case Gdk.Key.Right:
            case Gdk.Key.rightarrow:
            case Gdk.Key.KP_Right:
                if (ServiceManager.PlayerEngine.InDvdMenu)
                {
                    ServiceManager.PlayerEngine.NavigateToRightMenu();
                }
                else
                {
                    player.Position += mod ? fast_seek : slow_seek;
                    ShowControls();
                }
                break;

            case Gdk.Key.Left:
            case Gdk.Key.leftarrow:
            case Gdk.Key.KP_Left:
                if (ServiceManager.PlayerEngine.InDvdMenu)
                {
                    ServiceManager.PlayerEngine.NavigateToLeftMenu();
                }
                else
                {
                    player.Position -= mod ? fast_seek : slow_seek;
                    ShowControls();
                }
                break;

            case Gdk.Key.uparrow:
            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                if (ServiceManager.PlayerEngine.InDvdMenu)
                {
                    ServiceManager.PlayerEngine.NavigateToUpMenu();
                }
                break;

            case Gdk.Key.downarrow:
            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                if (ServiceManager.PlayerEngine.InDvdMenu)
                {
                    ServiceManager.PlayerEngine.NavigateToDownMenu();
                }
                break;
            }

            return(base.OnKeyPressEvent(evnt));
        }
        /// <summary>
        /// Modified this method so that punctuation characters
        /// will not close the completion window.
        /// </summary>
        public static bool ProcessKeyEvent(Gdk.EventKey e)
        {
            if (!wnd.Visible)
            {
                return(false);
            }

            XmlEditorListWindow.KeyAction ka = wnd.ProcessKey(e);

            if ((ka & XmlEditorListWindow.KeyAction.CloseWindow) != 0)
            {
                if (e.Key == Gdk.Key.Escape || e.Key == Gdk.Key.BackSpace || !System.Char.IsPunctuation((char)e.KeyValue))
                {
                    wnd.Hide();
                }
            }

            if ((ka & XmlEditorListWindow.KeyAction.Complete) != 0)
            {
                switch (e.Key)
                {
                case Gdk.Key.Tab:
                case Gdk.Key.Return:
                case Gdk.Key.ISO_Enter:
                case Gdk.Key.Key_3270_Enter:
                case Gdk.Key.KP_Enter:
                    wnd.Hide();
                    wnd.UpdateWord();
                    break;

                default:
                    break;
                }
            }

            if ((ka & XmlEditorListWindow.KeyAction.Ignore) != 0)
            {
                return(true);
            }

            if ((ka & XmlEditorListWindow.KeyAction.Process) != 0)
            {
                if (e.Key == Gdk.Key.Left)
                {
                    if (wnd.declarationviewwindow.Multiple)
                    {
                        wnd.declarationviewwindow.OverloadLeft();
                        wnd.UpdateDeclarationView();
                    }
                    return(true);
                }
                else if (e.Key == Gdk.Key.Right)
                {
                    if (wnd.declarationviewwindow.Multiple)
                    {
                        wnd.declarationviewwindow.OverloadRight();
                        wnd.UpdateDeclarationView();
                    }
                    return(true);
                }
            }

            return(false);
        }
Пример #26
0
        static MappedKeys MapKeys(Gdk.EventKey evt)
        {
            MappedKeys mapped;
            ushort     keycode = evt.HardwareKeycode;

            Gdk.ModifierType modifier = evt.State;
            byte             grp      = evt.Group;

            if (GtkMinorVersion >= 20)
            {
                gdk_keymap_add_virtual_modifiers(keymap.Handle, ref modifier);
            }

            //full key mapping
            uint keyval;
            int  effectiveGroup, level;

            Gdk.ModifierType consumedModifiers;
            TranslateKeyboardState(keycode, modifier, grp, out keyval, out effectiveGroup,
                                   out level, out consumedModifiers);
            mapped.Key   = (Gdk.Key)keyval;
            mapped.State = FixMacModifiers(evt.State & ~consumedModifiers, grp);

            //decompose the key into accel combinations
            var accelList = new List <KeyboardShortcut> ();

            const Gdk.ModifierType accelMods = Gdk.ModifierType.ShiftMask | Gdk.ModifierType.Mod1Mask
                                               | Gdk.ModifierType.ControlMask | Gdk.ModifierType.SuperMask | Gdk.ModifierType.MetaMask;

            //all accels ignore the lock key
            modifier &= ~Gdk.ModifierType.LockMask;

            //fully decomposed
            TranslateKeyboardState(evt.HardwareKeycode, Gdk.ModifierType.None, 0,
                                   out keyval, out effectiveGroup, out level, out consumedModifiers);
            accelList.Add(new KeyboardShortcut((Gdk.Key)keyval, FixMacModifiers(modifier, grp) & accelMods));

            //with shift composed
            if ((modifier & Gdk.ModifierType.ShiftMask) != 0)
            {
                keymap.TranslateKeyboardState(evt.HardwareKeycode, Gdk.ModifierType.ShiftMask, 0,
                                              out keyval, out effectiveGroup, out level, out consumedModifiers);
                var m = FixMacModifiers((modifier & ~consumedModifiers), grp) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //with group 1 composed
            if (grp == 1)
            {
                TranslateKeyboardState(evt.HardwareKeycode, modifier & ~Gdk.ModifierType.ShiftMask, 1,
                                       out keyval, out effectiveGroup, out level, out consumedModifiers);
                //somehow GTK on mac manages to consume a shift that we don't even pass to it
                if (oldMacKeyHacks)
                {
                    consumedModifiers &= ~Gdk.ModifierType.ShiftMask;
                }
                var m = FixMacModifiers((modifier & ~consumedModifiers), 0) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //with group 1 and shift composed
            if (grp == 1 && (modifier & Gdk.ModifierType.ShiftMask) != 0)
            {
                TranslateKeyboardState(evt.HardwareKeycode, modifier, 1,
                                       out keyval, out effectiveGroup, out level, out consumedModifiers);
                var m = FixMacModifiers((modifier & ~consumedModifiers), 0) & accelMods;
                AddIfNotDuplicate(accelList, new KeyboardShortcut((Gdk.Key)keyval, m));
            }

            //and also allow the fully mapped key as an accel
            AddIfNotDuplicate(accelList, new KeyboardShortcut(mapped.Key, mapped.State & accelMods));

            mapped.Accels = accelList.ToArray();
            return(mapped);
        }
Пример #27
0
        protected override bool OnKeyPressEvent(Gdk.EventKey press)
        {
            bool handled = false;

            switch (press.Key)
            {
            case Gdk.Key.a:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0 && Model.Count > 0)
                {
                    SelectionProxy.Selection.SelectAll();
                    handled = true;
                }
                break;

            case Gdk.Key.A:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0 && Selection.Count > 0)
                {
                    SelectionProxy.Selection.Clear();
                    handled = true;
                }
                break;

            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if (!HeaderFocused)
                {
                    handled = ActivateSelection();
                }
                else if (HeaderFocused && ActiveColumn >= 0)
                {
                    OnColumnLeftClicked(
                        column_cache[ActiveColumn].Column);
                    handled = true;
                }
                break;

            case Gdk.Key.Escape:
                handled = CancelColumnDrag();
                break;

            case Gdk.Key.space:
                if (Selection != null && Selection.FocusedIndex != 1 &&
                    !HeaderFocused)
                {
                    Selection.ToggleSelect(Selection.FocusedIndex);
                    handled = true;
                }
                break;

            case Gdk.Key.F10:
                if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    goto case Gdk.Key.Menu;
                }
                break;

            case Gdk.Key.Menu:
                // OnPopupMenu() is reserved for list items in derived classes.
                if (HeaderFocused)
                {
                    InvokeColumnHeaderMenu(ActiveColumn);
                    handled = true;
                }
                break;

            default:
                handled = HandleKeyboardScrollKey(press, KeyDirection.Press);
                break;
            }

            return(handled ? true : base.OnKeyPressEvent(press));
        }
Пример #28
0
 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
 {
     return(win.ProcessKey(evnt.Key, evnt.State));
 }
Пример #29
0
        private bool HandleKeyboardScrollKey(Gdk.EventKey press, KeyDirection direction)
        {
            bool handled = false;
            // FIXME: hard-coded grid logic here...
            bool grid          = ViewLayout != null;
            int  items_per_row = grid ? (ViewLayout as DataViewLayoutGrid).Columns : 1;

            switch (press.Key)
            {
            case Gdk.Key.k:
            case Gdk.Key.K:
            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                if (!HeaderFocused)
                {
                    handled = (direction == KeyDirection.Press)
                        ? KeyboardScroll(press.State, -items_per_row, true)
                        : UpdateSelectionForKeyboardScroll(press.State, -items_per_row);
                }
                break;

            case Gdk.Key.j:
            case Gdk.Key.J:
            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                if (direction == KeyDirection.Press)
                {
                    if (!HeaderFocused)
                    {
                        handled = KeyboardScroll(press.State, items_per_row, true);
                    }
                    else
                    {
                        handled       = true;
                        HeaderFocused = false;
                    }
                }
                else if (!HeaderFocused)
                {
                    handled = UpdateSelectionForKeyboardScroll(press.State, items_per_row);
                }
                break;

            case Gdk.Key.l:
            case Gdk.Key.L:
            case Gdk.Key.Right:
            case Gdk.Key.KP_Right:
                handled = true;
                if (direction == KeyDirection.Press)
                {
                    if (grid && !HeaderFocused)
                    {
                        handled = KeyboardScroll(press.State, 1, true);
                    }
                    else if (ActiveColumn + 1 < column_cache.Length)
                    {
                        ActiveColumn++;
                        InvalidateHeader();
                    }
                }
                else if (grid && !HeaderFocused)
                {
                    handled = UpdateSelectionForKeyboardScroll(press.State, 1);
                }
                break;

            case Gdk.Key.h:
            case Gdk.Key.H:
            case Gdk.Key.Left:
            case Gdk.Key.KP_Left:
                handled = true;
                if (direction == KeyDirection.Press)
                {
                    if (grid && !HeaderFocused)
                    {
                        handled = KeyboardScroll(press.State, -1, true);
                    }
                    else if (ActiveColumn - 1 >= 0)
                    {
                        ActiveColumn--;
                        InvalidateHeader();
                    }
                }
                else if (grid && !HeaderFocused)
                {
                    handled = UpdateSelectionForKeyboardScroll(press.State, -1);
                }
                break;

            case Gdk.Key.Page_Up:
            case Gdk.Key.KP_Page_Up:
                if (!HeaderFocused)
                {
                    int relativeRow = (int)(-vadjustment.PageIncrement / (double)ChildSize.Height) * items_per_row;
                    handled = vadjustment != null && (direction == KeyDirection.Press
                                                      ? KeyboardScroll(press.State, relativeRow, false)
                                                      : UpdateSelectionForKeyboardScroll(press.State, relativeRow));
                }
                break;

            case Gdk.Key.Page_Down:
            case Gdk.Key.KP_Page_Down:
                if (!HeaderFocused)
                {
                    int relativeRow = (int)(vadjustment.PageIncrement / (double)ChildSize.Height) * items_per_row;
                    handled = vadjustment != null && (direction == KeyDirection.Press
                                                          ? KeyboardScroll(press.State, relativeRow, false)
                                                          : UpdateSelectionForKeyboardScroll(press.State, relativeRow));
                }
                break;

            case Gdk.Key.Home:
            case Gdk.Key.KP_Home:
                if (!HeaderFocused)
                {
                    handled = direction == KeyDirection.Press
                        ? KeyboardScroll(press.State, int.MinValue, true)
                        : UpdateSelectionForKeyboardScroll(press.State, int.MinValue);
                }
                break;

            case Gdk.Key.End:
            case Gdk.Key.KP_End:
                if (!HeaderFocused)
                {
                    handled = direction == KeyDirection.Press
                        ? KeyboardScroll(press.State, int.MaxValue, true)
                        : UpdateSelectionForKeyboardScroll(press.State, int.MaxValue);
                }
                break;
            }

            return(handled);
        }
Пример #30
0
 /// <summary>
 /// Checks whether a keypress is a control-shift-space event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 /// <returns>True iff the event represents a control + shift + space click.</returns>
 private bool IsControlShiftSpace(Gdk.EventKey e)
 {
     return(IsControlSpace(e) && (e.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask);
 }
Пример #31
0
 protected override bool OnKeyReleaseEvent(Gdk.EventKey press)
 {
     return(HandleKeyboardScrollKey(press, KeyDirection.Release) ? true : base.OnKeyReleaseEvent(press));
 }
Пример #32
0
		void SendKeyEvent (Gtk.Widget target, uint keyval, Gdk.ModifierType state, Gdk.EventType eventType, string subWindow)
		{
			Gdk.KeymapKey[] keyms = Gdk.Keymap.Default.GetEntriesForKeyval (keyval);
			if (keyms.Length == 0)
				throw new Exception ("Keyval not found");
			
			Gdk.Window win;
			if (subWindow == null)
				win = target.GdkWindow;
			else
				win = (Gdk.Window) GetValue (target, target.GetType (), subWindow);
			
			NativeEventKeyStruct nativeEvent = new NativeEventKeyStruct (); 
			nativeEvent.type = eventType;
			nativeEvent.send_event = 1;
			nativeEvent.window = win.Handle;
			nativeEvent.state = (uint) state;
			nativeEvent.keyval = keyval;
			nativeEvent.group = (byte) keyms[0].Group;
			nativeEvent.hardware_keycode = (ushort) keyms[0].Keycode;
			nativeEvent.length = 0;
			nativeEvent.time = Gtk.Global.CurrentEventTime;
			
			IntPtr ptr = GLib.Marshaller.StructureToPtrAlloc (nativeEvent); 
			try {
				Gdk.EventKey evnt = new Gdk.EventKey (ptr); 
				Gdk.EventHelper.Put (evnt); 
			} finally {
				Marshal.FreeHGlobal (ptr);
			}
		}
Пример #33
0
 protected override bool OnKeyReleaseEvent(Gdk.EventKey evnt)
 {
     // TODO handle key events
     return(base.OnKeyPressEvent(evnt));
 }