tagging release
[dasher.git] / Src / DasherCore / IMEConversionHelper.cpp
blobff4d350d76891c6be265a3d5f0db1b2d1b72713f
1 #ifdef JAPANESE
3 #include "../WIn32/Common/WinUTF8.h"
4 #include "IMEConversionHelper.h"
6 #define BUFSIZE 10240
8 #include <iostream> //For testing 23 June 2005
10 CIMEConversionHelper::CIMEConversionHelper() {
11 IsInit = 0;
12 hIMC = ImmCreateContext();
13 IsInit = 1;
16 CIMEConversionHelper::~CIMEConversionHelper() {
17 ImmDestroyContext( hIMC );
18 IsInit = 0;
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);
26 HKL hKL;
27 DWORD dwSize;
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);
34 if(dwSize > 0) {
35 lpCand = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
36 dwSize = ImmGetConversionList(hKL, hIMC, (LPCWSTR)pQuery, lpCand, dwSize, GCL_CONVERSION);
37 size_t MaxLen = 0;
38 std::vector<std::string> new_phrase;
39 // For all candidates
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);
56 pQuery += MaxLen;
58 else {
59 // break;
61 //}
63 return true;
66 #endif