コード例 #1
0
ファイル: Checkbox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>
        /// Handle the keyboard for the checkbox
        /// </summary>
        public override bool HandleKeyboard(NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.KeyDown:
                if ((System.Windows.Forms.Keys)wParam.ToInt32() == System.Windows.Forms.Keys.Space)
                {
                    isPressed = true;
                    return(true);
                }
                break;

            case NativeMethods.WindowMessage.KeyUp:
                if ((System.Windows.Forms.Keys)wParam.ToInt32() == System.Windows.Forms.Keys.Space)
                {
                    if (isPressed)
                    {
                        isPressed = false;
                        SetCheckedInternal(!isBoxChecked, true);
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
コード例 #2
0
        public void HandleMessages(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case NativeMethods.WindowMessage.RightButtonDown:
                if (!rightMouseDown)
                {
                    lastMousePosition = System.Windows.Forms.Cursor.Position;
                }
                rightMouseDown = true;
                break;

            case NativeMethods.WindowMessage.RightButtonUp:
                rightMouseDown = false;
                break;

            case NativeMethods.WindowMessage.MiddleButtonDown:
                if (!middleMouseDown)
                {
                    lastMousePosition = System.Windows.Forms.Cursor.Position;
                }
                middleMouseDown = true;
                break;

            case NativeMethods.WindowMessage.MiddleButtonUp:
                middleMouseDown = false;
                break;
            }
        }
コード例 #3
0
        /// <summary>
        /// Handle the keyboard for the checkbox
        /// </summary>
        public override bool HandleKeyboard(NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.KeyDown:
                if ((System.Windows.Forms.Keys)wParam.ToInt32() == System.Windows.Forms.Keys.Space)
                {
                    isPressed = true;
                    return(true);
                }
                break;

            case NativeMethods.WindowMessage.KeyUp:
                if ((System.Windows.Forms.Keys)wParam.ToInt32() == System.Windows.Forms.Keys.Space)
                {
                    if (isPressed)
                    {
                        isPressed = false;
                        parentDialog.ClearRadioButtonGroup(buttonGroupIndex);
                        isBoxChecked = !isBoxChecked;

                        RaiseChangedEvent(this, true);
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
コード例 #4
0
ファイル: Cursor3D.cs プロジェクト: sionhannuna/rcdeskpilot
        public void HandleMessages(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            // Handle the keyboard
            case NativeMethods.WindowMessage.KeyDown:
                CursorKeys mappedKeyDown = MapKey(wParam);
                if (mappedKeyDown != (CursorKeys)byte.MaxValue)
                {
                    // Valid key was pressed, mark it as 'down'
                    keys[(int)mappedKeyDown] = true;
                }
                break;

            case NativeMethods.WindowMessage.KeyUp:
                CursorKeys mappedKeyUp = MapKey(wParam);
                if (mappedKeyUp != (CursorKeys)byte.MaxValue)
                {
                    // Valid key was let go, mark it as 'up'
                    keys[(int)mappedKeyUp] = false;
                }
                break;

            case NativeMethods.WindowMessage.RightButtonDown:
                rightButtonDown = true;
                break;

            case NativeMethods.WindowMessage.RightButtonUp:
                rightButtonDown = false;
                break;
            }
        }
コード例 #5
0
 /// <summary>
 /// Before handling window messages, the sample framework passes incoming windows
 /// messages to the application through this callback function. If the application sets
 /// noFurtherProcessing to true, the sample framework will not process the message
 /// </summary>
 public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
 {
     // Give the dialog a chance to handle the message first
     if (!hud.MessageProc(hWnd, msg, wParam, lParam))
     {
         // Pass all remaining windows messages to camera so it can respond to user input
         camera.HandleMessages(hWnd, msg, wParam, lParam);
     }
     return(IntPtr.Zero);
 }
コード例 #6
0
        /// <summary>
        /// Handle mouse messages from the radio button
        /// </summary>
        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.LeftButtonDoubleClick:
            case NativeMethods.WindowMessage.LeftButtonDown:
            {
                if (ContainsPoint(pt))
                {
                    // Pressed while inside the control
                    isPressed = true;
                    Parent.SampleFramework.Window.Capture = true;
                    if ((!hasFocus) && (parentDialog.IsUsingKeyboardInput))
                    {
                        Dialog.RequestFocus(this);
                    }

                    return(true);
                }
            }
            break;

            case NativeMethods.WindowMessage.LeftButtonUp:
            {
                if (isPressed)
                {
                    isPressed = false;
                    Parent.SampleFramework.Window.Capture = false;

                    // Button click
                    if (ContainsPoint(pt))
                    {
                        parentDialog.ClearRadioButtonGroup(buttonGroupIndex);
                        isBoxChecked = !isBoxChecked;

                        RaiseChangedEvent(this, true);
                    }

                    return(true);
                }
            }
            break;
            }

            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Before handling window messages, the sample framework passes incoming windows
        /// messages to the application through this callback function. If the application sets
        /// noFurtherProcessing to true, the sample framework will not process the message
        /// </summary>
        public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
        {
            // Give the dialog a chance to handle the message first
            //noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
            if (noFurtherProcessing)
            {
                return(IntPtr.Zero);
            }

            if (modelControl != null)
            {
                modelControl.HandleMessages(hWnd, msg, wParam, lParam);
            }

            return(IntPtr.Zero);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>
        /// Before handling window messages, the sample framework passes incoming windows
        /// messages to the application through this callback function. If the application sets
        /// noFurtherProcessing to true, the sample framework will not process the message
        /// </summary>
        public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
        {
            // Give the dialog a chance to handle the message first
            noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
            if (noFurtherProcessing)
            {
                return(IntPtr.Zero);
            }
            if (camera != null)
            {
                camera.HandleMessages(hWnd, msg, wParam, lParam);
            }
            if (cursor3d != null)
            {
                cursor3d.HandleMessages(hWnd, msg, wParam, lParam);
            }

            return(IntPtr.Zero);
        }
コード例 #9
0
        /// <summary>
        /// Before handling window messages, the sample framework passes incoming windows
        /// messages to the application through this callback function. If the application sets
        /// noFurtherProcessing to true, the sample framework will not process the message
        /// </summary>
        public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
        {
            // Give the dialog a chance to handle the message first
            noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
            if (noFurtherProcessing)
            {
                return(IntPtr.Zero);
            }

            noFurtherProcessing = sampleUi.MessageProc(hWnd, msg, wParam, lParam);
            if (noFurtherProcessing)
            {
                return(IntPtr.Zero);
            }

            // Give the light control a chance now
            lightControl[activeLight].HandleMessages(hWnd, msg, wParam, lParam);

            // Pass all remaining windows messages to camera so it can respond to user input
            camera.HandleMessages(hWnd, msg, wParam, lParam);

            return(IntPtr.Zero);
        }
コード例 #10
0
ファイル: ScrollBar.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Stores data for a combo box item</summary>
        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.LeftButtonDoubleClick:
            case NativeMethods.WindowMessage.LeftButtonDown:
            {
                Parent.SampleFramework.Window.Capture = true;

                // Check for on up button
                if (upButtonRect.Contains(pt))
                {
                    if (position > start)
                    {
                        --position;
                    }
                    UpdateThumbRectangle();
                    return(true);
                }

                // Check for on down button
                if (downButtonRect.Contains(pt))
                {
                    if (position + pageSize < end)
                    {
                        ++position;
                    }
                    UpdateThumbRectangle();
                    return(true);
                }

                // Check for click on thumb
                if (thumbRect.Contains(pt))
                {
                    isDragging   = true;
                    thumbOffsetY = pt.Y - thumbRect.Top;
                    return(true);
                }

                // check for click on track
                if (thumbRect.Left <= pt.X &&
                    thumbRect.Right > pt.X)
                {
                    if (thumbRect.Top > pt.Y &&
                        trackRect.Top <= pt.Y)
                    {
                        Scroll(-(pageSize - 1));
                        return(true);
                    }
                    else if (thumbRect.Bottom <= pt.Y &&
                             trackRect.Bottom > pt.Y)
                    {
                        Scroll(pageSize - 1);
                        return(true);
                    }
                }

                break;
            }

            case NativeMethods.WindowMessage.LeftButtonUp:
            {
                isDragging = false;
                Parent.SampleFramework.Window.Capture = false;
                UpdateThumbRectangle();
                break;
            }

            case NativeMethods.WindowMessage.MouseMove:
            {
                if (isDragging)
                {
                    // Calculate new bottom and top of thumb rect
                    int bottom = thumbRect.Bottom + (pt.Y - thumbOffsetY - thumbRect.Top);
                    int top    = pt.Y - thumbOffsetY;
                    thumbRect = new System.Drawing.Rectangle(thumbRect.Left, top, thumbRect.Width, bottom - top);
                    if (thumbRect.Top < trackRect.Top)
                    {
                        thumbRect.Offset(0, trackRect.Top - thumbRect.Top);
                    }
                    else if (thumbRect.Bottom > trackRect.Bottom)
                    {
                        thumbRect.Offset(0, trackRect.Bottom - thumbRect.Bottom);
                    }

                    // Compute first item index based on thumb position
                    int maxFirstItem = end - start - pageSize;              // Largest possible index for first item
                    int maxThumb     = trackRect.Height - thumbRect.Height; // Largest possible thumb position

                    position = start + (thumbRect.Top - trackRect.Top +
                                        maxThumb / (maxFirstItem * 2)) * // Shift by half a row to avoid last row covered
                               maxFirstItem / maxThumb;

                    return(true);
                }
                break;
            }
            }

            // Was not handled
            return(false);
        }
コード例 #11
0
        }                                                                                                                   // Nothing to do here

        /// <summary>Handle the mouse data</summary>
        public virtual bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            return(false);
        }                                                                                                                                         // Nothing to do here
コード例 #12
0
        }                                                                                                                         // Nothing to do here

        /// <summary>Handle the keyboard data</summary>
        public virtual bool HandleKeyboard(NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            return(false);
        }                                                                                                                   // Nothing to do here
コード例 #13
0
        }                                                                // Nothing to do here

        /// <summary>Message Handler</summary>
        public virtual bool MsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            return(false);
        }                                                                                                                         // Nothing to do here
コード例 #14
0
ファイル: EditBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Handle all other messages</summary>
        public override bool MsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            if (msg == NativeMethods.WindowMessage.Character)
            {
                int charKey = wParam.ToInt32();
                switch (charKey)
                {
                case (int)System.Windows.Forms.Keys.Back:
                {
                    // If there's a selection, treat this
                    // like a delete key.
                    if (caretPosition != textData.SelectionStart)
                    {
                        DeleteSelectionText();
                        RaiseChangedEvent(this, true);
                    }
                    else if (caretPosition > 0)
                    {
                        // Move the caret and delete the char
                        textData.Text = textData.Text.Remove(caretPosition - 1, 1);
                        PlaceCaret(caretPosition - 1);
                        textData.SelectionStart = caretPosition;
                        FocusText();
                        RaiseChangedEvent(this, true);
                    }

                    ResetCaretBlink();
                    break;
                }

                case 24:                                    // Ctrl-X Cut
                case (int)System.Windows.Forms.Keys.Cancel: // Ctrl-C Copy
                {
                    CopyToClipboard();

                    // If the key is Ctrl-X, delete the selection too.
                    if (charKey == 24)
                    {
                        DeleteSelectionText();
                        RaiseChangedEvent(this, true);
                    }

                    break;
                }

                // Ctrl-V Paste
                case 22:
                {
                    PasteFromClipboard();
                    RaiseChangedEvent(this, true);
                    break;
                }

                case (int)System.Windows.Forms.Keys.Return:
                    // Invoke the event when the user presses Enter.
                    RaiseEnterEvent(this, true);
                    break;

                // Ctrl-A Select All
                case 1:
                {
                    if (textData.SelectionStart == caretPosition)
                    {
                        textData.SelectionStart = 0;
                        PlaceCaret(textData.Text.Length);
                    }
                    break;
                }

                // Junk characters we don't want in the string
                case 26:      // Ctrl Z
                case 2:       // Ctrl B
                case 14:      // Ctrl N
                case 19:      // Ctrl S
                case 4:       // Ctrl D
                case 6:       // Ctrl F
                case 7:       // Ctrl G
                case 10:      // Ctrl J
                case 11:      // Ctrl K
                case 12:      // Ctrl L
                case 17:      // Ctrl Q
                case 23:      // Ctrl W
                case 5:       // Ctrl E
                case 18:      // Ctrl R
                case 20:      // Ctrl T
                case 25:      // Ctrl Y
                case 21:      // Ctrl U
                case 9:       // Ctrl I
                case 15:      // Ctrl O
                case 16:      // Ctrl P
                case 27:      // Ctrl [
                case 29:      // Ctrl ]
                case 28:      // Ctrl \ 
                    break;

                default:
                {
                    // If there's a selection and the user
                    // starts to type, the selection should
                    // be deleted.
                    if (caretPosition != textData.SelectionStart)
                    {
                        DeleteSelectionText();
                    }
                    // If we are in overwrite mode and there is already
                    // a char at the caret's position, simply replace it.
                    // Otherwise, we insert the char as normal.
                    if (!isInsertMode && caretPosition < textData.Text.Length)
                    {
                        // This isn't the most efficient way to do this, but it's simple
                        // and shows the correct behavior
                        char[] charData = textData.Text.ToCharArray();
                        charData[caretPosition] = (char)wParam.ToInt32();
                        textData.Text           = new string(charData);
                    }
                    else
                    {
                        // Insert the char
                        char c = (char)wParam.ToInt32();
                        textData.Text = textData.Text.Insert(caretPosition, c.ToString());
                    }

                    // Move the caret and selection position now
                    PlaceCaret(caretPosition + 1);
                    textData.SelectionStart = caretPosition;
                    FocusText();

                    ResetCaretBlink();
                    RaiseChangedEvent(this, true);
                    break;
                }
                }
            }
            return(false);
        }
コード例 #15
0
ファイル: EditBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Handle mouse messages</summary>
        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            // We need a new point
            System.Drawing.Point p = pt;
            p.X -= textRect.Left;
            p.Y -= textRect.Top;

            switch (msg)
            {
            case NativeMethods.WindowMessage.LeftButtonDown:
            case NativeMethods.WindowMessage.LeftButtonDoubleClick:
                // Get focus first
                if (!hasFocus)
                {
                    Dialog.RequestFocus(this);
                }

                if (!ContainsPoint(pt))
                {
                    return(false);
                }

                isMouseDragging = true;
                Parent.SampleFramework.Window.Capture = true;
                // Determine the character corresponding to the coordinates
                int index = textData.GetCharIndexFromPosition(p);

                System.Drawing.Point startPosition = textData.GetPositionFromCharIndex(index);

                if (p.X > startPosition.X && index < textData.Text.Length)
                {
                    PlaceCaret(index + 1);
                }
                else
                {
                    PlaceCaret(index);
                }

                textData.SelectionStart = caretPosition;
                FocusText();
                ResetCaretBlink();
                return(true);

            case NativeMethods.WindowMessage.LeftButtonUp:
                Parent.SampleFramework.Window.Capture = false;
                isMouseDragging = false;
                break;

            case NativeMethods.WindowMessage.MouseMove:
                if (isMouseDragging)
                {
                    // Determine the character corresponding to the coordinates
                    int dragIndex = textData.GetCharIndexFromPosition(p);

                    if (dragIndex < textData.Text.Length)
                    {
                        PlaceCaret(dragIndex + 1);
                    }
                    else
                    {
                        PlaceCaret(dragIndex);
                    }
                }
                break;
            }
            return(false);
        }
コード例 #16
0
ファイル: ComboBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Called when the control needs to handle the keyboard</summary>
        public override bool HandleKeyboard(NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            const uint RepeatMask = (0x40000000);

            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            // Let the scroll bar have a chance to handle it first
            if (scrollbarControl.HandleKeyboard(msg, wParam, lParam))
            {
                return(true);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.KeyDown:
            {
                switch ((System.Windows.Forms.Keys)wParam.ToInt32())
                {
                case System.Windows.Forms.Keys.Return:
                {
                    if (isComboOpen)
                    {
                        if (selectedIndex != focusedIndex)
                        {
                            selectedIndex = focusedIndex;
                            RaiseChangedEvent(this, true);
                        }
                        isComboOpen = false;

                        if (!Parent.IsUsingKeyboardInput)
                        {
                            Dialog.ClearFocus();
                        }

                        return(true);
                    }
                    break;
                }

                case System.Windows.Forms.Keys.F4:
                {
                    // Filter out auto repeats
                    if ((lParam.ToInt32() & RepeatMask) != 0)
                    {
                        return(true);
                    }

                    isComboOpen = !isComboOpen;
                    if (!isComboOpen)
                    {
                        RaiseChangedEvent(this, true);

                        if (!Parent.IsUsingKeyboardInput)
                        {
                            Dialog.ClearFocus();
                        }
                    }

                    return(true);
                }

                case System.Windows.Forms.Keys.Left:
                case System.Windows.Forms.Keys.Up:
                {
                    if (focusedIndex > 0)
                    {
                        focusedIndex--;
                        selectedIndex = focusedIndex;
                        if (!isComboOpen)
                        {
                            RaiseChangedEvent(this, true);
                        }
                    }
                    return(true);
                }

                case System.Windows.Forms.Keys.Right:
                case System.Windows.Forms.Keys.Down:
                {
                    if (focusedIndex + 1 < (int)NumberItems)
                    {
                        focusedIndex++;
                        selectedIndex = focusedIndex;
                        if (!isComboOpen)
                        {
                            RaiseChangedEvent(this, true);
                        }
                    }
                    return(true);
                }
                }
                break;
            }
            }

            return(false);
        }
コード例 #17
0
ファイル: ComboBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Called when the control should handle the mouse</summary>
        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false); // Nothing to do
            }
            // Let the scroll bar handle it first
            if (scrollbarControl.HandleMouse(msg, pt, wParam, lParam))
            {
                return(true);
            }

            // Ok, scrollbar didn't handle it, move on
            switch (msg)
            {
            case NativeMethods.WindowMessage.MouseMove:
            {
                if (isComboOpen && dropDownRect.Contains(pt))
                {
                    // Determine which item has been selected
                    for (int i = 0; i < itemList.Count; i++)
                    {
                        ComboBoxItem cbi = (ComboBoxItem)itemList[i];
                        if (cbi.IsItemVisible && cbi.ItemRect.Contains(pt))
                        {
                            focusedIndex = i;
                        }
                    }
                    return(true);
                }
                break;
            }

            case NativeMethods.WindowMessage.LeftButtonDoubleClick:
            case NativeMethods.WindowMessage.LeftButtonDown:
            {
                if (ContainsPoint(pt))
                {
                    // Pressed while inside the control
                    isPressed = true;
                    Parent.SampleFramework.Window.Capture = true;

                    if (!hasFocus)
                    {
                        Dialog.RequestFocus(this);
                    }

                    // Toggle dropdown
                    if (hasFocus)
                    {
                        isComboOpen = !isComboOpen;
                        if (!isComboOpen)
                        {
                            if (!parentDialog.IsUsingKeyboardInput)
                            {
                                Dialog.ClearFocus();
                            }
                        }
                    }

                    return(true);
                }

                // Perhaps this click is within the dropdown
                if (isComboOpen && dropDownRect.Contains(pt))
                {
                    // Determine which item has been selected
                    for (int i = scrollbarControl.TrackPosition; i < itemList.Count; i++)
                    {
                        ComboBoxItem cbi = (ComboBoxItem)itemList[i];
                        if (cbi.IsItemVisible && cbi.ItemRect.Contains(pt))
                        {
                            selectedIndex = focusedIndex = i;
                            RaiseChangedEvent(this, true);

                            isComboOpen = false;

                            if (!parentDialog.IsUsingKeyboardInput)
                            {
                                Dialog.ClearFocus();
                            }

                            break;
                        }
                    }
                    return(true);
                }
                // Mouse click not on main control or in dropdown, fire an event if needed
                if (isComboOpen)
                {
                    focusedIndex = selectedIndex;
                    RaiseChangedEvent(this, true);
                    isComboOpen = false;
                }

                // Make sure the control is no longer 'pressed'
                isPressed = false;

                // Release focus if appropriate
                if (!parentDialog.IsUsingKeyboardInput)
                {
                    Dialog.ClearFocus();
                }

                break;
            }

            case NativeMethods.WindowMessage.LeftButtonUp:
            {
                if (isPressed && ContainsPoint(pt))
                {
                    // Button click
                    isPressed = false;
                    Parent.SampleFramework.Window.Capture = false;
                    return(true);
                }
                break;
            }

            case NativeMethods.WindowMessage.MouseWheel:
            {
                int zdelta = (short)NativeMethods.HiWord((uint)wParam.ToInt32()) / Dialog.WheelDelta;
                if (isComboOpen)
                {
                    scrollbarControl.Scroll(-zdelta * System.Windows.Forms.SystemInformation.MouseWheelScrollLines);
                }
                else
                {
                    if (zdelta > 0)
                    {
                        if (focusedIndex > 0)
                        {
                            focusedIndex--;
                            selectedIndex = focusedIndex;
                            if (!isComboOpen)
                            {
                                RaiseChangedEvent(this, true);
                            }
                        }
                    }
                    else
                    {
                        if (focusedIndex + 1 < NumberItems)
                        {
                            focusedIndex++;
                            selectedIndex = focusedIndex;
                            if (!isComboOpen)
                            {
                                RaiseChangedEvent(this, true);
                            }
                        }
                    }
                }
                return(true);
            }
            }

            // Didn't handle it
            return(false);
        }
コード例 #18
0
ファイル: ListBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Called when the control should handle the mouse</summary>
        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)
        {
            const int ShiftModifier   = 0x0004;
            const int ControlModifier = 0x0008;

            if (!IsEnabled || !IsVisible)
            {
                return(false); // Nothing to do
            }
            // First acquire focus
            if (msg == NativeMethods.WindowMessage.LeftButtonDown)
            {
                if (!hasFocus)
                {
                    Dialog.RequestFocus(this);
                }
            }


            // Let the scroll bar handle it first
            if (scrollbarControl.HandleMouse(msg, pt, wParam, lParam))
            {
                return(true);
            }

            // Ok, scrollbar didn't handle it, move on
            switch (msg)
            {
            case NativeMethods.WindowMessage.LeftButtonDoubleClick:
            case NativeMethods.WindowMessage.LeftButtonDown:
            {
                // Check for clicks in the text area
                if (itemList.Count > 0 && selectionRect.Contains(pt))
                {
                    // Compute the index of the clicked item
                    int clicked = 0;
                    if (textHeight > 0)
                    {
                        clicked = scrollbarControl.TrackPosition + (pt.Y - textRect.Top) / textHeight;
                    }
                    else
                    {
                        clicked = -1;
                    }

                    // Only proceed if the click falls ontop of an item
                    if (clicked >= scrollbarControl.TrackPosition &&
                        clicked < itemList.Count &&
                        clicked < scrollbarControl.TrackPosition + scrollbarControl.PageSize)
                    {
                        Parent.SampleFramework.Window.Capture = true;
                        isDragging = true;

                        // If this is a double click, fire off an event and exit
                        // since the first click would have taken care of the selection
                        // updating.
                        if (msg == NativeMethods.WindowMessage.LeftButtonDoubleClick)
                        {
                            RaiseDoubleClickEvent(this, true);
                            return(true);
                        }

                        selectedIndex = clicked;
                        if ((wParam.ToInt32() & ShiftModifier) == 0)
                        {
                            selectedStarted = selectedIndex;         // Shift isn't down
                        }
                        // If this is a multi-selection listbox, update per-item
                        // selection data.
                        if (style == ListBoxStyle.Multiselection)
                        {
                            // Determine behavior based on the state of Shift and Ctrl
                            ListBoxItem selectedItem = (ListBoxItem)itemList[selectedIndex];
                            if ((wParam.ToInt32() & (ShiftModifier | ControlModifier)) == ControlModifier)
                            {
                                // Control click, reverse the selection
                                selectedItem.IsItemSelected = !selectedItem.IsItemSelected;
                                itemList[selectedIndex]     = selectedItem;
                            }
                            else if ((wParam.ToInt32() & (ShiftModifier | ControlModifier)) == ShiftModifier)
                            {
                                // Shift click. Set the selection for all items
                                // from last selected item to the current item.
                                // Clear everything else.
                                int begin = Math.Min(selectedStarted, selectedIndex);
                                int end   = Math.Max(selectedStarted, selectedIndex);

                                // Unselect everthing before the beginning
                                for (int i = 0; i < begin; ++i)
                                {
                                    ListBoxItem lb = (ListBoxItem)itemList[i];
                                    lb.IsItemSelected = false;
                                    itemList[i]       = lb;
                                }
                                // unselect everything after the end
                                for (int i = end + 1; i < itemList.Count; ++i)
                                {
                                    ListBoxItem lb = (ListBoxItem)itemList[i];
                                    lb.IsItemSelected = false;
                                    itemList[i]       = lb;
                                }

                                // Select everything between
                                for (int i = begin; i <= end; ++i)
                                {
                                    ListBoxItem lb = (ListBoxItem)itemList[i];
                                    lb.IsItemSelected = true;
                                    itemList[i]       = lb;
                                }
                            }
                            else if ((wParam.ToInt32() & (ShiftModifier | ControlModifier)) == (ShiftModifier | ControlModifier))
                            {
                                // Control-Shift-click.

                                // The behavior is:
                                //   Set all items from selectedStarted to selectedIndex to
                                //     the same state as selectedStarted, not including selectedIndex.
                                //   Set selectedIndex to selected.
                                int begin = Math.Min(selectedStarted, selectedIndex);
                                int end   = Math.Max(selectedStarted, selectedIndex);

                                // The two ends do not need to be set here.
                                bool isLastSelected = ((ListBoxItem)itemList[selectedStarted]).IsItemSelected;

                                for (int i = begin + 1; i < end; ++i)
                                {
                                    ListBoxItem lb = (ListBoxItem)itemList[i];
                                    lb.IsItemSelected = isLastSelected;
                                    itemList[i]       = lb;
                                }

                                selectedItem.IsItemSelected = true;
                                itemList[selectedIndex]     = selectedItem;

                                // Restore selectedIndex to the previous value
                                // This matches the Windows behavior

                                selectedIndex = selectedStarted;
                            }
                            else
                            {
                                // Simple click.  Clear all items and select the clicked
                                // item.
                                for (int i = 0; i < itemList.Count; ++i)
                                {
                                    ListBoxItem lb = (ListBoxItem)itemList[i];
                                    lb.IsItemSelected = false;
                                    itemList[i]       = lb;
                                }
                                selectedItem.IsItemSelected = true;
                                itemList[selectedIndex]     = selectedItem;
                            }
                        }         // End of multi-selection case
                        RaiseSelectionEvent(this, true);
                    }
                    return(true);
                }
                break;
            }

            case NativeMethods.WindowMessage.LeftButtonUp:
            {
                Parent.SampleFramework.Window.Capture = false;
                isDragging = false;

                if (selectedIndex != -1)
                {
                    // Set all items between selectedStarted and selectedIndex to
                    // the same state as selectedStarted
                    int end = Math.Max(selectedStarted, selectedIndex);
                    for (int i = Math.Min(selectedStarted, selectedIndex) + 1; i < end; ++i)
                    {
                        ListBoxItem lb = (ListBoxItem)itemList[i];
                        lb.IsItemSelected = ((ListBoxItem)itemList[selectedStarted]).IsItemSelected;
                        itemList[i]       = lb;
                    }
                    ListBoxItem lbs = (ListBoxItem)itemList[selectedIndex];
                    lbs.IsItemSelected      = ((ListBoxItem)itemList[selectedStarted]).IsItemSelected;
                    itemList[selectedIndex] = lbs;

                    // If selectedStarted and selectedIndex are not the same,
                    // the user has dragged the mouse to make a selection.
                    // Notify the application of this.
                    if (selectedIndex != selectedStarted)
                    {
                        RaiseSelectionEvent(this, true);
                    }
                }
                break;
            }

            case NativeMethods.WindowMessage.MouseWheel:
            {
                int lines        = System.Windows.Forms.SystemInformation.MouseWheelScrollLines;
                int scrollAmount = (int)(NativeMethods.HiWord((uint)wParam.ToInt32()) / Dialog.WheelDelta * lines);
                scrollbarControl.Scroll(-scrollAmount);
                break;
            }

            case NativeMethods.WindowMessage.MouseMove:
            {
                if (isDragging)
                {
                    // compute the index of the item below the cursor
                    int itemIndex = -1;
                    if (textHeight > 0)
                    {
                        itemIndex = scrollbarControl.TrackPosition + (pt.Y - textRect.Top) / textHeight;
                    }

                    // Only proceed if the cursor is on top of an item
                    if (itemIndex >= scrollbarControl.TrackPosition &&
                        itemIndex < itemList.Count &&
                        itemIndex < scrollbarControl.TrackPosition + scrollbarControl.PageSize)
                    {
                        selectedIndex = itemIndex;
                        RaiseSelectionEvent(this, true);
                    }
                    else if (itemIndex < scrollbarControl.TrackPosition)
                    {
                        // User drags the mouse above window top
                        scrollbarControl.Scroll(-1);
                        selectedIndex = scrollbarControl.TrackPosition;
                        RaiseSelectionEvent(this, true);
                    }
                    else if (itemIndex >= scrollbarControl.TrackPosition + scrollbarControl.PageSize)
                    {
                        // User drags the mouse below the window bottom
                        scrollbarControl.Scroll(1);
                        selectedIndex = Math.Min(itemList.Count, scrollbarControl.TrackPosition + scrollbarControl.PageSize - 1);
                        RaiseSelectionEvent(this, true);
                    }
                }
                break;
            }
            }

            // Didn't handle it
            return(false);
        }
コード例 #19
0
ファイル: ListBox.cs プロジェクト: sionhannuna/rcdeskpilot
        /// <summary>Called when the control needs to handle the keyboard</summary>
        public override bool HandleKeyboard(NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
        {
            if (!IsEnabled || !IsVisible)
            {
                return(false);
            }

            // Let the scroll bar have a chance to handle it first
            if (scrollbarControl.HandleKeyboard(msg, wParam, lParam))
            {
                return(true);
            }

            switch (msg)
            {
            case NativeMethods.WindowMessage.KeyDown:
            {
                switch ((System.Windows.Forms.Keys)wParam.ToInt32())
                {
                case System.Windows.Forms.Keys.Up:
                case System.Windows.Forms.Keys.Down:
                case System.Windows.Forms.Keys.Next:
                case System.Windows.Forms.Keys.Prior:
                case System.Windows.Forms.Keys.Home:
                case System.Windows.Forms.Keys.End:
                {
                    // If no items exists, do nothing
                    if (itemList.Count == 0)
                    {
                        return(true);
                    }

                    int oldSelected = selectedIndex;

                    // Adjust selectedIndex
                    switch ((System.Windows.Forms.Keys)wParam.ToInt32())
                    {
                    case System.Windows.Forms.Keys.Up: --selectedIndex; break;

                    case System.Windows.Forms.Keys.Down: ++selectedIndex; break;

                    case System.Windows.Forms.Keys.Next: selectedIndex += scrollbarControl.PageSize - 1; break;

                    case System.Windows.Forms.Keys.Prior: selectedIndex -= scrollbarControl.PageSize - 1; break;

                    case System.Windows.Forms.Keys.Home: selectedIndex = 0; break;

                    case System.Windows.Forms.Keys.End: selectedIndex = itemList.Count - 1; break;
                    }

                    // Clamp the item
                    if (selectedIndex < 0)
                    {
                        selectedIndex = 0;
                    }
                    if (selectedIndex >= itemList.Count)
                    {
                        selectedIndex = itemList.Count - 1;
                    }

                    // Did the selection change?
                    if (oldSelected != selectedIndex)
                    {
                        if (style == ListBoxStyle.Multiselection)
                        {
                            // Clear all selection
                            for (int i = 0; i < itemList.Count; i++)
                            {
                                ListBoxItem lbi = (ListBoxItem)itemList[i];
                                lbi.IsItemSelected = false;
                                itemList[i]        = lbi;
                            }

                            // Is shift being held down?
                            bool shiftDown = ((NativeMethods.GetAsyncKeyState
                                                   ((int)System.Windows.Forms.Keys.ShiftKey) & 0x8000) != 0);

                            if (shiftDown)
                            {
                                // Select all items from the start selection to current selected index
                                int end = Math.Max(selectedStarted, selectedIndex);
                                for (int i = Math.Min(selectedStarted, selectedIndex); i <= end; ++i)
                                {
                                    ListBoxItem lbi = (ListBoxItem)itemList[i];
                                    lbi.IsItemSelected = true;
                                    itemList[i]        = lbi;
                                }
                            }
                            else
                            {
                                ListBoxItem lbi = (ListBoxItem)itemList[selectedIndex];
                                lbi.IsItemSelected      = true;
                                itemList[selectedIndex] = lbi;

                                // Update selection start
                                selectedStarted = selectedIndex;
                            }
                        }
                        else                 // Update selection start
                        {
                            selectedStarted = selectedIndex;
                        }

                        // adjust scrollbar
                        scrollbarControl.ShowItem(selectedIndex);
                        RaiseSelectionEvent(this, true);
                    }
                }
                    return(true);
                }
                break;
            }
            }

            return(false);
        }
コード例 #20
0
 /// <summary>Hand messages off to dialog</summary>
 public void HandleMessages(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
 {
     dialog.MessageProc(hWnd, msg, wParam, lParam);
 }