2
#A part of NonVisual Desktop Access (NVDA)
3
#Copyright (C) 2006-2010 NVDA Contributors <http://www.nvda-project.org/>
4
#This file is covered by the GNU General Public License.
5
#See the file COPYING for more details.
11
// nvdajpime.cpp : DLL アプリケーション用にエクスポートされる関数を定義します。
14
#include "nvdajpime.h"
20
void* __RPC_USER midl_user_allocate(size_t size) {
24
void __RPC_USER midl_user_free(void* p) {
31
Cnvdajpime* g_Cnvdajpime;
34
DWORD TLS::dwTLSIndex = TLS_OUT_OF_INDEXES;
36
CnvdajpimeSharedMem g_SharedMemory;
41
wchar_t desktopSpecificNamespace[64];
42
generateDesktopSpecificNamespace(desktopSpecificNamespace,ARRAYSIZE(desktopSpecificNamespace));
44
s<<L"ncalrpc:[NvdaCtlr."<<desktopSpecificNamespace<<L"]";
45
RpcBindingFromStringBinding((RPC_WSTR)(s.str().c_str()),&nvdaControllerBindingHandle);
46
nvdajpimeRPC_speakText(buff);
47
//nvdajpimeRPC_speakIme(13,buff,0,buff,buff,0);
48
RpcBindingFree(&nvdaControllerBindingHandle);
58
wchar_t desktopSpecificNamespace[64];
59
generateDesktopSpecificNamespace(desktopSpecificNamespace,ARRAYSIZE(desktopSpecificNamespace));
61
s<<L"ncalrpc:[NvdaCtlr."<<desktopSpecificNamespace<<L"]";
62
RpcBindingFromStringBinding((RPC_WSTR)(s.str().c_str()),&nvdaControllerBindingHandle);
63
//nvdajpimeRPC_speakText(buff);
64
nvdajpimeRPC_speakIme(13,L"",0,buff,L"",0);
65
RpcBindingFree(&nvdaControllerBindingHandle);
75
WCHAR* Diff(WCHAR* pOld,WCHAR* pNew,UINT pFirstCode,UINT pLastCode)
78
std::wstring Old(pOld);
79
std::wstring New(pNew);
80
std::wstring Dif(L"");
81
WCHAR Ret[256]={NULL};
87
case 28: // VK_CONVERT
97
wsprintf(Ret,L"%s",New.c_str());
98
else if(pFirstCode!=pLastCode) //@@
99
wsprintf(Ret,L"%s",New.c_str()); //@@
100
else if(pFirstCode==38) //@@
101
wsprintf(Ret,L"%s",New.c_str()); //@@
102
else if(pFirstCode==40) //@@
103
wsprintf(Ret,L"%s",New.c_str()); //@@
105
wsprintf(Ret,L"%s",L"");
113
for(int i=(UINT)Old.length()-1,j=(UINT)New.length()-1;(i>=0)&&(j>=0);i--,j--) //@@
118
wsprintf(Ret,L"%s",Dif.c_str());
123
if(Old[i-1]!=New[j-1])
126
if( Dif.compare(std::wstring(L"ゃ")) == 0 )
127
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
128
else if (Dif.compare(std::wstring(L"ゅ")) == 0 )
129
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
130
else if (Dif.compare(std::wstring(L"ょ")) == 0 )
131
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
132
else if (Dif.compare(std::wstring(L"ぁ")) == 0 )
133
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
134
else if (Dif.compare(std::wstring(L"ぃ")) == 0 )
135
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
136
else if (Dif.compare(std::wstring(L"ぉ")) == 0 )
137
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
140
else if (Dif.compare(std::wstring(L"ャ")) == 0 )
141
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
142
else if (Dif.compare(std::wstring(L"ュ")) == 0 )
143
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
144
else if (Dif.compare(std::wstring(L"ョ")) == 0 )
145
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
146
else if (Dif.compare(std::wstring(L"ァ")) == 0 )
147
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
148
else if (Dif.compare(std::wstring(L"ィ")) == 0 )
149
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
150
else if (Dif.compare(std::wstring(L"ォ")) == 0 )
151
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
154
else if (Dif.compare(std::wstring(L"ャ")) == 0 )
155
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
156
else if (Dif.compare(std::wstring(L"ュ")) == 0 )
157
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
158
else if (Dif.compare(std::wstring(L"ョ")) == 0 )
159
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
160
else if (Dif.compare(std::wstring(L"ァ")) == 0 )
161
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
162
else if (Dif.compare(std::wstring(L"ィ")) == 0 )
163
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
164
else if (Dif.compare(std::wstring(L"ォ")) == 0 )
165
wsprintf(Ret,L"%s",New.substr(j-1,2).c_str());
176
if(Dif.empty() & (Old.length()<New.length()) )
178
Dif = New[New.length()-1];
179
wsprintf(Ret,L"%s",Dif.c_str());
185
BOOL GetIMMOpenStatus()
193
return GetSharedMemory()->ImeOpenStatus;
195
himc = ImmGetContext(hwnd);
198
Ret = ImmGetOpenStatus(himc);
199
ImmReleaseContext(hwnd, himc);
207
UINT WINAPI Cnvdajpime::Thread(void *p_this)
209
Cnvdajpime* m_this = reinterpret_cast<Cnvdajpime*>(p_this);
211
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, EVENT_NAME);
213
while(m_this->m_RunFlag)
216
WaitForSingleObject(hEvent, INFINITE);
220
m_this->m_Result.ImeOpenStatus=GetSharedMemory()->ImeOpenStatus;
222
wsprintf(m_this->m_Result.OldValue,L"%s",m_this->m_Result.NewValue);
223
wsprintf(m_this->m_Result.NewValue,L"%s",GetSharedMemory()->TextValue);
224
wsprintf(m_this->m_Result.DiffValue,L"%s",Diff(m_this->m_Result.OldValue,m_this->m_Result.NewValue,m_this->m_Result.LastKeyCode,GetSharedMemory()->LastKeyCode));
226
m_this->m_Result.LastKeyCode=GetSharedMemory()->LastKeyCode;
228
if(m_this->m_CallBack!=NULL)
231
m_this->m_Result.LastKeyCode,
232
m_this->m_Result.DiffValue,
233
m_this->m_Result.ImeOpenStatus,
234
m_this->m_Result.OldValue,
235
m_this->m_Result.NewValue
238
/////////////////////////////////////////////////////////////
240
if(m_this->m_Result.DiffValue[0]!=0)
242
wchar_t desktopSpecificNamespace[64];
243
generateDesktopSpecificNamespace(desktopSpecificNamespace,ARRAYSIZE(desktopSpecificNamespace));
245
s<<L"ncalrpc:[NvdaCtlr."<<desktopSpecificNamespace<<L"]";
246
RpcBindingFromStringBinding((RPC_WSTR)(s.str().c_str()),&nvdaControllerBindingHandle);
248
if(nvdajpimeRPC_testIfRunning()==0)
250
nvdajpimeRPC_speakText(m_this->m_Result.DiffValue);
252
RpcBindingFree(&nvdaControllerBindingHandle);
270
//+---------------------------------------------------------------------------
272
//+---------------------------------------------------------------------------
274
UINT _SysGetMsgProc(WPARAM wParam, LPARAM lParam)
279
pmsg = (MSG *)lParam;
280
uMsg = pmsg->message;
288
case WM_IME_STARTCOMPOSITION:
290
case WM_IME_ENDCOMPOSITION:
292
case WM_IME_COMPOSITION:
295
if ( GetAsyncKeyState(VK_SPACE) & 0x8000 )
297
GetSharedMemory()->NewKeyCode = VK_SPACE;
300
else if ( GetAsyncKeyState(VK_CONVERT) & 0x8000 )
302
GetSharedMemory()->NewKeyCode = VK_CONVERT;
304
else if ( GetAsyncKeyState(VK_UP) & 0x8000 )
306
GetSharedMemory()->NewKeyCode = VK_UP;
308
else if ( GetAsyncKeyState(VK_DOWN) & 0x8000 )
310
GetSharedMemory()->NewKeyCode = VK_DOWN;
312
else if ( GetAsyncKeyState(VK_F6) & 0x8000 )
314
GetSharedMemory()->NewKeyCode = VK_F6;
316
else if ( GetAsyncKeyState(VK_F7) & 0x8000 )
318
GetSharedMemory()->NewKeyCode = VK_F7;
320
else if ( GetAsyncKeyState(VK_F8) & 0x8000 )
322
GetSharedMemory()->NewKeyCode = VK_F8;
324
else if ( GetAsyncKeyState(VK_F9) & 0x8000 )
326
GetSharedMemory()->NewKeyCode = VK_F9;
328
else if ( GetAsyncKeyState(VK_F10) & 0x8000 )
330
GetSharedMemory()->NewKeyCode = VK_F10;
332
else if ( GetAsyncKeyState(VK_RETURN) & 0x8000 )
334
GetSharedMemory()->NewKeyCode = VK_RETURN;
335
if(GetSharedMemory()->ImeOpenStatus)
337
yy(GetSharedMemory()->NewValue);
342
GetSharedMemory()->NewKeyCode = 0;
345
if(GetSharedMemory()->ImeOpenStatus)
347
GetSharedMemory()->TsfMode=TRUE;
348
CnvdajpimeTSF::Init();
354
ImeStatus=GetIMMOpenStatus();
355
if(ImeStatus!=GetSharedMemory()->ImeOpenStatus)
357
GetSharedMemory()->ImeOpenStatus=ImeStatus;
358
if ( GetAsyncKeyState(VK_OEM_COPY) & 0x8000 )
360
GetSharedMemory()->NewKeyCode = VK_OEM_COPY;
362
else if ( GetAsyncKeyState(VK_OEM_AUTO) & 0x8000 )
364
GetSharedMemory()->NewKeyCode = VK_OEM_AUTO;
366
else if ( GetAsyncKeyState(VK_OEM_ENLW) & 0x8000 )
368
GetSharedMemory()->NewKeyCode = VK_OEM_ENLW;
370
else if ( GetAsyncKeyState(VK_KANJI) & 0x8000 ) // ALT-` (us-keyboard)
372
GetSharedMemory()->NewKeyCode = VK_KANJI;
376
GetSharedMemory()->NewKeyCode = 0;
379
if(((GetSharedMemory()->NewKeyCode==VK_OEM_COPY)||(GetSharedMemory()->NewKeyCode==VK_OEM_AUTO)||(GetSharedMemory()->NewKeyCode==VK_KANJI))
384
else if(GetSharedMemory()->NewKeyCode!=0)
394
//+---------------------------------------------------------------------------
396
//+---------------------------------------------------------------------------
398
LRESULT CALLBACK SysGetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
402
hHook = GetSharedMemory()->hSysGetMsgHook;
404
if (nCode == HC_ACTION && (wParam & PM_REMOVE))
406
_SysGetMsgProc(wParam, lParam);
408
return CallNextHookEx(hHook, nCode, wParam, lParam);
411
//+---------------------------------------------------------------------------
415
//+---------------------------------------------------------------------------
417
LRESULT CALLBACK SysGetMsgProc2(int nCode, WPARAM wParam, LPARAM lParam)
420
hHook = GetSharedMemory()->hSysGetMsgHook2;
421
GetSharedMemory()->NewKeyCode = (UINT)wParam;
422
return CallNextHookEx(hHook, nCode, wParam, lParam);
425
//////////////////////////////////////////////////////////////////////////////
427
Cnvdajpime::Cnvdajpime()
432
//////////////////////////////////////////////////////////////////////////////
434
Cnvdajpime::~Cnvdajpime()
439
//////////////////////////////////////////////////////////////////////////////
441
extern "C" NVDAJPIME_API BOOL WINAPI Initialize(void)
444
g_Cnvdajpime = new Cnvdajpime();
446
HHOOK hSysGetMsgHook = SetWindowsHookEx(
453
GetSharedMemory()->hSysGetMsgHook = hSysGetMsgHook;
457
HHOOK hSysGetMsgHook2 = SetWindowsHookEx(
463
if (!hSysGetMsgHook2)
465
GetSharedMemory()->hSysGetMsgHook2 = hSysGetMsgHook2; // Masataka.Shinke
468
GetSharedMemory()->TsfMode=FALSE;
470
GetSharedMemory()->OldKeyCode=0;
471
GetSharedMemory()->NewKeyCode=0;
473
wsprintf(GetSharedMemory()->TextValue,L"%s",L"");
474
wsprintf(GetSharedMemory()->DiffValue,L"%s",L"");
475
wsprintf(GetSharedMemory()->OldValue,L"%s",L"");
476
wsprintf(GetSharedMemory()->NewValue,L"%s",L"");
479
GetSharedMemory()->fReadCompRunning = TRUE;
480
GetSharedMemory()->ImeOpenStatus=TRUE;
485
//////////////////////////////////////////////////////////////////////////////
487
extern "C" NVDAJPIME_API BOOL WINAPI Terminate(void)
492
GetSharedMemory()->fReadCompRunning = FALSE;
495
HHOOK hSysGetMsgHook2 = GetSharedMemory()->hSysGetMsgHook2;
496
UnhookWindowsHookEx(hSysGetMsgHook2);
499
HHOOK hSysGetMsgHook = GetSharedMemory()->hSysGetMsgHook;
500
UnhookWindowsHookEx(hSysGetMsgHook);