ReactOS 0.4.17-dev-0-g129ef35
profile.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS msctfime.ime
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Profile of msctfime.ime
5 * COPYRIGHT: Copyright 2024-2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "msctfime.h"
9
11
12// The callback function type
14
20{
21 if (!profile.fActive || !memcmp(&profile.clsid, &GUID_NULL, sizeof(GUID_NULL)))
22 return S_FALSE;
24 if (!pArg)
25 return S_OK;
26 if (memcmp(&profile.catid, &pArg->catid, sizeof(profile.catid)) != 0)
27 return S_FALSE;
28 pArg->profile = profile;
29 return S_OK;
30}
31
32template <typename T_IFACE, typename T_DATA>
34{
35 T_IFACE* m_iface;
38
39public:
41 : m_iface(iface)
44 { }
45
47 {
48 HRESULT hr;
49 T_DATA data;
50
51 for (;;)
52 {
53 hr = m_iface->Next(1, &data, NULL);
54 if (hr != S_OK)
55 break;
56
58 if (hr == S_OK)
59 return ERROR_SUCCESS;
60 }
61
63 }
64};
65
68{
69 m_dwFlags = 0;
70 m_cRefs = 1;
73 m_LangID1 = 0;
75 m_LangID2 = 0;
76 m_dwUnknown1 = 0;
77}
78
81{
82 if (m_pIPProfiles)
83 {
84 if (m_LangID1)
85 m_pIPProfiles->ChangeCurrentLanguage(m_LangID1);
86
87 m_pIPProfiles->Release();
89 }
90
92 {
96 }
97}
98
101{
102 *ppvObj = NULL;
103 return E_NOINTERFACE;
104}
105
108{
109 return ::InterlockedIncrement(&m_cRefs);
110}
111
114{
116 {
117 delete this;
118 return 0;
119 }
120 return m_cRefs;
121}
122
126 REFGUID rguid1,
127 REFGUID rguid2,
128 BOOL fActivated,
129 LPVOID pUserData)
130{
131 CicProfile *pThis = (CicProfile *)pUserData;
132 pThis->m_dwFlags &= ~0xE;
133 return 0;
134}
135
138{
139 if (!puCodePage)
140 return E_INVALIDARG;
141
142 if (m_dwFlags & 2)
143 {
144 *puCodePage = m_nCodePage;
145 return S_OK;
146 }
147
148 *puCodePage = 0;
149
152 if (FAILED(hr))
153 return E_FAIL;
154
155 WCHAR szBuff[12];
157 if (cch)
158 {
159 szBuff[cch] = 0;
160 m_nCodePage = *puCodePage = wcstoul(szBuff, NULL, 10);
161 m_dwFlags |= 2;
162 }
163
164 return S_OK;
165}
166
169{
170 *pLangID = 0;
171
172 if (!m_pIPProfiles)
173 return E_FAIL;
174
175 if (m_dwFlags & 4)
176 {
177 *pLangID = m_LangID2;
178 return S_OK;
179 }
180
181 HRESULT hr = m_pIPProfiles->GetCurrentLanguage(pLangID);
182 if (SUCCEEDED(hr))
183 {
184 m_dwFlags |= 4;
185 m_LangID2 = *pLangID;
186 }
187
188 return hr;
189}
190
194{
196 if (FAILED(hr))
197 return hr;
198
200 {
204 if (!pSink)
205 {
206 m_pIPProfiles->Release();
208 return E_FAIL;
209 }
211 }
212
213 if (pTLS->m_pThreadMgr)
214 m_pActiveLanguageProfileNotifySink->_Advise(pTLS->m_pThreadMgr);
215
216 return hr;
217}
218
222 _In_ HKL hKL,
224 _Out_ TF_LANGUAGEPROFILE* pProfile)
225{
227 HRESULT hr = m_pIPProfiles->EnumLanguageProfiles(LOWORD(hKL), &pEnum);
228 if (FAILED(hr))
229 return S_FALSE;
230
232 arg.catid = catid;
233
235 enumValue(pEnum, LanguageProfilesCallback, (LPARAM)&arg);
236 DWORD ret = enumValue.DoEnum();
237 if (ret != ERROR_SUCCESS || !pProfile)
238 return S_FALSE;
239 *pProfile = arg.profile;
240 return S_OK;
241}
242
245{
247 HRESULT hr = m_pIPProfiles->EnumLanguageProfiles(LOWORD(hKL), &pEnum);
248 if (FAILED(hr))
249 return S_FALSE;
250
252 enumValue(pEnum, LanguageProfilesCallback);
253 DWORD ret = enumValue.DoEnum();
254 return (ret == ERROR_SUCCESS) ? S_OK : S_FALSE;
255}
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODIMP_(t)
Definition: basetyps.h:44
#define cicNoThrow
Definition: cicbase.h:49
HRESULT _Advise(ITfThreadMgr *pThreadMgr)
@implemented
Definition: sinks.cpp:472
HRESULT _Unadvise()
@implemented
Definition: sinks.cpp:502
CicEnumValue(T_IFACE *iface, FN_LanguageProfilesCallback callback, LPARAM lParam=0)
Definition: profile.cpp:40
DWORD DoEnum()
Definition: profile.cpp:46
FN_LanguageProfilesCallback m_callback
Definition: profile.cpp:36
T_IFACE * m_iface
Definition: profile.cpp:35
LPARAM m_lParam
Definition: profile.cpp:37
struct CicProfile::tagLANG_PROF_ENUM_ARG * PLANG_PROF_ENUM_ARG
DWORD m_dwFlags
Definition: profile.h:25
UINT m_nCodePage
Definition: profile.h:26
LANGID m_LangID1
Definition: profile.h:23
static INT CALLBACK ActiveLanguageProfileNotifySinkCallback(REFGUID rguid1, REFGUID rguid2, BOOL fActivated, LPVOID pUserData)
@implemented
Definition: profile.cpp:125
static HRESULT CALLBACK LanguageProfilesCallback(_In_ TF_LANGUAGEPROFILE profile, _Inout_opt_ LPARAM lParam)
@implemented
Definition: profile.cpp:17
HRESULT GetLangId(_Out_ LANGID *pLangID)
@implemented
Definition: profile.cpp:168
DWORD m_dwUnknown1
Definition: profile.h:29
HRESULT IsIME(HKL hKL)
@implemented
Definition: profile.cpp:244
LONG m_cRefs
Definition: profile.h:30
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj) override
@implemented
Definition: profile.cpp:100
LANGID m_LangID2
Definition: profile.h:27
CicProfile()
@implemented
Definition: profile.cpp:67
HRESULT GetCodePageA(_Out_ UINT *puCodePage)
@implemented
Definition: profile.cpp:137
virtual ~CicProfile()
@implemented
Definition: profile.cpp:80
HRESULT GetActiveLanguageProfile(_In_ HKL hKL, _In_ REFGUID catid, _Out_ TF_LANGUAGEPROFILE *pProfile)
@implemented
Definition: profile.cpp:221
ITfInputProcessorProfiles * m_pIPProfiles
Definition: profile.h:21
CActiveLanguageProfileNotifySink * m_pActiveLanguageProfileNotifySink
Definition: profile.h:22
HRESULT InitProfileInstance(_Inout_ TLS *pTLS)
@implemented
Definition: profile.cpp:193
Definition: tls.h:14
LPARAM lParam
Definition: combotst.c:139
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:573
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define CALLBACK
Definition: compat.h:35
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
REFIID riid
Definition: atlbase.h:39
ULONG AddRef()
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define profile
Definition: kernel32.h:12
#define GUID_NULL
Definition: ks.h:106
USHORT LANGID
Definition: mui.h:9
LONG_PTR LPARAM
Definition: minwindef.h:175
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static IPrintDialogCallback callback
Definition: printdlg.c:326
HRESULT WINAPI TF_CreateInputProcessorProfiles(ITfInputProcessorProfiles **ppipr)
Definition: msctf.cpp:651
UINT_PTR HKL
Definition: msctf.idl:125
GUID catid
Definition: msctf.idl:629
unsigned int UINT
Definition: ndis.h:50
#define _Inout_
Definition: no_sal2.h:162
#define _Inout_opt_
Definition: no_sal2.h:216
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define LOWORD(l)
Definition: pedump.c:82
short WCHAR
Definition: pedump.c:58
HRESULT(CALLBACK * FN_LanguageProfilesCallback)(TF_LANGUAGEPROFILE profile, LPARAM lParam)
Definition: profile.cpp:13
#define REFIID
Definition: guiddef.h:118
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#define _countof(array)
Definition: sndvol32.h:70
TF_LANGUAGEPROFILE profile
Definition: profile.h:18
Definition: scsiwmi.h:51
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1083
void * arg
Definition: msvc.h:10
#define HRESULT
Definition: msvc.h:7
#define S_FALSE
Definition: winerror.h:3451
#define E_NOINTERFACE
Definition: winerror.h:3479
#define LOCALE_IDEFAULTANSICODEPAGE
Definition: winnls.h:45