Example #1
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;
            }
        }