forked from ckw-mod/ckw-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ime_wrap.cpp
110 lines (98 loc) · 3.01 KB
/
ime_wrap.cpp
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
/*-----------------------------------------------------------------------------
* File: ime_wrap.cpp
*-----------------------------------------------------------------------------
* Copyright (c) 2005 Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>
* - original version
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*---------------------------------------------------------------------------*/
#include <windows.h>
#include <imm.h>
static HMODULE gDll = NULL;
typedef HIMC (WINAPI* FN_GetContext)(HWND);
typedef BOOL (WINAPI* FN_ReleaseContext)(HWND,HIMC);
typedef BOOL (WINAPI* FN_GetOpenStatus)(HIMC);
typedef BOOL (WINAPI* FN_SetCompositionFontW)(HIMC, LPLOGFONTW);
typedef BOOL (WINAPI* FN_SetCompositionWindow)(HIMC, PCOMPOSITIONFORM);
static FN_GetContext fn_GetContext = NULL;
static FN_ReleaseContext fn_ReleaseContext = NULL;
static FN_GetOpenStatus fn_GetOpenStatus = NULL;
static FN_SetCompositionFontW fn_SetCompositionFontW = NULL;
static FN_SetCompositionWindow fn_SetCompositionWindow = NULL;
HIMC WINAPI ImmGetContext(HWND hwnd)
{
if(fn_GetContext)
return( fn_GetContext(hwnd) );
return(NULL);
}
BOOL WINAPI ImmReleaseContext(HWND hwnd, HIMC imc)
{
if(fn_ReleaseContext)
return( fn_ReleaseContext(hwnd, imc) );
return(FALSE);
}
BOOL WINAPI ImmGetOpenStatus(HIMC imc)
{
if(fn_GetOpenStatus)
return( fn_GetOpenStatus(imc) );
return(FALSE);
}
BOOL WINAPI ImmSetCompositionFontW(HIMC imc, LPLOGFONTW lf)
{
if(fn_SetCompositionFontW)
return( fn_SetCompositionFontW(imc, lf) );
return(FALSE);
}
BOOL WINAPI ImmSetCompositionWindow(HIMC imc, PCOMPOSITIONFORM cf)
{
if(fn_SetCompositionWindow)
return( fn_SetCompositionWindow(imc, cf) );
return(FALSE);
}
#define GET_PROC(name) \
if(result) { \
fn_##name = (FN_##name) GetProcAddress(gDll, "Imm" #name); \
if(! fn_##name) result = FALSE; \
}
BOOL ime_wrap_init()
{
BOOL result = TRUE;
gDll = LoadLibraryA("imm32.dll");
if(!gDll)
return(FALSE);
GET_PROC( GetContext );
GET_PROC( ReleaseContext );
GET_PROC( GetOpenStatus );
GET_PROC( SetCompositionFontW );
GET_PROC( SetCompositionWindow );
if(!result) {
fn_GetContext = NULL;
fn_ReleaseContext = NULL;
fn_GetOpenStatus = NULL;
fn_SetCompositionFontW = NULL;
fn_SetCompositionWindow = NULL;
FreeLibrary(gDll);
gDll = NULL;
}
return(result);
}
void ime_wrap_term()
{
if (gDll) {
FreeLibrary(gDll);
gDll = NULL;
}
}
/* EOF */