|
1 | | -// Permission is hereby granted, free of charge, to any person obtaining |
2 | | -// a copy of this software and associated documentation files (the |
3 | | -// "Software"), to deal in the Software without restriction, including |
4 | | -// without limitation the rights to use, copy, modify, merge, publish, |
5 | | -// distribute, sublicense, and/or sell copies of the Software, and to |
6 | | -// permit persons to whom the Software is furnished to do so, subject to |
7 | | -// the following conditions: |
8 | | -// |
9 | | -// The above copyright notice and this permission notice shall be |
10 | | -// included in all copies or substantial portions of the Software. |
11 | | -// |
12 | | -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
13 | | -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
14 | | -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
15 | | -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
16 | | -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
17 | | -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
18 | | -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
19 | | -// |
20 | | -// Copyright (c) 2004-2005 Novell, Inc. |
21 | | -// |
22 | | -// Authors: |
23 | | -// Peter Bartok pbartok@novell.com |
24 | | -// |
25 | | -// |
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
26 | 4 |
|
27 | 5 | using System; |
28 | 6 | using Avalonia.Input; |
29 | 7 |
|
30 | 8 | namespace Modern.Forms |
31 | 9 | { |
| 10 | + /// <summary> |
| 11 | + /// Provides data for the KeyDown or KeyUp event. |
| 12 | + /// </summary> |
32 | 13 | public class KeyEventArgs : EventArgs |
33 | 14 | { |
34 | | - private bool supress_key_press; |
| 15 | + private bool _suppressKeyPress = false; |
35 | 16 |
|
| 17 | + /// <summary> |
| 18 | + /// Initializes a new instance of the KeyEventArgs class. |
| 19 | + /// </summary> |
36 | 20 | public KeyEventArgs (Keys keyData) |
37 | 21 | { |
38 | 22 | KeyData = keyData; |
39 | | - Handled = false; |
40 | 23 | } |
41 | 24 |
|
42 | | - public virtual bool Alt => KeyData.HasFlag (Keys.Alt); |
| 25 | + /// <summary> |
| 26 | + /// Gets a value indicating whether the ALT key was pressed. |
| 27 | + /// </summary> |
| 28 | + public virtual bool Alt => (KeyData & Keys.Alt) == Keys.Alt; |
43 | 29 |
|
44 | | - public virtual bool Control => KeyData.HasFlag (Keys.Control); |
| 30 | + /// <summary> |
| 31 | + /// Gets a value indicating whether the CTRL key was pressed. |
| 32 | + /// </summary> |
| 33 | + public bool Control => (KeyData & Keys.Control) == Keys.Control; |
45 | 34 |
|
| 35 | + /// <summary> |
| 36 | + /// Gets or sets a value indicating whether the event was handled. |
| 37 | + /// </summary> |
46 | 38 | public bool Handled { get; set; } |
47 | 39 |
|
48 | | - public Keys KeyCode => KeyData & Keys.KeyCode; |
| 40 | + /// <summary> |
| 41 | + /// Gets the keyboard code for a KeyDown or KeyUp event. |
| 42 | + /// </summary> |
| 43 | + public Keys KeyCode { |
| 44 | + get { |
| 45 | + var keyGenerated = KeyData & Keys.KeyCode; |
49 | 46 |
|
50 | | - public Keys KeyData { get; } |
| 47 | + // since Keys can be discontiguous, keeping Enum.IsDefined. |
| 48 | + if (!Enum.IsDefined (typeof (Keys), (int)keyGenerated)) { |
| 49 | + return Keys.None; |
| 50 | + } |
| 51 | + return keyGenerated; |
| 52 | + } |
| 53 | + } |
51 | 54 |
|
52 | | - public int KeyValue => Convert.ToInt32 (KeyData); |
| 55 | + /// <summary> |
| 56 | + /// Gets the keyboard value for a <see cref='Forms.Control.KeyDown'/> or |
| 57 | + /// <see cref='Forms.Control.KeyUp'/> event. |
| 58 | + /// </summary> |
| 59 | + public int KeyValue => (int)(KeyData & Keys.KeyCode); |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Gets the key data for a <see cref='Forms.Control.KeyDown'/> or |
| 63 | + /// <see cref='Forms.Control.KeyUp'/> event. |
| 64 | + /// </summary> |
| 65 | + public Keys KeyData { get; } |
53 | 66 |
|
| 67 | + /// <summary> |
| 68 | + /// Gets the modifier flags for a <see cref='Forms.Control.KeyDown'/> or |
| 69 | + /// <see cref='Forms.Control.KeyUp'/> event. |
| 70 | + /// This indicates which modifier keys (CTRL, SHIFT, and/or ALT) were pressed. |
| 71 | + /// </summary> |
54 | 72 | public Keys Modifiers => KeyData & Keys.Modifiers; |
55 | 73 |
|
56 | | - public virtual bool Shift => KeyData.HasFlag (Keys.Shift); |
| 74 | + /// <summary> |
| 75 | + /// Gets a value indicating whether the SHIFT key was pressed. |
| 76 | + /// </summary> |
| 77 | + public virtual bool Shift => (KeyData & Keys.Shift) == Keys.Shift; |
57 | 78 |
|
| 79 | + /// <summary> |
| 80 | + /// Gets or sets a value indicating the key press should be suppressed. |
| 81 | + /// </summary> |
58 | 82 | public bool SuppressKeyPress { |
59 | | - get => supress_key_press; |
| 83 | + get => _suppressKeyPress; |
60 | 84 | set { |
61 | | - supress_key_press = value; |
| 85 | + _suppressKeyPress = value; |
62 | 86 | Handled = value; |
63 | 87 | } |
64 | 88 | } |
|
0 commit comments