forked from ms-iot/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyModel.cs
More file actions
222 lines (206 loc) · 7.15 KB
/
KeyModel.cs
File metadata and controls
222 lines (206 loc) · 7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
Copyright(c) Microsoft Open Technologies, Inc.All rights reserved.
The MIT License(MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
**/
using System;
namespace OnScreenKeyboardSample
{
/// <summary>
/// A KeyModel defines what is assigned to one keyboard key (which we're calling key-buttons).
/// </summary>
public class KeyModel : ViewModel
{
public KeyModel()
{
this.UnshiftedCodePoint = '?';
}
/// <param name="iCodePoint">The Unicode codepoint for this particular key-button</param>
/// <param name="isThisALetter">Indicates whether this is an alphabetic letter</param>
public KeyModel(int iCodePoint, bool isLetter)
{
UnshiftedCodePoint = (char)iCodePoint;
ShiftedCodePoint = (char)0;
IsLetter = isLetter;
}
/// <param name="iCodePoint">The Unicode codepoint for this particular key-button</param>
/// <param name="iShiftedCodePoint">The Unicode codepoint to use when in the SHIFT state</param>
public KeyModel(int iCodePoint, int iShiftedCodePoint)
{
UnshiftedCodePoint = (char)iCodePoint;
ShiftedCodePoint = (char)iShiftedCodePoint;
IsLetter = true;
}
/// <summary>
/// Get the Unicode code-point (as a string) that's assigned to this key-button, as a function of it's shifted or alt state.
/// </summary>
public virtual string CodePointString
{
get
{
if (theKeyboardViewModel != null)
{
if ((theKeyboardViewModel.IsShiftLock || (isThisALetter && theKeyboardViewModel.IsCapsLock)) && shiftedCodePoint != 0)
{
return ((char)ShiftedCodePoint).ToString();
}
else
{
return ((char)UnshiftedCodePoint).ToString();
}
}
else
{
return "-";
}
}
}
public char UnshiftedCodePoint
{
get { return unshiftedCodePoint; }
set
{
if (value != unshiftedCodePoint)
{
unshiftedCodePoint = value;
}
}
}
public char ShiftedCodePoint
{
get { return shiftedCodePoint; }
set
{
if (value != shiftedCodePoint)
{
shiftedCodePoint = value;
Notify("Text");
}
}
}
public bool IsLetter
{
get { return isThisALetter; }
set { isThisALetter = value; }
}
/// <summary>
/// Get the button name of the WPF Button that this is a view-model of.
/// </summary>
public string KeyName
{
get
{
if (String.IsNullOrEmpty(keyName))
{
return "";
}
else
{
return keyName;
}
}
set { keyName = value; }
}
/// <summary>
/// Get a name to identify this key by, whether the display-name or the KeyName.
/// </summary>
public string Name
{
get
{
if (this.KeyName != string.Empty)
{
return this.KeyName;
}
else
{
return "NA";
}
}
}
/// <summary>
/// Get the Text to be shown on the corresponding Button
/// </summary>
public virtual string Text
{
get
{
{
string sText;
if (!String.IsNullOrEmpty(text))
{
sText = text;
}
else
{
sText = this.CodePointString;
}
return sText;
}
}
}
/// <summary>
/// This flag indicates whether this key-button contains a 'letter'.
/// </summary>
protected bool isThisALetter;
protected string keyName;
protected string text;
public static KeyboardViewModel theKeyboardViewModel;
protected char unshiftedCodePoint; // the character you normally get from this key-button.
protected char shiftedCodePoint; // the character you get when the Shift key is active.
}
public class KeyModelWithTwoGlyphs : KeyModel
{
public KeyModelWithTwoGlyphs(): base() {}
/// <param name="iCodePoint">The Unicode codepoint for this particular key-button</param>
/// <param name="iShiftedCodePoint">The Unicode codepoint to use when in the SHIFT state</param>
/// <param name="isThisALetter">Indicates whether this is an alphabetic letter</param>
public KeyModelWithTwoGlyphs(int iCodePoint, int iShiftedCodePoint, bool isLetter)
{
UnshiftedCodePoint = (char)iCodePoint;
ShiftedCodePoint = (char)iShiftedCodePoint;
IsLetter = isLetter;
}
/// <returns>A description of the state of this object, or else if in design-time just the key-name</returns>
public override string ToString()
{
return CodePointString;
}
}
public class ShiftKeyViewModel : KeyModel
{
public ShiftKeyViewModel()
{
}
/// <summary>
/// Get/set whether we are in the Shift state.
/// </summary>
public bool IsInShiftState
{
get { return isInShiftState; }
set
{
if (value != isInShiftState)
{
isInShiftState = value;
Notify("Text");
}
}
}
private bool isInShiftState;
}
}