3 #include "../WIn32/Common/WinUTF8.h"
4 #include "IMEConversionHelper.h"
8 #include <iostream> //For testing 23 June 2005
10 CIMEConversionHelper::CIMEConversionHelper() {
12 hIMC
= ImmCreateContext();
16 CIMEConversionHelper::~CIMEConversionHelper() {
17 ImmDestroyContext( hIMC
);
21 bool CIMEConversionHelper::Convert(const std::string
&strSource
, std::vector
<std::vector
<std::string
> > &vResult
) {
23 std::wstring strInput
;
24 WinUTF8::UTF8string_to_wstring(strSource
, strInput
);
28 LPCANDIDATELIST lpCand
;
30 hKL
= GetKeyboardLayout(0);
31 const WCHAR
*pQuery
= strInput
.c_str();
32 //while( wcslen(pQuery) ){
33 dwSize
= ImmGetConversionList(hKL
, hIMC
, (LPCWSTR
)pQuery
, NULL
, 0, GCL_CONVERSION
);
35 lpCand
= (LPCANDIDATELIST
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwSize
);
36 dwSize
= ImmGetConversionList(hKL
, hIMC
, (LPCWSTR
)pQuery
, lpCand
, dwSize
, GCL_CONVERSION
);
38 std::vector
<std::string
> new_phrase
;
40 for (unsigned int i
= 0; i
< lpCand
->dwCount
; i
++)
42 std::wstring
strOutput((WCHAR
*)((char *)lpCand
+ lpCand
->dwOffset
[i
]));
43 std::string strUTF8Output
;
44 WinUTF8::wstring_to_UTF8string(strOutput
, strUTF8Output
);
45 new_phrase
.push_back(strUTF8Output
);
46 //sprintf( buf, "%s\n",(LPBYTE)lpCand + lpCand->dwOffset[i] );
47 // Find hiragana length
49 MaxLen
= strOutput
.size();
51 /*if( wcslen( (WCHAR *)lpCand + lpCand->dwOffset[i] ) > MaxLen )
52 MaxLen = wcslen( (WCHAR *)lpCand + lpCand->dwOffset[i] );*/
54 vResult
.push_back(new_phrase
);
55 HeapFree(GetProcessHeap(), 0, lpCand
);