-
Notifications
You must be signed in to change notification settings - Fork 20
/
Globals.h
269 lines (202 loc) · 7.13 KB
/
Globals.h
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
/* DIME IME for Windows 7/8/10/11
BSD 3-Clause License
Copyright (c) 2022, Jeremy Wu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GLOBAL_H
#define GLOBAL_H
#pragma once
#include "private.h"
#include "define.h"
#include "BaseStructure.h"
#include "Config.h"
void DllAddRef();
void DllRelease();
namespace Global {
extern IME_MODE imeMode;
extern BOOL isWindows8; //OS Version
extern HFONT defaultlFontHandle; // Global font object we use everywhere
extern BOOL hasPhraseSection; // the dictionary file has TTS [Phrase] section
extern BOOL hasCINPhraseSection; // the dictionary file has CIN %phrasedef section
extern const WCHAR UnicodeByteOrderMark;
extern WCHAR KeywordDelimiter;
extern const WCHAR StringDelimiter;
extern const CLSID DIMECLSID;
extern const GUID DIMEDayiGuidProfile;
extern const GUID DIMEArrayGuidProfile;
extern const GUID DIMEPhoneticGuidProfile;
extern const GUID DIMEGenericGuidProfile;
extern const GUID DIMEGuidImeModePreserveKey;
extern const GUID DIMEGuidDoubleSingleBytePreserveKey;
extern const GUID DIMEGuidConfigPreserveKey;
#ifndef DIMESettings
//---------------------------------------------------------------------
// inline
//---------------------------------------------------------------------
inline void SafeRelease(_In_ IUnknown *punk)
{
if (punk != nullptr)
{
punk->Release();
}
}
inline void QuickVariantInit(_Inout_ VARIANT *pvar)
{
pvar->vt = VT_EMPTY;
}
inline void QuickVariantClear(_Inout_ VARIANT *pvar)
{
switch (pvar->vt)
{
// some ovbious VTs that don't need to call VariantClear.
case VT_EMPTY:
case VT_NULL:
case VT_I2:
case VT_I4:
case VT_R4:
case VT_R8:
case VT_CY:
case VT_DATE:
case VT_I1:
case VT_UI1:
case VT_UI2:
case VT_UI4:
case VT_I8:
case VT_UI8:
case VT_INT:
case VT_UINT:
case VT_BOOL:
break;
// Call release for VT_UNKNOWN.
case VT_UNKNOWN:
SafeRelease(pvar->punkVal);
break;
default:
// we call OleAut32 for other VTs.
VariantClear(pvar);
break;
}
pvar->vt = VT_EMPTY;
}
//+---------------------------------------------------------------------------
//
// IsTooSimilar
//
// Return TRUE if the colors cr1 and cr2 are so similar that they
// are hard to distinguish. Used for deciding to use reverse video
// selection instead of system selection colors.
//
//----------------------------------------------------------------------------
inline BOOL IsTooSimilar(COLORREF cr1, COLORREF cr2)
{
if ((cr1 | cr2) & 0xFF000000) // One color and/or the other isn't RGB, so algorithm doesn't apply
{
return FALSE;
}
LONG DeltaR = abs(GetRValue(cr1) - GetRValue(cr2));
LONG DeltaG = abs(GetGValue(cr1) - GetGValue(cr2));
LONG DeltaB = abs(GetBValue(cr1) - GetBValue(cr2));
return DeltaR + DeltaG + DeltaB < 80;
}
//---------------------------------------------------------------------
// extern
//---------------------------------------------------------------------
extern HINSTANCE dllInstanceHandle;
extern HINSTANCE hShcore;
extern ATOM AtomCandidateWindow;
extern ATOM AtomCandidateShadowWindow;
extern ATOM AtomCandidateScrollBarWindow;
extern ATOM AtomNotifyWindow;
extern ATOM AtomNotifyShadowWindow;
BOOL RegisterWindowClass();
extern LONG dllRefCount;
extern CRITICAL_SECTION CS;
extern const CLSID DIMECLSID;
extern const GUID DIMEDayiGuidProfile;
extern const GUID DIMEArrayGuidProfile;
extern const GUID DIMEPhoneticGuidProfile;
extern const GUID DIMEGenericGuidProfile;
extern const GUID DIMEGuidImeModePreserveKey;
extern const GUID DIMEGuidDoubleSingleBytePreserveKey;
extern const GUID DIMEGuidConfigPreserveKey;
LRESULT CALLBACK ThreadKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
BOOL CheckModifiers(UINT uModCurrent, UINT uMod);
BOOL UpdateModifiers(WPARAM wParam, LPARAM lParam);
extern USHORT ModifiersValue;
extern BOOL IsShiftKeyDownOnly;
extern BOOL IsControlKeyDownOnly;
extern BOOL IsAltKeyDownOnly;
extern const GUID DIMEGuidCompartmentIMEMode;
extern const GUID DIMEGuidCompartmentDoubleSingleByte;
extern const WCHAR FullWidthCharTable[];
extern const WCHAR DayiSymbolCharTable[];
extern const _DAYI_ADDRESS_DIRECT_INPUT dayiAddressCharTable[6];
extern const _DAYI_ADDRESS_DIRECT_INPUT dayiArticleCharTable[6];
extern const GUID DIMEGuidLangBarIMEMode;
extern const GUID DIMEGuidLangBarDoubleSingleByte;
extern const GUID DIMEGuidDisplayAttributeInput;
extern const GUID DIMEGuidDisplayAttributeConverted;
extern const GUID DIMEGuidCandUIElement;
extern WCHAR ImeModeDescription[50];
extern const int ImeModeOnIcoIndex;
extern const int ImeModeOffIcoIndex;
extern WCHAR DoubleSingleByteDescription[50];
extern const int DoubleSingleByteOnIcoIndex;
extern const int DoubleSingleByteOffIcoIndex;
extern const WCHAR LangbarImeModeDescription[];
extern const WCHAR LangbarDoubleSingleByteDescription[];
extern const WCHAR LangbarPunctuationDescription[];
#endif
}
#ifdef DEBUG_PRINT
#include <ShlObj.h>
#include <Shlwapi.h>
#include <stdarg.h>
#include <stdio.h>
inline static void debugPrint(const WCHAR* format,...)
{
WCHAR wszAppData[MAX_PATH];
if (SHGetSpecialFolderPath(NULL, wszAppData, CSIDL_APPDATA, TRUE))
{
StringCchPrintf(wszAppData, MAX_PATH, L"%s\\%s", wszAppData, L"DIME\\");
if (PathFileExists(wszAppData))
CreateDirectory(wszAppData, NULL);
}
WCHAR wszDebugLogPath[MAX_PATH];
StringCchPrintf(wszDebugLogPath, MAX_PATH, L"%s\\%s", wszAppData, L"debug.txt");
FILE *fp;
_wfopen_s(&fp, wszDebugLogPath, L"a, ccs=UTF-8");
if(fp)
{
va_list args;
va_start (args, format);
vfwprintf_s(fp, format, args);
va_end (args);
fwprintf_s(fp, L"\n");
fclose(fp);
}
}
#else
inline static void debugPrint(const WCHAR* format,...) {format;}
#endif
#endif