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
|
// KanjiConversionIME.cpp
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2005 Takashi Kaburagi
//
/////////////////////////////////////////////////////////////////////////////
#include "../../Common/Common.h"
#include "KanjiConversionIME.h"
#include <iostream> //For testing 23 June 2005
using namespace Dasher;
using namespace std;
// Track memory leaks on Windows to the line that new'd the memory
#ifdef _WIN32
#ifdef _DEBUG
#define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif
CKanjiConversionIME::CKanjiConversionIME() {
IsInit = 0;
hIMC = ImmCreateContext();
IsInit = 1;
}
CKanjiConversionIME::~CKanjiConversionIME() {
ImmDestroyContext( hIMC );
IsInit = 0;
}
int CKanjiConversionIME::ConvertKanji(std::string str) {
HKL hKL;
DWORD dwSize;
LPCANDIDATELIST lpCand;
hKL = GetKeyboardLayout(0);
char *pQuery = (char *)str.c_str();
while( strlen(pQuery) ){
dwSize = ImmGetConversionList(hKL, hIMC, (LPCWSTR)pQuery, NULL, 0, GCL_CONVERSION);
lpCand = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
dwSize = ImmGetConversionList(hKL, hIMC, (LPCWSTR)pQuery, lpCand, dwSize, GCL_CONVERSION);
size_t MaxLen = 0;
CPhrase new_phrase;
// For all candidates
for (unsigned int i = 0; i< lpCand->dwCount; i++)
{
new_phrase.candidate_list.push_back( (char *)(lpCand + lpCand->dwOffset[i]) );
//sprintf( buf, "%s\n",(LPBYTE)lpCand + lpCand->dwOffset[i] );
// Find hiragana length
if( strlen( (char *)lpCand + lpCand->dwOffset[i] ) > MaxLen )
MaxLen = strlen( (char *)lpCand + lpCand->dwOffset[i] );
}
phrase.push_back(new_phrase);
HeapFree(GetProcessHeap(), 0, lpCand);
pQuery += MaxLen;
}
return 0;
}
|