Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WinImm32Ime.cs
Go to the documentation of this file.
1using System;
3using System.Text;
6
8
10{
11 private IntPtr _hWnd;
12
13 private IntPtr _hImc;
14
15 private bool _isFocused;
16
18
19 private bool _disposedValue;
20
21 private string _compString;
22
23 private string[] _candList = Array.Empty<string>();
24
25 private uint _candSelection;
26
27 private uint _candPageSize;
28
29 public uint SelectedPage
30 {
31 get
32 {
33 if (_candPageSize != 0)
34 {
36 }
37 return 0u;
38 }
39 }
40
41 public override string CompositionString => _compString;
42
43 public override bool IsCandidateListVisible => CandidateCount != 0;
44
46
47 public override uint CandidateCount => Math.Min((uint)_candList.Length - SelectedPage * _candPageSize, _candPageSize);
48
59
60 private void SetEnabled(bool bEnable)
61 {
63 }
64
79
80 private string GetCompositionString()
81 {
83 try
84 {
86 if (size == 0)
87 {
88 return "";
89 }
90 Span<byte> buf = stackalloc byte[size];
92 return Encoding.Unicode.GetString(buf.ToArray());
93 }
94 finally
95 {
97 }
98 }
99
100 private void UpdateCandidateList()
101 {
103 try
104 {
106 if (size == 0)
107 {
108 _candList = Array.Empty<string>();
109 _candPageSize = 0u;
110 _candSelection = 0u;
111 return;
112 }
113 Span<byte> buf = stackalloc byte[size];
114 ReLogic.Localization.IME.WinImm32.NativeMethods.ImmGetCandidateList(hImc, 0u, ref MemoryMarshal.GetReference(buf), size);
115 ref CandidateList candList = ref MemoryMarshal.AsRef<CandidateList>(buf);
116 ReadOnlySpan<uint> offsets = MemoryMarshal.CreateReadOnlySpan(ref candList.dwOffset, (int)candList.dwCount);
117 string[] candStrList = new string[candList.dwCount];
118 int next = buf.Length;
119 for (int i = (int)(candList.dwCount - 1); i >= 0; i--)
120 {
121 int start = (int)offsets[i];
122 int num = i;
123 Encoding unicode = Encoding.Unicode;
124 Span<byte> span = buf;
125 int num2 = start;
126 candStrList[num] = unicode.GetString(span.Slice(num2, next - 2 - num2));
127 next = start;
128 }
129 _candList = candStrList;
130 _candPageSize = candList.dwPageSize;
131 _candSelection = candList.dwSelection;
132 }
133 finally
134 {
136 }
137 }
138
139 public override string GetCandidate(uint index)
140 {
141 if (index < CandidateCount)
142 {
144 }
145 return "";
146 }
147
148 protected override void OnEnable()
149 {
150 if (_isFocused)
151 {
152 SetEnabled(bEnable: true);
153 }
154 }
155
156 protected override void OnDisable()
157 {
159 SetEnabled(bEnable: false);
160 }
161
162 public bool PreFilterMessage(ref Message message)
163 {
164 if (message.Msg == 8)
165 {
166 SetEnabled(bEnable: false);
167 _isFocused = false;
168 return true;
169 }
170 if (message.Msg == 7)
171 {
172 if (base.IsEnabled)
173 {
174 SetEnabled(bEnable: true);
175 }
176 _isFocused = true;
177 return true;
178 }
179 if (message.Msg == 641)
180 {
181 message.LParam = IntPtr.Zero;
182 return false;
183 }
184 if (!base.IsEnabled)
185 {
186 return false;
187 }
188 switch (message.Msg)
189 {
190 case 81:
191 return true;
192 case 269:
193 _compString = "";
194 return true;
195 case 271:
197 break;
198 case 270:
199 _compString = "";
201 break;
202 case 642:
203 {
204 int num = message.WParam.ToInt32();
205 if ((uint)(num - 3) <= 2u)
206 {
208 }
209 return true;
210 }
211 case 258:
212 OnKeyPress((char)message.WParam.ToInt32());
213 break;
214 }
215 return false;
216 }
217
218 protected override void Dispose(bool disposing)
219 {
220 if (!_disposedValue)
221 {
222 if (base.IsEnabled)
223 {
224 Disable();
225 }
228 _disposedValue = true;
229 }
230 }
231
233 {
234 Dispose(disposing: false);
235 }
236}
void FinalizeString(bool bSend=false)
bool PreFilterMessage(ref Message message)
override void Dispose(bool disposing)
override string GetCandidate(uint index)
WinImm32Ime(WindowsMessageHook wndProcHook, IntPtr hWnd)
static IntPtr ImmAssociateContext(IntPtr hWnd, IntPtr hImc)
static int ImmGetCandidateList(IntPtr hImc, uint dwIndex, ref byte lpCandList, int dwBufLen)
static bool ImmReleaseContext(IntPtr hWnd, IntPtr hImc)
static bool ImmNotifyIME(IntPtr hImc, uint dwAction, uint dwIndex, uint dwValue)
static bool ImmSetCompositionString(IntPtr hImc, uint dwIndex, string lpComp, int dwCompLen, string lpRead, int dwReadLen)
static int ImmGetCompositionString(IntPtr hImc, uint dwIndex, ref byte lpBuf, int dwBufLen)
static IntPtr GetForegroundWindow()
void AddMessageFilter(IMessageFilter filter)
void RemoveMessageFilter(IMessageFilter filter)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static Encoding Unicode
Definition Encoding.cs:519
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
static readonly IntPtr Zero
Definition IntPtr.cs:18
Span< T > Slice(int start)
Definition Span.cs:271
static Span< T > Empty
Definition Span.cs:87
T[] ToArray()
Definition Span.cs:291
int Length
Definition Span.cs:70