forked from jrywu/DIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Globals.cpp
464 lines (391 loc) · 15.6 KB
/
Globals.cpp
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
//
//
// Derived from Microsoft Sample IME by Jeremy '13,7,17
//
//
#include <map>
#include "Globals.h"
#include "Private.h"
#include "resource.h"
#include "BaseWindow.h"
#include "define.h"
#include "BaseStructure.h"
namespace Global {
HINSTANCE dllInstanceHandle;
LONG dllRefCount = -1;
BOOL isWindows8 = FALSE;
_T_GetDpiForMonitor _GetDpiForMonitor = nullptr;
HINSTANCE hShcore = NULL;
IME_MODE imeMode = IME_MODE_NONE;
BOOL hasPhraseSection = FALSE;
BOOL hasCINPhraseSection = FALSE;
CRITICAL_SECTION CS;
HFONT defaultlFontHandle; // Global font object we use everywhere
//---------------------------------------------------------------------
// DIME CLSID
//---------------------------------------------------------------------
// {1DE68A87-FF3B-46A0-8F80-46730B2491B1}
extern const CLSID DIMECLSID =
{ 0x1de68a87, 0xff3b, 0x46a0, { 0x8f, 0x80, 0x46, 0x73, 0xb, 0x24, 0x91, 0xb1 } };
//---------------------------------------------------------------------
// TSFDayiProfile GUID
//---------------------------------------------------------------------
// {36851834-92AD-4397-9F50-800384D5C24C}
extern const GUID DIMEDayiGuidProfile =
{ 0x36851834, 0x92ad, 0x4397, { 0x9f, 0x50, 0x80, 0x3, 0x84, 0xd5, 0xc2, 0x4c } };
//---------------------------------------------------------------------
// TSFArrayProfile GUID
//---------------------------------------------------------------------
// {5DFC1743-638C-4F61-9E76-FCFA9707F450}
extern const GUID DIMEArrayGuidProfile =
{ 0x5dfc1743, 0x638c, 0x4f61, { 0x9e, 0x76, 0xfc, 0xfa, 0x97, 0x7, 0xf4, 0x50 } };
//---------------------------------------------------------------------
// TSFPhoneticProfile GUID
//---------------------------------------------------------------------
// {26892981-14E3-447B-AF2C-9067CD4A4A8A}
extern const GUID DIMEPhoneticGuidProfile =
{ 0x26892981, 0x14e3, 0x447b, { 0xaf, 0x2c, 0x90, 0x67, 0xcd, 0x4a, 0x4a, 0x8a } };
//---------------------------------------------------------------------
// TSFGenericProfile GUID
//---------------------------------------------------------------------
// {061BEEA7-FFF9-420C-B3F6-A9047AFD0877}
extern const GUID DIMEGenericGuidProfile =
{ 0x61beea7, 0xfff9, 0x420c, { 0xb3, 0xf6, 0xa9, 0x4, 0x7a, 0xfd, 0x8, 0x77 } };
//---------------------------------------------------------------------
// PreserveKey GUID
//---------------------------------------------------------------------
// {3C4173E2-D908-419B-BEE0-89FDF46456A2}
extern const GUID DIMEGuidImeModePreserveKey =
{ 0x3c4173e2, 0xd908, 0x419b, { 0xbe, 0xe0, 0x89, 0xfd, 0xf4, 0x64, 0x56, 0xa2 } };
// {B9F1B6BA-CCCF-478F-B7C2-89B0D9442A38}
extern const GUID DIMEGuidDoubleSingleBytePreserveKey =
{ 0xb9f1b6ba, 0xcccf, 0x478f, { 0xb7, 0xc2, 0x89, 0xb0, 0xd9, 0x44, 0x2a, 0x38 } };
// {6EA68D83-9FC2-40A6-BB30-52E77FABDEC7}
extern const GUID DIMEGuidConfigPreserveKey =
{ 0x6ea68d83, 0x9fc2, 0x40a6, { 0xbb, 0x30, 0x52, 0xe7, 0x7f, 0xab, 0xde, 0xc7 } };
//---------------------------------------------------------------------
// Compartments
//---------------------------------------------------------------------
// {91FCB13F-0BA5-4D93-846C-E8A706BB5F2B}
extern const GUID DIMEGuidCompartmentIMEMode =
{ 0x91fcb13f, 0xba5, 0x4d93, { 0x84, 0x6c, 0xe8, 0xa7, 0x6, 0xbb, 0x5f, 0x2b } };
// {176AF217-E72C-4A24-8373-F90581786A5D}
extern const GUID DIMEGuidCompartmentDoubleSingleByte =
{ 0x176af217, 0xe72c, 0x4a24, { 0x83, 0x73, 0xf9, 0x5, 0x81, 0x78, 0x6a, 0x5d } };
//---------------------------------------------------------------------
// LanguageBars
//---------------------------------------------------------------------
// {B9F1B6BA-CCCF-478F-B7C2-89B0D9442A38}
extern const GUID DIMEGuidLangBarIMEMode =
{ 0xb9f1b6ba, 0xcccf, 0x478f, { 0xb7, 0xc2, 0x89, 0xb0, 0xd9, 0x44, 0x2a, 0x38 } };
// {FB007925-ACBE-4AF1-A98B-2701EB68A90B}
extern const GUID DIMEGuidLangBarDoubleSingleByte =
{ 0xfb007925, 0xacbe, 0x4af1, { 0xa9, 0x8b, 0x27, 0x1, 0xeb, 0x68, 0xa9, 0xb } };
// {C1AD6968-5F10-4C73-9125-51A3C70F88A0}
extern const GUID DIMEGuidDisplayAttributeInput =
{ 0xc1ad6968, 0x5f10, 0x4c73, { 0x91, 0x25, 0x51, 0xa3, 0xc7, 0xf, 0x88, 0xa0 } };
extern const GUID DIMEGuidDisplayAttributeConverted =
{ 0x62a68877, 0xc2c1, 0x41ed, { 0x9f, 0x80, 0x54, 0xde, 0xbd, 0x87, 0x9f, 0x74 } };
//---------------------------------------------------------------------
// UI element
//---------------------------------------------------------------------
// {87D9FBA0-C152-475B-BD82-0A18DFA616A7}
extern const GUID DIMEGuidCandUIElement =
{ 0x87d9fba0, 0xc152, 0x475b, { 0xbd, 0x82, 0xa, 0x18, 0xdf, 0xa6, 0x16, 0xa7 } };
//---------------------------------------------------------------------
// Unicode byte order mark
//---------------------------------------------------------------------
extern const WCHAR UnicodeByteOrderMark = 0xFEFF;
//---------------------------------------------------------------------
// dictionary table delimiter
//---------------------------------------------------------------------
extern WCHAR KeywordDelimiter = L'=';
extern const WCHAR StringDelimiter = L'\"';
//---------------------------------------------------------------------
// defined item in setting file table [PreservedKey] section
//---------------------------------------------------------------------
extern WCHAR ImeModeDescription[50] = {'\0'};
extern const int ImeModeOnIcoIndex = IME_MODE_ON_ICON_INDEX;
extern const int ImeModeOffIcoIndex = IME_MODE_OFF_ICON_INDEX;
extern WCHAR DoubleSingleByteDescription[50] = {'\0'};
extern const int DoubleSingleByteOnIcoIndex = IME_DOUBLE_ON_INDEX;
extern const int DoubleSingleByteOffIcoIndex = IME_DOUBLE_OFF_INDEX;
//---------------------------------------------------------------------
// defined item in setting file table [LanguageBar] section
//---------------------------------------------------------------------
extern const WCHAR LangbarImeModeDescription[] = L"Conversion mode";
extern const WCHAR LangbarDoubleSingleByteDescription[] = L"Character width";
//---------------------------------------------------------------------
// windows class / titile / atom
//---------------------------------------------------------------------
extern const WCHAR CandidateClassName[] = L"DIME.CandidateWindow";
ATOM AtomCandidateWindow;
extern const WCHAR CandidateShadowClassName[] = L"DIME.CandidateShadowWindow";
ATOM AtomCandidateShadowWindow;
extern const WCHAR CandidateScrollBarClassName[] = L"DIME.CandidateScrollBarWindow";
ATOM AtomCandidateScrollBarWindow;
extern const WCHAR NotifyClassName[] = L"DIME.NotifyWindow";
ATOM AtomNotifyWindow;
extern const WCHAR NotifyShadowClassName[] = L"DIME.NotifyShadowWindow";
ATOM AtomNotifyShadowWindow;
BOOL RegisterWindowClass()
{
if (!CBaseWindow::_InitWindowClass(CandidateClassName, &AtomCandidateWindow))
{
return FALSE;
}
if (!CBaseWindow::_InitWindowClass(CandidateShadowClassName, &AtomCandidateShadowWindow))
{
return FALSE;
}
if (!CBaseWindow::_InitWindowClass(CandidateScrollBarClassName, &AtomCandidateScrollBarWindow))
{
return FALSE;
}
if (!CBaseWindow::_InitWindowClass(NotifyClassName, &AtomNotifyWindow))
{
return FALSE;
}
if (!CBaseWindow::_InitWindowClass(NotifyShadowClassName, &AtomNotifyShadowWindow))
{
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------
// defined full width characters for Double/Single byte conversion
//---------------------------------------------------------------------
extern const WCHAR FullWidthCharTable[] = {
// ! " # $ % & ' ( ) * + , - . /
0x3000, 0xFF01, 0xFF02, 0xFF03, 0xFF04, 0xFF05, 0xFF06, 0xFF07, 0xFF08, 0xFF09, 0xFF0A, 0xFF0B, 0xFF0C, 0xFF0D, 0xFF0E, 0xFF0F,
// 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
0xFF10, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0xFF15, 0xFF16, 0xFF17, 0xFF18, 0xFF19, 0xFF1A, 0xFF1B, 0xFF1C, 0xFF1D, 0xFF1E, 0xFF1F,
// @ A B C D E F G H I J K L M N 0
0xFF20, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F,
// P Q R S T U V W X Y Z [ \ ] ^ _
0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0xFF3B, 0xFF3C, 0xFF3D, 0xFF3E, 0xFF3F,
// ' a b c d e f g h i j k l m n o
0xFF40, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F,
// p q r s t u v w x y z { | } ~
0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0xFF5B, 0xFF5C, 0xFF5D, 0xFF5E
};
//---------------------------------------------------------------------
// defined symbol characters
//---------------------------------------------------------------------
extern const WCHAR DayiSymbolCharTable[] = L" !@\\\"#$%&L\'()+:<>[]^-_`{}|~?";
//---------------------------------------------------------------------
// defined directly input address characters
//---------------------------------------------------------------------
extern const _DAYI_ADDRESS_DIRECT_INPUT dayiAddressCharTable[6] = {
{ L'`', L'巷' },
{L'\'', L'號'},
{L'[', L'路'},
{L']', L'街'},
{L'-', L'鄉'},
{L'\\', L'鎮'}
};
//---------------------------------------------------------------------
// defined directly input full shaped symbols in article modes
//---------------------------------------------------------------------
extern const _DAYI_ADDRESS_DIRECT_INPUT dayiArticleCharTable[6] = {
{ L'`', L':' },
{ L'\'', L',' },
{ L'[', L'。' },
{ L']', L'?' },
{ L'-', L'、' },
{ L'\\', L';' }
};
//+---------------------------------------------------------------------------
//
// CheckModifiers
//
//----------------------------------------------------------------------------
#define TF_MOD_ALLALT (TF_MOD_RALT | TF_MOD_LALT | TF_MOD_ALT)
#define TF_MOD_ALLCONTROL (TF_MOD_RCONTROL | TF_MOD_LCONTROL | TF_MOD_CONTROL)
#define TF_MOD_ALLSHIFT (TF_MOD_RSHIFT | TF_MOD_LSHIFT | TF_MOD_SHIFT)
#define TF_MOD_RLALT (TF_MOD_RALT | TF_MOD_LALT)
#define TF_MOD_RLCONTROL (TF_MOD_RCONTROL | TF_MOD_LCONTROL)
#define TF_MOD_RLSHIFT (TF_MOD_RSHIFT | TF_MOD_LSHIFT)
#define CheckMod(m0, m1, mod) \
if (m1 & TF_MOD_ ## mod ##) \
{ \
if (!(m0 & TF_MOD_ ## mod ##)) \
{ \
return FALSE; \
} \
} \
else \
{ \
if ((m1 ^ m0) & TF_MOD_RL ## mod ##) \
{ \
return FALSE; \
} \
} \
BOOL CheckModifiers(UINT modCurrent, UINT mod)
{
mod &= ~TF_MOD_ON_KEYUP;
if (mod & TF_MOD_IGNORE_ALL_MODIFIER)
{
return TRUE;
}
if (modCurrent == mod)
{
return TRUE;
}
if (modCurrent && !mod)
{
return FALSE;
}
CheckMod(modCurrent, mod, ALT);
CheckMod(modCurrent, mod, SHIFT);
CheckMod(modCurrent, mod, CONTROL);
return TRUE;
}
//+---------------------------------------------------------------------------
//
// UpdateModifiers
//
// wParam - virtual-key code
// lParam - [0-15] Repeat count
// [16-23] Scan code
// [24] Extended key
// [25-28] Reserved
// [29] Context code
// [30] Previous key state
// [31] Transition state
//----------------------------------------------------------------------------
USHORT ModifiersValue = 0;
BOOL IsShiftKeyDownOnly = FALSE;
BOOL IsControlKeyDownOnly = FALSE;
BOOL IsAltKeyDownOnly = FALSE;
BOOL UpdateModifiers(WPARAM wParam, LPARAM lParam)
{
// high-order bit : key down
// low-order bit : toggled
SHORT sksMenu = GetKeyState(VK_MENU);
SHORT sksCtrl = GetKeyState(VK_CONTROL);
SHORT sksShft = GetKeyState(VK_SHIFT);
switch (wParam & 0xff)
{
case VK_MENU:
// is VK_MENU down?
if (sksMenu & 0x8000)
{
// is extended key?
if (lParam & 0x01000000)
{
ModifiersValue |= (TF_MOD_RALT | TF_MOD_ALT);
}
else
{
ModifiersValue |= (TF_MOD_LALT | TF_MOD_ALT);
}
// is previous key state up?
if (!(lParam & 0x40000000))
{
// is VK_CONTROL and VK_SHIFT up?
if (!(sksCtrl & 0x8000) && !(sksShft & 0x8000))
{
IsAltKeyDownOnly = TRUE;
}
else
{
IsShiftKeyDownOnly = FALSE;
IsControlKeyDownOnly = FALSE;
IsAltKeyDownOnly = FALSE;
}
}
}
break;
case VK_CONTROL:
// is VK_CONTROL down?
if (sksCtrl & 0x8000)
{
// is extended key?
if (lParam & 0x01000000)
{
ModifiersValue |= (TF_MOD_RCONTROL | TF_MOD_CONTROL);
ModifiersValue &= TF_MOD_LCONTROL;
}
else
{
ModifiersValue |= (TF_MOD_LCONTROL | TF_MOD_CONTROL);
ModifiersValue &= TF_MOD_RCONTROL;
}
// is previous key state up?
if (!(lParam & 0x40000000))
{
// is VK_SHIFT and VK_MENU up?
if (!(sksShft & 0x8000) && !(sksMenu & 0x8000))
{
IsControlKeyDownOnly = TRUE;
}
else
{
IsShiftKeyDownOnly = FALSE;
IsControlKeyDownOnly = FALSE;
IsAltKeyDownOnly = FALSE;
}
}
}
break;
case VK_SHIFT:
// is VK_SHIFT down?
if (sksShft & 0x8000)
{
// is scan code 0x36(right shift)?
if (((lParam >> 16) & 0x00ff) == 0x36)
{
ModifiersValue |= (TF_MOD_RSHIFT | TF_MOD_SHIFT);
ModifiersValue &= ~TF_MOD_LSHIFT;
}
else
{
ModifiersValue |= (TF_MOD_LSHIFT | TF_MOD_SHIFT);
ModifiersValue &= ~TF_MOD_RSHIFT;
}
// is previous key state up?
if (!(lParam & 0x40000000))
{
// is VK_MENU and VK_CONTROL up?
if (!(sksMenu & 0x8000) && !(sksCtrl & 0x8000))
{
IsShiftKeyDownOnly = TRUE;
}
else
{
IsShiftKeyDownOnly = FALSE;
IsControlKeyDownOnly = FALSE;
IsAltKeyDownOnly = FALSE;
}
}
}
break;
default:
IsShiftKeyDownOnly = FALSE;
IsControlKeyDownOnly = FALSE;
IsAltKeyDownOnly = FALSE;
break;
}
if (!(sksMenu & 0x8000))
{
ModifiersValue &= ~TF_MOD_ALLALT;
}
if (!(sksCtrl & 0x8000))
{
ModifiersValue &= ~TF_MOD_ALLCONTROL;
}
if (!(sksShft & 0x8000))
{
ModifiersValue &= ~TF_MOD_ALLSHIFT;
}
return TRUE;
}
//---------------------------------------------------------------------
// override CompareElements
//---------------------------------------------------------------------
BOOL CompareElements(LCID locale, const CStringRange* pElement1, const CStringRange* pElement2)
{
return (CStringRange::Compare(locale, (CStringRange*)pElement1, (CStringRange*)pElement2) == CSTR_EQUAL) ? TRUE : FALSE;
}
}