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));
        }
        bool OnListButtonPressEvent(Gdk.EventButton evnt)
        {
            if (Model == null)
            {
                return(true);
            }

            int x = (int)evnt.X - list_interaction_alloc.X;
            int y = (int)evnt.Y - list_interaction_alloc.Y;

            GrabFocus();

            int row_index = GetModelRowAt(x, y);

            if (row_index < 0 || row_index >= Model.Count)
            {
                Gtk.Drag.SourceUnset(this);
                return(true);
            }

            if (LayoutChildHandlesEvent(evnt, true))
            {
                return(true);
            }

            ProxyEventToCell(evnt, true);

            object item = model[row_index];

            if (item == null)
            {
                return(true);
            }

            if (evnt.Button == 1 && evnt.Type == Gdk.EventType.TwoButtonPress)
            {
                // Double clicked
                OnRowActivated();
            }
            else if (Selection != null)
            {
                if ((evnt.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (evnt.Button == 3)
                    {
                        // Right clicked with ctrl pressed, so make sure row selected
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Select(row_index);
                        }
                    }
                    else
                    {
                        // Normal ctrl-click, so toggle
                        Selection.ToggleSelect(row_index);
                    }
                }
                else if ((evnt.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    // Shift-click, so select from first-row-selected (if any) to the current row
                    Selection.SelectFromFirst(row_index, true);
                }
                else
                {
                    if (evnt.Button == 3)
                    {
                        // Normal right-click, make sure row is only row selected
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Clear(false);
                            Selection.Select(row_index);
                        }
                    }
                    else
                    {
                        // Normal click, if row not already selected, select only it right now,
                        // but if it's already selected, wait until the Release to unselect any others so that
                        // drag and drop of 2+ items works.
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Clear(false);
                            Selection.Select(row_index);
                        }
                    }
                }

                FocusModelRow(row_index);

                // Now that we've worked out the selections, open the context menu
                if (evnt.Button == 3)
                {
                    OnPopupMenu();
                }
            }

            InvalidateList();
            return(true);
        }
示例#3
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));
        }