Exemplo n.º 1
0
        public override int Execute()
        {
            bool       AutoSelect;
            MenuAction Action;
            char       Ch;
            MenuItem   ItemShown, P;
            MenuView   Target;
            Rect       R;
            Event      E;
            bool       MouseActive;
            int        Result;

            AutoSelect = false;
            E.InfoPtr  = null;
            ItemShown  = null;

            Current     = Menu.Default;
            MouseActive = false;
            do
            {
                Action = MenuAction.DoNothing;
                E      = GetEvent();
                switch (E.What)
                {
                case Event.MouseDown:
                    if ((MouseInView(E.Where)) || (MouseInOwner(E)))
                    {
                        TrackMouse(E);
                        if (Size.Y == 1)
                        {
                            AutoSelect = true;
                        }
                    }
                    else
                    {
                        Action = MenuAction.DoReturn;
                    }
                    break;

                case Event.MouseUp:
                {
                    TrackMouse(E);
                    if (MouseInOwner(E))
                    {
                        Current = Menu.Default;
                    }
                    else
                    if (Current != null)
                    {
                        if (Current.Name != "")
                        {
                            Action = MenuAction.DoSelect;
                        }
                        else
                        if (MouseActive || MouseInView(E.Where))
                        {
                            Action = MenuAction.DoReturn;
                        }
                        else
                        {
                            Current = Menu.Default;
                            if (Current != null)
                            {
                                Current = Menu.Items;
                            }
                            Action = MenuAction.DoNothing;
                        }
                    }
                }
                break;

                case Event.MouseMove:
                    if (E.Buttons != 0)
                    {
                        TrackMouse(E);
                        if ((!(MouseInView(E.Where) || MouseInOwner(E))) && MouseInMenus(E))
                        {
                            Action = MenuAction.DoReturn;
                        }
                    }
                    break;

                case Event.KeyDown:
                    switch (Drivers.CtrlToArrow(E.KeyCode))
                    {
                    case KeyboardKeys.Up:
                    case KeyboardKeys.Down:
                        if (Size.Y != 1)
                        {
                            TrackKey(Drivers.CtrlToArrow(E.KeyCode) == KeyboardKeys.Down);
                        }
                        else
                        if (E.KeyCode == KeyboardKeys.Down)
                        {
                            AutoSelect = true;
                        }
                        break;

                    case KeyboardKeys.Left:
                    case KeyboardKeys.Right:
                        if (ParentMenu == null)
                        {
                            TrackKey(Drivers.CtrlToArrow(E.KeyCode) == KeyboardKeys.Right);
                        }
                        else
                        {
                            Action = MenuAction.DoReturn;
                        }
                        break;

                    case KeyboardKeys.Home:
                    case KeyboardKeys.End:
                        if (Size.Y != 1)
                        {
                            Current = Menu.Items;
                            if (E.KeyCode == KeyboardKeys.End)
                            {
                                TrackKey(false);
                            }
                        }
                        break;

                    case KeyboardKeys.Enter:
                    {
                        if (Size.Y == 1)
                        {
                            AutoSelect = true;
                        }
                        Action = MenuAction.DoSelect;
                    }
                    break;

                    case KeyboardKeys.Esc:
                    {
                        Action = MenuAction.DoReturn;
                        if ((ParentMenu == null) || (ParentMenu.Size.Y != 1))
                        {
                            ClearEvent(ref E);
                        }
                    }
                    break;

                    default:
                        Target = this;
                        Ch     = (char)(Program.GetAltChar((int)E.KeyCode));
                        if (Ch == '\x00')
                        {
                            Ch = (char)E.CharCode;
                        }
                        else
                        {
                            Target = TopMenu();
                        }
                        P = Target.FindItem(Ch);
                        if (P == null)
                        {
                            P = TopMenu().HotKey(E.KeyCode);
                            if ((P != null) && (CommandEnabled(P.Command)))
                            {
                                Result = P.Command;
                                Action = MenuAction.DoReturn;
                            }
                        }
                        else
                        if (Target == this)
                        {
                            if (Size.Y == 1)
                            {
                                AutoSelect = true;
                            }
                            Action  = MenuAction.DoSelect;
                            Current = P;
                        }
                        else
                        if ((ParentMenu != Target) || (ParentMenu.Current != P))
                        {
                            Action = MenuAction.DoReturn;
                        }
                        break;
                    }
                    break;

                case Event.evCommand:
                    if (E.Command == cmMenu)
                    {
                        AutoSelect = false;
                        if (ParentMenu != null)
                        {
                            Action = MenuAction.DoReturn;
                        }
                    }
                    else
                    {
                        Action = MenuAction.DoReturn;
                    }
                    break;
                }
                if (ItemShown != Current)
                {
                    ItemShown = Current;
                    DrawView();
                }
                Result = 0;
                if ((Action == MenuAction.DoSelect) || ((Action == MenuAction.DoNothing) && AutoSelect))
                {
                    if (Current != null)
                    {
                        if (Current.Name != "")
                        {
                            if (Current.Command == 0)
                            {
                                if ((E.What & (Event.MouseDown | Event.MouseMove)) != 0)
                                {
                                    PutEvent(E);
                                }
                                R      = GetItemRect(Current);
                                R.A.X += Origin.X;
                                R.A.Y  = R.B.Y + Origin.Y;
                                R.B    = new Point(Owner.Size.X, Owner.Size.Y);
                                if (Size.Y == 1)
                                {
                                    R.A.X--;
                                }
                                Target = TopMenu().NewSubView(R, Current.SubMenu, this);
                                Result = Owner.ExecView(Target);
                                Target.Done();
                            }
                            else
                            if (Action == MenuAction.DoSelect)
                            {
                                Result = Current.Command;
                            }
                        }
                    }
                }
                if ((Result != 0) && CommandEnabled(Result))
                {
                    Action = MenuAction.DoReturn;
                    ClearEvent(ref E);
                }
                else
                {
                    Result = 0;
                }
            }while(Action != MenuAction.DoReturn);
            if (E.What != Event.Nothing)
            {
                if ((ParentMenu != null) || (E.What == Event.evCommand))
                {
                    PutEvent(E);
                }
            }
            if (Current != null)
            {
                Menu.Default = Current;
                Current      = null;
                DrawView();
            }
            return(Result);
        }
Exemplo n.º 2
0
        public override void HandleEvent(ref Event Event)
        {
            ConsoleKey[] PadKeys = new ConsoleKey[] {
                ConsoleKey.LeftArrow,
                ConsoleKey.RightArrow,
                ConsoleKey.UpArrow,
                ConsoleKey.DownArrow,
                ConsoleKey.Home,
                ConsoleKey.End,
                ConsoleKey.Delete,
                ConsoleKey.Insert,
                ConsoleKey.PageUp,
                ConsoleKey.PageDown,
                ConsoleKey.Backspace
            };
            int    Delta, Anchor = 0;
            bool   ExtendBlock = false;
            string OldData = "";
            int    OldCurPos = 0, OldFirstPos = 0,
                   OldSelStart = 0, OldSelEnd = 0;
            bool WasAppending = false;

            base.HandleEvent(ref Event);
            if ((State & StateFlags.Selected) != 0)
            {
                switch (Event.What)
                {
                case Event.MouseDown:
                {
                    Delta = MouseDelta(ref Event);
                    if (CanScroll(Delta))
                    {
                        do
                        {
                            if (CanScroll(Delta))
                            {
                                FirstPos += Delta;
                                DrawView();
                            }
                        } while (MouseEvent(ref Event, Event.MouseAuto));
                    }
                    else
                    if (Event.Double)
                    {
                        SelectAll(true);
                    }
                    else
                    {
                        Anchor = MousePos(ref Event);
                        do
                        {
                            if (Event.What == Event.MouseAuto)
                            {
                                Delta = MouseDelta(ref Event);
                                if (CanScroll(Delta))
                                {
                                    FirstPos += Delta;
                                }
                            }
                            CurPos = MousePos(ref Event);
                            AdjustSelectBlock(ref Anchor);
                            DrawView();
                        } while (MouseEvent(ref Event, Event.MouseMove | Event.MouseAuto));
                    }
                    ClearEvent(ref Event);
                }
                break;

                case Event.KeyDown:
                    SaveState(ref OldData, ref OldCurPos, ref OldFirstPos, ref OldSelStart, ref OldSelEnd, ref WasAppending);
                    Event.KeyCode = Drivers.CtrlToArrow(Event.KeyCode);
                    if ((Array.IndexOf(PadKeys, (ConsoleKey)Event.KeyEvent.wVirtualKeyCode) != -1) &&
                        ((Event.KeyEvent.CtrlAltShift ^ 0x01) == 0))
                    {
                        Event.CharCode = 0x00;
                        if (CurPos == SelEnd)
                        {
                            Anchor = SelStart;
                        }
                        else
                        {
                            Anchor = SelEnd;
                        }
                        ExtendBlock = true;
                    }
                    else
                    {
                        ExtendBlock = false;
                    }
                    switch (Event.KeyCode)
                    {
                    case KeyboardKeys.Left:
                        if (CurPos > 0)
                        {
                            CurPos--;
                        }
                        break;

                    case KeyboardKeys.Right:
                        if (CurPos < Data.Length)
                        {
                            CurPos++;
                            CheckValid(true);
                        }
                        break;

                    case KeyboardKeys.Home:
                        CurPos = 0;
                        break;

                    case KeyboardKeys.End:
                        CurPos = Data.Length;
                        CheckValid(true);
                        break;

                    case KeyboardKeys.Back:
                        if (CurPos > 0)
                        {
                            Data = Data.Remove(CurPos - 1, 1);
                            CurPos--;
                            if (FirstPos > 0)
                            {
                                FirstPos--;
                            }
                            CheckValid(true);
                        }
                        break;

                    case KeyboardKeys.Del:
                        if (SelStart == SelEnd)
                        {
                            if (CurPos < (Data.Length - 1))
                            {
                                SelStart = CurPos;
                                SelEnd   = CurPos + 1;
                            }
                        }
                        DeleteSelect();
                        CheckValid(true);
                        break;

                    case KeyboardKeys.Ins:
                        SetState(StateFlags.CursorIns, (State & StateFlags.CursorIns) == 0);
                        break;

                    case KeyboardKeys.CtrlIns:
//                                if (SelStart == SelEnd)
//                                    System.Windows.Forms.Clipboard.SetText(Data);
//                                else
//                                    System.Windows.Forms.Clipboard.SetText(Data.Substring( SelStart, SelEnd - SelStart));
                        break;

                    default:
                        if ((Event.KeyEvent.UnicodeChar >= (byte)' ') /*&& ( Event.CharCode <= 255)*/)
                        {
                            if ((State & StateFlags.CursorIns) != 0)
                            {
                                Data = Data.Remove(CurPos, 1);
                            }
                            else
                            {
                                DeleteSelect();
                            }
                            if (CheckValid(true))
                            {
                                if ((Data.Length - 1) < MaxLen)
                                {
                                    if (FirstPos > CurPos)
                                    {
                                        FirstPos = CurPos;
                                    }
                                    CurPos++;
                                    Data = Data.Insert(CurPos - 1, new string(Event.KeyEvent.UnicodeChar, 1));
                                }
                                CheckValid(true);
                            }
                        }
                        else if (Event.CharCode == 0x19)
                        {
                            Data   = "";
                            CurPos = 0;
                        }
                        else
                        {
                            return;
                        }
                        break;
                    }
                    if (ExtendBlock)
                    {
                        AdjustSelectBlock(ref Anchor);
                    }
                    else
                    {
                        SelStart = CurPos;
                        SelEnd   = CurPos;
                    }
                    if (FirstPos > CurPos)
                    {
                        FirstPos = CurPos;
                    }
                    int I = CurPos - Size.X + 2;
                    if (FirstPos < I)
                    {
                        FirstPos = I;
                    }
                    DrawView();
                    ClearEvent(ref Event);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public override void HandleEvent(ref Event Event)
        {
            Point Mouse;

            base.HandleEvent(ref Event);
            if ((Options & OptionFlags.ofSelectable) == 0)
            {
                return;
            }
            if (Event.What == Event.MouseDown)
            {
                Mouse = MakeLocal(Event.Where);
                int I = FindSel(Mouse);
                if (I != -1)
                {
                    if (ButtonState(I))
                    {
                        Sel = I;
                    }
                }
                DrawView();
                do
                {
                    Mouse = MakeLocal(Event.Where);
                    if (FindSel(Mouse) == Sel)
                    {
                        ShowCursor();
                    }
                    else
                    {
                        HideCursor();
                    }
                } while (MouseEvent(ref Event, Event.MouseMove));
                ShowCursor();
                Mouse = MakeLocal(Event.Where);
                if ((FindSel(Mouse) == Sel) && (ButtonState(Sel)))
                {
                    Press(Sel);
                    DrawView();
                }
                ClearEvent(ref Event);
            }
            else if (Event.What == Event.KeyDown)
            {
                int S = Sel;
                switch (Drivers.CtrlToArrow(Event.KeyCode))
                {
                case KeyboardKeys.Up:
                    if ((State & StateFlags.Focused) != 0)
                    {
                        int I = 0;
                        do
                        {
                            I++;
                            S--;
                            if (S < 0)
                            {
                                S = Strings.Count - 1;
                            }
                        }while(!(ButtonState(S) || (I > Strings.Count)));
                        MoveSel(I, S);
                        ClearEvent(ref Event);
                    }
                    break;

                case KeyboardKeys.Down:
                    if ((State & StateFlags.Focused) != 0)
                    {
                        int I = 0;
                        do
                        {
                            I++;
                            S++;
                            if (S >= Strings.Count)
                            {
                                S = 0;
                            }
                        } while (!(ButtonState(S) || (I > Strings.Count)));
                        MoveSel(I, S);
                        ClearEvent(ref Event);
                    }
                    break;

                case KeyboardKeys.Right:
                    if ((State & StateFlags.Focused) != 0)
                    {
                        int I = 0;
                        do
                        {
                            I++;
                            S += Size.Y;
                            if (S > Strings.Count)
                            {
                                S = (S + 1) % Size.Y;
                                if (S >= Strings.Count)
                                {
                                    S = 0;
                                }
                            }
                        } while (!(ButtonState(S) || (I > Strings.Count)));
                        MoveSel(I, S);
                        ClearEvent(ref Event);
                    }
                    break;

                case KeyboardKeys.Left:
                    if ((State & StateFlags.Focused) != 0)
                    {
                        int I = 0;
                        do
                        {
                            I++;
                            if (S > 0)
                            {
                                S -= Size.Y;
                                if (S < 0)
                                {
                                    S = ((Strings.Count + Size.Y - 1) / Size.Y) * Size.Y + S - 1;
                                    if (S >= Strings.Count)
                                    {
                                        S = Strings.Count - 1;
                                    }
                                }
                            }
                            else
                            {
                                S = Strings.Count - 1;
                            }
                        } while (!(ButtonState(S) || (I > Strings.Count)));
                        MoveSel(I, S);
                        ClearEvent(ref Event);
                    }
                    break;

                default:
                {
                    for (int I = 0; I < Strings.Count; I++)
                    {
                        char C = HotKey(Strings[I]);
                        if ((Drivers.GetAltCode(C) == (uint)Event.KeyCode) ||
                            (((Owner.Phase == Phases.phPostProcess) || ((State & StateFlags.Focused) != 0)) &&
                             (C != '\x0000') && (char.ToUpper((char)Event.CharCode) == C)))
                        {
                            if (ButtonState(I))
                            {
                                if (Focus())
                                {
                                    Sel = I;
                                    MovedTo(Sel);
                                    Press(Sel);
                                    DrawView();
                                }
                                ClearEvent(ref Event);
                            }
                            return;
                        }
                    }
                    if ((Event.CharCode == ' ') && ((State & StateFlags.Focused) != 0) && ButtonState(Sel))
                    {
                        Press(Sel);
                        DrawView();
                        ClearEvent(ref Event);
                    }
                }
                break;
                }
            }
        }
Exemplo n.º 4
0
        public override void HandleEvent(ref Event Event)
        {
            const byte MouseAutosToSkip = 4;

            Point Mouse;
            int   ColWidth;
            int   OldItem, NewItem;
            uint  Count;

            base.HandleEvent(ref Event);
            if (Event.What == Event.MouseDown)
            {
                ColWidth = (Size.X / NumCols) + 1;
                OldItem  = Focused;
                Mouse    = MakeLocal(Event.Where);
                if (MouseInView(Event.Where))
                {
                    NewItem = Mouse.Y + (Size.Y * (Mouse.X / ColWidth)) + TopItem;
                }
                else
                {
                    NewItem = OldItem;
                }
                Count = 0;
                do
                {
                    if (NewItem != OldItem)
                    {
                        FocusItemNum(NewItem);
                        DrawView();
                    }
                    OldItem = NewItem;
                    Mouse   = MakeLocal(Event.Where);
                    if (MouseInView(Event.Where))
                    {
                        NewItem = Mouse.Y + (Size.Y * (Mouse.X / ColWidth)) + TopItem;
                    }
                    else
                    {
                        if (NumCols == 1)
                        {
                            if (Event.What == Event.MouseAuto)
                            {
                                Count++;
                            }
                            if (Count == MouseAutosToSkip)
                            {
                                Count = 0;
                                if (Mouse.Y < 0)
                                {
                                    NewItem = Focused - 1;
                                }
                                else
                                if (Mouse.Y >= Size.Y)
                                {
                                    NewItem = Focused + 1;
                                }
                            }
                        }
                        else
                        {
                            if (Event.What == Event.MouseAuto)
                            {
                                Count++;
                            }
                            if (Count == MouseAutosToSkip)
                            {
                                Count = 0;
                                if (Mouse.X < 0)
                                {
                                    NewItem = Focused - Size.Y;
                                }
                                else
                                if (Mouse.X >= Size.X)
                                {
                                    NewItem = Focused + Size.Y;
                                }
                                else
                                if (Mouse.Y < 0)
                                {
                                    NewItem = Focused - (Focused % Size.Y);
                                }
                                else if (Mouse.Y > Size.Y)
                                {
                                    NewItem = Focused - (Focused % Size.Y) + Size.Y - 1;
                                }
                            }
                        }
                    }
                }while(MouseEvent(ref Event, Event.MouseMove | Event.MouseAuto));
                FocusItemNum(NewItem);
                DrawView();
                if ((Event.Double) & (Range > Focused))
                {
                    SelectItem(Focused);
                }
                ClearEvent(ref Event);
            }
            else
            if (Event.What == Event.KeyDown)
            {
                if ((Event.CharCode == (byte)' ') && (Focused < Range))
                {
                    SelectItem(Focused);
                    NewItem = Focused;
                }
                else
                {
                    switch (Drivers.CtrlToArrow(Event.KeyCode))
                    {
                    case KeyboardKeys.Up:
                        NewItem = Focused - 1;
                        break;

                    case KeyboardKeys.Down:
                        NewItem = Focused + 1;
                        break;

                    case KeyboardKeys.Right:
                        if (NumCols > 1)
                        {
                            NewItem = Focused + Size.Y;
                        }
                        else
                        {
                            return;
                        }
                        break;

                    case KeyboardKeys.Left:
                        if (NumCols > 1)
                        {
                            NewItem = Focused - Size.Y;
                        }
                        else
                        {
                            return;
                        }
                        break;

                    case KeyboardKeys.PageDown:
                        NewItem = Focused + (Size.Y * NumCols);
                        break;

                    case KeyboardKeys.PageUp:
                        NewItem = Focused - (Size.Y * NumCols);
                        break;

                    case KeyboardKeys.Home:
                        NewItem = TopItem;
                        break;

                    case KeyboardKeys.End:
                        NewItem = TopItem + (Size.Y * NumCols) - 1;
                        break;

                    case KeyboardKeys.CtrlPageDown:
                        NewItem = Range - 1;
                        break;

                    case KeyboardKeys.CtrlPageUp:
                        NewItem = 0;
                        break;

                    default:
                        return;
                    }
                }
                FocusItemNum(NewItem);
                DrawView();
                ClearEvent(ref Event);
            }
            else
            if (Event.What == Event.Broadcast)
            {
                if ((Options & OptionFlags.ofSelectable) != 0)
                {
                    if ((Event.Command == cmScrollBarClicked) && ((Event.InfoPtr == HScrollBar) || (Event.InfoPtr == VScrollBar)))
                    {
                        Select();
                    }
                    else
                    if (Event.Command == cmScrollBarChanged)
                    {
                        FocusItemNum(VScrollBar.Value);
                        DrawView();
                    }
                    else
                    if (HScrollBar == Event.InfoPtr)
                    {
                        DrawView();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void HandleEvent(ref Event Event)
        {
            bool  Tracking;
            int   P, S, ClickPart;
            Point Mouse;
            Rect  Extent;

            base.HandleEvent(ref Event);
            int I = 0;

            switch (Event.What)
            {
            case Event.MouseDown:
                Clicked();
                Mouse  = MakeLocal(Event.Where);
                Extent = GetExtent();
                Extent.Grow(1, 1);
                P         = (int)GetPos();
                S         = (int)GetSize() - 1;
                ClickPart = GetPartCode(Mouse, Extent, P, S);
                if (ClickPart == sbIndicator)
                {
                    do
                    {
                        Mouse = MakeLocal(Event.Where);
                        if (GetPartCode(Mouse, Extent, P, S) == ClickPart)
                        {
                            SetValue((int)(Value + ScrollStep(ClickPart)));
                        }
                    }while(MouseEvent(ref Event, Event.MouseAuto));
                }
                else
                {
                    do
                    {
                        Mouse    = MakeLocal(Event.Where);
                        Tracking = Extent.Contains(Mouse);
                        if (Tracking)
                        {
                            if (Size.X == 1)
                            {
                                I = Mouse.Y;
                            }
                            else
                            {
                                I = Mouse.X;
                            }
                            if (I < 0)
                            {
                                I = 1;
                            }
                            if (I > S)
                            {
                                I = S - 1;
                            }
                        }
                        else
                        {
                            I = (int)GetPos();
                        }
                        if (I != P)
                        {
                            DrawPos(I);
                            P = I;
                        }
                    }while(MouseEvent(ref Event, Event.MouseMove));
                    if (Tracking && (S > 2))
                    {
                        S -= 2;
                        SetValue(((P - 1) * (Max - Min) + (S >> 1)) / S + Min);
                    }
                }
                ClearEvent(ref Event);
                break;

            case Event.KeyDown:
                if ((State & StateFlags.Visible) != 0)
                {
                    ClickPart = sbIndicator;
                    if (Size.Y == 1)
                    {
                        switch (Drivers.CtrlToArrow(Event.KeyCode))
                        {
                        case KeyboardKeys.Left:
                            ClickPart = sbLeftArrow;
                            break;

                        case KeyboardKeys.Right:
                            ClickPart = sbRightArrow;
                            break;

                        case KeyboardKeys.CtrlLeft:
                            ClickPart = sbPageLeft;
                            break;

                        case KeyboardKeys.CtrlRight:
                            ClickPart = sbPageRight;
                            break;

                        case KeyboardKeys.Home:
                            I = Min;
                            break;

                        case KeyboardKeys.End:
                            I = Max;
                            break;

                        default:
                            return;
                        }
                    }
                    else
                    {
                        switch (Drivers.CtrlToArrow(Event.KeyCode))
                        {
                        case KeyboardKeys.Up:
                            ClickPart = sbUpArrow;
                            break;

                        case KeyboardKeys.Down:
                            ClickPart = sbDownArrow;
                            break;

                        case KeyboardKeys.PageUp:
                            ClickPart = sbPageUp;
                            break;

                        case KeyboardKeys.PageDown:
                            ClickPart = sbPageDown;
                            break;

                        case KeyboardKeys.CtrlPageUp:
                            I = Min;
                            break;

                        case KeyboardKeys.CtrlPageDown:
                            I = Max;
                            break;

                        default:
                            return;
                        }
                    }
                    Clicked();
                    if (ClickPart != sbIndicator)
                    {
                        I = (int)(Value + ScrollStep(ClickPart));
                    }
                    SetValue(I);
                    ClearEvent(ref Event);
                }
                break;
            }
        }