This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
forked from ryancheung/MonoGame.IMEHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMEHandler.cs
226 lines (190 loc) · 7.41 KB
/
IMEHandler.cs
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
223
224
225
226
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace MonoGame.IMEHelper
{
public abstract class IMEHandler
{
private static IMEHandler _ImplInstance;
public static IMEHandler ImplInstance
{
get
{
if (_ImplInstance == null)
throw new NotImplementedException("Muset set `IMEHandler.ImplInstance` to an implementation instance.");
return _ImplInstance;
}
set
{
if (_ImplInstance != null)
return;
_ImplInstance = value;
}
}
public static IMEHandler CreateIMEHandler(Game game)
{
#if WINDOWSDX || XNA
return new WinFormsIMEHandler(game, true);
#elif DESKTOPGL || FNA
return new SdlIMEHandler(game, true);
#endif
}
/// <summary>
/// Game Instance
/// </summary>
public Game GameInstance { get; private set; }
public bool ShowDefaultIMEWindow { get; private set; }
protected IMEHandler(Game game, bool showDefaultIMEWindow = false)
{
this.GameInstance = game;
this.ShowDefaultIMEWindow = showDefaultIMEWindow;
PlatformInitialize();
}
/// <summary>
/// Platform specific initialization.
/// </summary>
public abstract void PlatformInitialize();
/// <summary>
/// Check if text composition is enabled currently.
/// </summary>
public abstract bool Enabled { get; protected set; }
/// <summary>
/// Enable the system IMM service to support composited character input.
/// This should be called when you expect text input from a user and you support languages
/// that require an IME (Input Method Editor).
/// </summary>
/// <seealso cref="EndTextComposition" />
/// <seealso cref="TextComposition" />
public abstract void StartTextComposition();
/// <summary>
/// Stop the system IMM service.
/// </summary>
/// <seealso cref="StartTextComposition" />
/// <seealso cref="TextComposition" />
public abstract void StopTextComposition();
/// <summary>
/// Use this function to set the rectangle used to type Unicode text inputs if IME supported.
/// In SDL2, this method call gives the OS a hint for where to show the candidate text list,
/// since the OS doesn't know where you want to draw the text you received via SDL_TEXTEDITING event.
/// </summary>
public virtual void SetTextInputRect(ref Rectangle rect) { }
/// <summary>
/// Array of the candidates
/// </summary>
public virtual string[] Candidates { get { return null; } }
/// <summary>
/// How many candidates should display per page
/// </summary>
public virtual uint CandidatesPageSize { get { return 0; } }
/// <summary>
/// First candidate index of current page
/// </summary>
public virtual uint CandidatesPageStart { get { return 0; } }
/// <summary>
/// The selected canddiate index
/// </summary>
public virtual uint CandidatesSelection { get { return 0; } }
/// <summary>
/// Composition String
/// </summary>
public virtual string Composition { get { return string.Empty; } }
/// <summary>
/// Composition Clause
/// </summary>
public virtual string CompositionClause { get { return string.Empty; } }
/// <summary>
/// Composition Reading String
/// </summary>
public virtual string CompositionRead { get { return string.Empty; } }
/// <summary>
/// Composition Reading Clause
/// </summary>
public virtual string CompositionReadClause { get { return string.Empty; } }
/// <summary>
/// Caret position of the composition
/// </summary>
public virtual int CompositionCursorPos { get { return 0; } }
/// <summary>
/// Result String
/// </summary>
public virtual string Result { get { return string.Empty; } }
/// <summary>
/// Result Clause
/// </summary>
public virtual string ResultClause { get { return string.Empty; } }
/// <summary>
/// Result Reading String
/// </summary>
public virtual string ResultRead { get { return string.Empty; } }
/// <summary>
/// Result Reading Clause
/// </summary>
public virtual string ResultReadClause { get { return string.Empty; } }
/// <summary>
/// Position Y of virtual keyboard, for mobile platforms has virtual keyboard.
/// </summary>
public virtual int VirtualKeyboardHeight { get { return 0; } }
/// <summary>
/// Get the composition attribute at character index.
/// </summary>
/// <param name="index">Character Index</param>
/// <returns>Composition Attribute</returns>
public virtual CompositionAttributes GetCompositionAttr(int charIndex)
{
return CompositionAttributes.Input;
}
/// <summary>
/// Get the composition read attribute at character index.
/// </summary>
/// <param name="index">Character Index</param>
/// <returns>Composition Attribute</returns>
public virtual CompositionAttributes GetCompositionReadAttr(int charIndex)
{
return CompositionAttributes.Input;
}
/// <summary>
/// Invoked when the IMM service is enabled and a character composition is changed.
/// </summary>
/// <seealso cref="StartTextComposition" />
/// <seealso cref="EndTextComposition" />
public event EventHandler<TextCompositionEventArgs> TextComposition;
/// <summary>
/// Trigger a text composition event.
/// </summary>
/// <param name="compString"></param>
/// <param name="cursorPosition"></param>
/// <param name="candidateList"></param>
public virtual void OnTextComposition(string compString, int cursorPosition, CandidateList? candidateList = null)
{
if (TextComposition != null)
TextComposition(this, new TextCompositionEventArgs(compString, cursorPosition, candidateList));
}
/// <summary>
/// Invoked when the IMM service emit character input event.
/// </summary>
/// <seealso cref="StartTextComposition" />
/// <seealso cref="EndTextComposition" />
public event EventHandler<TextInputEventArgs> TextInput;
/// <summary>
/// Trigger a text input event.
/// </summary>
/// <param name="character"></param>
/// <param name="key"></param>
public virtual void OnTextInput(char character, Keys key = Keys.None)
{
if (TextInput != null)
TextInput(this, new TextInputEventArgs(character, key));
}
/// <summary>
/// Redirect a sdl text input event.
/// </summary>
public virtual void OnTextInput(TextInputEventArgs args)
{
if (TextInput != null)
TextInput(this, args);
}
public virtual void Update(GameTime gameTime)
{
}
}
}