/// <summary>Handle keyboard input</summary> public override bool HandleKeyboard(Bonsai.Core.NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam) { if (!IsEnabled || !IsVisible) { return(false); } if (msg == NativeMethods.WindowMessage.KeyDown) { switch ((System.Windows.Forms.Keys)wParam.ToInt32()) { case System.Windows.Forms.Keys.Home: SetValueInternal(minValue, true); return(true); case System.Windows.Forms.Keys.End: SetValueInternal(maxValue, true); return(true); case System.Windows.Forms.Keys.Prior: case System.Windows.Forms.Keys.Left: case System.Windows.Forms.Keys.Up: SetValueInternal(currentValue - 1, true); return(true); case System.Windows.Forms.Keys.Next: case System.Windows.Forms.Keys.Right: case System.Windows.Forms.Keys.Down: SetValueInternal(currentValue + 1, true); return(true); } } return(false); }
/// <summary>Handle mouse input input</summary> public override bool HandleMouse(Bonsai.Core.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 (buttonRect.Contains(pt)) { // Pressed while inside the control isPressed = true; Parent.SampleFramework.Window.Capture = true; return(true); } break; } case NativeMethods.WindowMessage.LeftButtonUp: { if (isPressed) { isPressed = false; Parent.SampleFramework.Window.Capture = false; Dialog.ClearFocus(); RaiseClickEvent(this, true); return(true); } break; } } return(false); }
/// <summary>Handle keyboard input to the edit box</summary> public override bool HandleKeyboard(Bonsai.Core.NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam) { if (!IsEnabled || !IsVisible) { return(false); } // Default to not handling the message bool isHandled = false; if (msg == NativeMethods.WindowMessage.KeyDown) { switch ((System.Windows.Forms.Keys)wParam.ToInt32()) { case System.Windows.Forms.Keys.End: case System.Windows.Forms.Keys.Home: // Move the caret if (wParam.ToInt32() == (int)System.Windows.Forms.Keys.End) { PlaceCaret(textData.Text.Length); } else { PlaceCaret(0); } if (!NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ShiftKey)) { // Shift is not down. Update selection start along with caret textData.SelectionStart = caretPosition; FocusText(); } ResetCaretBlink(); isHandled = true; break; case System.Windows.Forms.Keys.Insert: if (NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ControlKey)) { // Control insert -> Copy to clipboard CopyToClipboard(); } else if (NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ShiftKey)) { // Shift insert -> Paste from clipboard PasteFromClipboard(); } else { // Toggle insert mode isInsertMode = !isInsertMode; } break; case System.Windows.Forms.Keys.Delete: // Check to see if there is a text selection if (caretPosition != textData.SelectionStart) { DeleteSelectionText(); RaiseChangedEvent(this, true); } else { if (caretPosition < textData.Text.Length) { // Deleting one character textData.Text = textData.Text.Remove(caretPosition, 1); RaiseChangedEvent(this, true); } } ResetCaretBlink(); isHandled = true; break; case System.Windows.Forms.Keys.Left: if (NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ControlKey)) { // Control is down. Move the caret to a new item // instead of a character. } else if (caretPosition > 0) { PlaceCaret(caretPosition - 1); // Move one to the left } if (!NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ShiftKey)) { // Shift is not down. Update selection // start along with the caret. textData.SelectionStart = caretPosition; FocusText(); } ResetCaretBlink(); isHandled = true; break; case System.Windows.Forms.Keys.Right: if (NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ControlKey)) { // Control is down. Move the caret to a new item // instead of a character. } else if (caretPosition < textData.Text.Length) { PlaceCaret(caretPosition + 1); // Move one to the right } if (!NativeMethods.IsKeyDown(System.Windows.Forms.Keys.ShiftKey)) { // Shift is not down. Update selection // start along with the caret. textData.SelectionStart = caretPosition; FocusText(); } ResetCaretBlink(); isHandled = true; break; case System.Windows.Forms.Keys.Up: case System.Windows.Forms.Keys.Down: // Trap up and down arrows so that the dialog // does not switch focus to another control. isHandled = true; break; default: // Let the application handle escape isHandled = ((System.Windows.Forms.Keys)wParam.ToInt32()) == System.Windows.Forms.Keys.Escape; break; } } return(isHandled); }
/// <summary>Handle mouse input input</summary> public override bool HandleMouse(Bonsai.Core.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 (buttonRect.Contains(pt)) { // Pressed while inside the control isPressed = true; Parent.SampleFramework.Window.Capture = true; dragX = pt.X; dragOffset = buttonX - dragX; if (!hasFocus) { Dialog.RequestFocus(this); } return(true); } if (boundingBox.Contains(pt)) { if (pt.X > buttonX + controlX) { SetValueInternal(currentValue + 1, true); return(true); } if (pt.X < buttonX + controlX) { SetValueInternal(currentValue - 1, true); return(true); } } break; } case NativeMethods.WindowMessage.LeftButtonUp: { if (isPressed) { isPressed = false; Parent.SampleFramework.Window.Capture = false; Dialog.ClearFocus(); RaiseValueChanged(this, true); return(true); } break; } case NativeMethods.WindowMessage.MouseMove: { if (isPressed) { SetValueInternal(ValueFromPosition(controlX + pt.X + dragOffset), true); return(true); } break; } } return(false); }