OSDN Git Service

Change icon.ico. And fix icon bug, write ChangeLog.txt.
[ckw/ckw.git] / ime_wrap.cpp
1 /*-----------------------------------------------------------------------------
2  * File: ime_wrap.cpp
3  *-----------------------------------------------------------------------------
4  * Copyright (c) 2005       Kazuo Ishii <k-ishii@wb4.so-net.ne.jp>
5  *                              - original version
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *---------------------------------------------------------------------------*/
21 #include <windows.h>
22 #include <imm.h>
23
24 static HMODULE gDll = NULL;
25
26 typedef HIMC (WINAPI* FN_GetContext)(HWND);
27 typedef BOOL (WINAPI* FN_ReleaseContext)(HWND,HIMC);
28 typedef BOOL (WINAPI* FN_GetOpenStatus)(HIMC);
29 typedef BOOL (WINAPI* FN_SetCompositionFontW)(HIMC, LPLOGFONTW);
30 typedef BOOL (WINAPI* FN_SetCompositionWindow)(HIMC, PCOMPOSITIONFORM);
31
32 static FN_GetContext            fn_GetContext    = NULL;
33 static FN_ReleaseContext        fn_ReleaseContext       = NULL;
34 static FN_GetOpenStatus         fn_GetOpenStatus        = NULL;
35 static FN_SetCompositionFontW   fn_SetCompositionFontW  = NULL;
36 static FN_SetCompositionWindow  fn_SetCompositionWindow = NULL;
37
38 HIMC WINAPI ImmGetContext(HWND hwnd)
39 {
40         if(fn_GetContext)
41                 return( fn_GetContext(hwnd) );
42         return(NULL);
43 }
44
45 BOOL WINAPI ImmReleaseContext(HWND hwnd, HIMC imc)
46 {
47         if(fn_ReleaseContext)
48                 return( fn_ReleaseContext(hwnd, imc) );
49         return(FALSE);
50 }
51
52 BOOL WINAPI ImmGetOpenStatus(HIMC imc)
53 {
54         if(fn_GetOpenStatus)
55                 return( fn_GetOpenStatus(imc) );
56         return(FALSE);
57 }
58
59 BOOL WINAPI ImmSetCompositionFontW(HIMC imc, LPLOGFONTW lf)
60 {
61         if(fn_SetCompositionFontW)
62                 return( fn_SetCompositionFontW(imc, lf) );
63         return(FALSE);
64 }
65
66 BOOL WINAPI ImmSetCompositionWindow(HIMC imc, PCOMPOSITIONFORM cf)
67 {
68         if(fn_SetCompositionWindow)
69                 return( fn_SetCompositionWindow(imc, cf) );
70         return(FALSE);
71 }
72
73 #define GET_PROC(name) \
74         if(result) { \
75                 fn_##name = (FN_##name) GetProcAddress(gDll, "Imm" #name); \
76                 if(! fn_##name) result = FALSE; \
77         }
78
79 BOOL    ime_wrap_init()
80 {
81         BOOL result = TRUE;
82         gDll = LoadLibraryA("imm32.dll");
83         if(!gDll)
84                 return(FALSE);
85         GET_PROC( GetContext );
86         GET_PROC( ReleaseContext );
87         GET_PROC( GetOpenStatus );
88         GET_PROC( SetCompositionFontW );
89         GET_PROC( SetCompositionWindow );
90         if(!result) {
91                 fn_GetContext = NULL;
92                 fn_ReleaseContext = NULL;
93                 fn_GetOpenStatus = NULL;
94                 fn_SetCompositionFontW = NULL;
95                 fn_SetCompositionWindow = NULL;
96                 FreeLibrary(gDll);
97                 gDll = NULL;
98         }
99         return(result);
100 }
101
102 void ime_wrap_term()
103 {
104         if (gDll) {
105                 FreeLibrary(gDll);
106                 gDll = NULL;
107         }
108 }
109
110 /* EOF */