xref: /reactos/dll/win32/imm32/ctf.c (revision 1734f297)
1 /*
2  * PROJECT:     ReactOS IMM32
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Implementing the IMM32 Cicero-aware Text Framework (CTF)
5  * COPYRIGHT:   Copyright 2022 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
10 WINE_DEFAULT_DEBUG_CHANNEL(imm);
11 
12 /*
13  * NOTE: Microsoft CTF protocol has vulnerability.
14  *       If insecure, we don't follow the dangerous design.
15  *
16  * https://www.zdnet.com/article/vulnerability-in-microsoft-ctf-protocol-goes-back-to-windows-xp/
17  * https://googleprojectzero.blogspot.com/2019/08/down-rabbit-hole.html
18  */
19 
20 // Win: LoadCtfIme
21 HMODULE APIENTRY Imm32LoadCtfIme(VOID)
22 {
23     return NULL;
24 }
25 
26 // Win: Internal_CtfImeDestroyInputContext
27 HRESULT APIENTRY Imm32CtfImeDestroyInputContext(HIMC hIMC)
28 {
29     if (!Imm32LoadCtfIme())
30         return E_FAIL;
31 
32 #if 1
33     FIXME("(%p)\n", hIMC);
34     return E_NOTIMPL;
35 #else
36     return g_pfnCtfImeDestroyInputContext(hIMC);
37 #endif
38 }
39 
40 // Win: CtfImmTIMDestroyInputContext
41 HRESULT APIENTRY CtfImmTIMDestroyInputContext(HIMC hIMC)
42 {
43     if (!IS_CICERO_MODE() || (GetWin32ClientInfo()->dwCompatFlags2 & 2))
44         return E_NOINTERFACE;
45 
46     return Imm32CtfImeDestroyInputContext(hIMC);
47 }
48 
49 // Win: CtfImmTIMCreateInputContext
50 HRESULT APIENTRY CtfImmTIMCreateInputContext(HIMC hIMC)
51 {
52     TRACE("(%p)\n", hIMC);
53     return E_NOTIMPL;
54 }
55 
56 /***********************************************************************
57  *		CtfImmIsCiceroEnabled (IMM32.@)
58  */
59 BOOL WINAPI CtfImmIsCiceroEnabled(VOID)
60 {
61     return IS_CICERO_MODE();
62 }
63 
64 /***********************************************************************
65  *		CtfImmIsTextFrameServiceDisabled(IMM32.@)
66  */
67 BOOL WINAPI CtfImmIsTextFrameServiceDisabled(VOID)
68 {
69     return !!(GetWin32ClientInfo()->CI_flags & CI_TFSDISABLED);
70 }
71 
72 /***********************************************************************
73  *		CtfImmTIMActivate(IMM32.@)
74  */
75 HRESULT WINAPI CtfImmTIMActivate(HKL hKL)
76 {
77     FIXME("(%p)\n", hKL);
78     return E_NOTIMPL;
79 }
80 
81 /***********************************************************************
82  *		CtfImmRestoreToolbarWnd(IMM32.@)
83  */
84 VOID WINAPI CtfImmRestoreToolbarWnd(DWORD dwStatus)
85 {
86     FIXME("(0x%lx)\n", dwStatus);
87 }
88 
89 /***********************************************************************
90  *		CtfImmHideToolbarWnd(IMM32.@)
91  */
92 DWORD WINAPI CtfImmHideToolbarWnd(VOID)
93 {
94     FIXME("()\n");
95     return 0;
96 }
97 
98 /***********************************************************************
99  *		CtfImmDispatchDefImeMessage(IMM32.@)
100  */
101 LRESULT WINAPI CtfImmDispatchDefImeMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
102 {
103     /* FIXME("(%p, %u, %p, %p)\n", hWnd, uMsg, wParam, lParam); */
104     return 0;
105 }
106 
107 /***********************************************************************
108  *		CtfImmIsGuidMapEnable(IMM32.@)
109  */
110 BOOL WINAPI CtfImmIsGuidMapEnable(HIMC hIMC)
111 {
112     DWORD dwThreadId;
113     HKL hKL;
114     PIMEDPI pImeDpi;
115     BOOL ret = FALSE;
116 
117     TRACE("(%p)\n", hIMC);
118 
119     if (!IS_CICERO_MODE() || IS_16BIT_MODE())
120         return ret;
121 
122     dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
123     hKL = GetKeyboardLayout(dwThreadId);
124 
125     if (IS_IME_HKL(hKL))
126         return ret;
127 
128     pImeDpi = Imm32FindOrLoadImeDpi(hKL);
129     if (IS_NULL_UNEXPECTEDLY(pImeDpi))
130         return ret;
131 
132     ret = pImeDpi->CtfImeIsGuidMapEnable(hIMC);
133 
134     ImmUnlockImeDpi(pImeDpi);
135     return ret;
136 }
137 
138 /***********************************************************************
139  *		CtfImmGetGuidAtom(IMM32.@)
140  */
141 HRESULT WINAPI CtfImmGetGuidAtom(HIMC hIMC, DWORD dwUnknown, LPDWORD pdwGuidAtom)
142 {
143     HRESULT hr = E_FAIL;
144     PIMEDPI pImeDpi;
145     DWORD dwThreadId;
146     HKL hKL;
147 
148     TRACE("(%p, 0xlX, %p)\n", hIMC, dwUnknown, pdwGuidAtom);
149 
150     *pdwGuidAtom = 0;
151 
152     if (!IS_CICERO_MODE() || IS_16BIT_MODE())
153         return hr;
154 
155     dwThreadId = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTTHREADID);
156     hKL = GetKeyboardLayout(dwThreadId);
157     if (IS_IME_HKL(hKL))
158         return S_OK;
159 
160     pImeDpi = Imm32FindOrLoadImeDpi(hKL);
161     if (IS_NULL_UNEXPECTEDLY(pImeDpi))
162         return hr;
163 
164     hr = pImeDpi->CtfImeGetGuidAtom(hIMC, dwUnknown, pdwGuidAtom);
165 
166     ImmUnlockImeDpi(pImeDpi);
167     return hr;
168 }
169