xref: /reactos/dll/ime/msctfime/profile.cpp (revision febb589e)
1b2ec7867SKatayama Hirofumi MZ /*
2b2ec7867SKatayama Hirofumi MZ  * PROJECT:     ReactOS msctfime.ime
3b2ec7867SKatayama Hirofumi MZ  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4b2ec7867SKatayama Hirofumi MZ  * PURPOSE:     Profile of msctfime.ime
5b2ec7867SKatayama Hirofumi MZ  * COPYRIGHT:   Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6b2ec7867SKatayama Hirofumi MZ  */
7b2ec7867SKatayama Hirofumi MZ 
8b2ec7867SKatayama Hirofumi MZ #include "msctfime.h"
9b2ec7867SKatayama Hirofumi MZ 
10b2ec7867SKatayama Hirofumi MZ WINE_DEFAULT_DEBUG_CHANNEL(msctfime);
11b2ec7867SKatayama Hirofumi MZ 
12b2ec7867SKatayama Hirofumi MZ /// @implemented
CicProfile()13b2ec7867SKatayama Hirofumi MZ CicProfile::CicProfile()
14b2ec7867SKatayama Hirofumi MZ {
15b2ec7867SKatayama Hirofumi MZ     m_dwFlags &= 0xFFFFFFF0;
16b2ec7867SKatayama Hirofumi MZ     m_cRefs = 1;
17b2ec7867SKatayama Hirofumi MZ     m_pIPProfiles = NULL;
18b2ec7867SKatayama Hirofumi MZ     m_pActiveLanguageProfileNotifySink = NULL;
19b2ec7867SKatayama Hirofumi MZ     m_LangID1 = 0;
20b2ec7867SKatayama Hirofumi MZ     m_nCodePage = CP_ACP;
21b2ec7867SKatayama Hirofumi MZ     m_LangID2 = 0;
22b2ec7867SKatayama Hirofumi MZ     m_dwUnknown1 = 0;
23b2ec7867SKatayama Hirofumi MZ }
24b2ec7867SKatayama Hirofumi MZ 
25b2ec7867SKatayama Hirofumi MZ /// @implemented
~CicProfile()26b2ec7867SKatayama Hirofumi MZ CicProfile::~CicProfile()
27b2ec7867SKatayama Hirofumi MZ {
28b2ec7867SKatayama Hirofumi MZ     if (m_pIPProfiles)
29b2ec7867SKatayama Hirofumi MZ     {
30b2ec7867SKatayama Hirofumi MZ         if (m_LangID1)
31b2ec7867SKatayama Hirofumi MZ             m_pIPProfiles->ChangeCurrentLanguage(m_LangID1);
32b2ec7867SKatayama Hirofumi MZ 
33b2ec7867SKatayama Hirofumi MZ         m_pIPProfiles->Release();
34b2ec7867SKatayama Hirofumi MZ         m_pIPProfiles = NULL;
35b2ec7867SKatayama Hirofumi MZ     }
36b2ec7867SKatayama Hirofumi MZ 
37b2ec7867SKatayama Hirofumi MZ     if (m_pActiveLanguageProfileNotifySink)
38b2ec7867SKatayama Hirofumi MZ     {
39b2ec7867SKatayama Hirofumi MZ         m_pActiveLanguageProfileNotifySink->_Unadvise();
40b2ec7867SKatayama Hirofumi MZ         m_pActiveLanguageProfileNotifySink->Release();
41b2ec7867SKatayama Hirofumi MZ         m_pActiveLanguageProfileNotifySink = NULL;
42b2ec7867SKatayama Hirofumi MZ     }
43b2ec7867SKatayama Hirofumi MZ }
44b2ec7867SKatayama Hirofumi MZ 
45b2ec7867SKatayama Hirofumi MZ /// @implemented
QueryInterface(REFIID riid,LPVOID * ppvObj)46b2ec7867SKatayama Hirofumi MZ STDMETHODIMP CicProfile::QueryInterface(REFIID riid, LPVOID* ppvObj)
47b2ec7867SKatayama Hirofumi MZ {
48b2ec7867SKatayama Hirofumi MZ     *ppvObj = NULL;
49b2ec7867SKatayama Hirofumi MZ     return E_NOINTERFACE;
50b2ec7867SKatayama Hirofumi MZ }
51b2ec7867SKatayama Hirofumi MZ 
52b2ec7867SKatayama Hirofumi MZ /// @implemented
STDMETHODIMP_(ULONG)53b2ec7867SKatayama Hirofumi MZ STDMETHODIMP_(ULONG) CicProfile::AddRef()
54b2ec7867SKatayama Hirofumi MZ {
55b2ec7867SKatayama Hirofumi MZ     return ::InterlockedIncrement(&m_cRefs);
56b2ec7867SKatayama Hirofumi MZ }
57b2ec7867SKatayama Hirofumi MZ 
58b2ec7867SKatayama Hirofumi MZ /// @implemented
STDMETHODIMP_(ULONG)59b2ec7867SKatayama Hirofumi MZ STDMETHODIMP_(ULONG) CicProfile::Release()
60b2ec7867SKatayama Hirofumi MZ {
61b2ec7867SKatayama Hirofumi MZ     if (::InterlockedDecrement(&m_cRefs) == 0)
62b2ec7867SKatayama Hirofumi MZ     {
63b2ec7867SKatayama Hirofumi MZ         delete this;
64b2ec7867SKatayama Hirofumi MZ         return 0;
65b2ec7867SKatayama Hirofumi MZ     }
66b2ec7867SKatayama Hirofumi MZ     return m_cRefs;
67b2ec7867SKatayama Hirofumi MZ }
68b2ec7867SKatayama Hirofumi MZ 
69b2ec7867SKatayama Hirofumi MZ /// @implemented
70b2ec7867SKatayama Hirofumi MZ INT CALLBACK
ActiveLanguageProfileNotifySinkCallback(REFGUID rguid1,REFGUID rguid2,BOOL fActivated,LPVOID pUserData)71b2ec7867SKatayama Hirofumi MZ CicProfile::ActiveLanguageProfileNotifySinkCallback(
72b2ec7867SKatayama Hirofumi MZ     REFGUID rguid1,
73b2ec7867SKatayama Hirofumi MZ     REFGUID rguid2,
74b2ec7867SKatayama Hirofumi MZ     BOOL fActivated,
75b2ec7867SKatayama Hirofumi MZ     LPVOID pUserData)
76b2ec7867SKatayama Hirofumi MZ {
77b2ec7867SKatayama Hirofumi MZ     CicProfile *pThis = (CicProfile *)pUserData;
78b2ec7867SKatayama Hirofumi MZ     pThis->m_dwFlags &= ~0xE;
79b2ec7867SKatayama Hirofumi MZ     return 0;
80b2ec7867SKatayama Hirofumi MZ }
81b2ec7867SKatayama Hirofumi MZ 
82b2ec7867SKatayama Hirofumi MZ /// @implemented
GetCodePageA(_Out_ UINT * puCodePage)83b2ec7867SKatayama Hirofumi MZ HRESULT CicProfile::GetCodePageA(_Out_ UINT *puCodePage)
84b2ec7867SKatayama Hirofumi MZ {
85b2ec7867SKatayama Hirofumi MZ     if (!puCodePage)
86b2ec7867SKatayama Hirofumi MZ         return E_INVALIDARG;
87b2ec7867SKatayama Hirofumi MZ 
88b2ec7867SKatayama Hirofumi MZ     if (m_dwFlags & 2)
89b2ec7867SKatayama Hirofumi MZ     {
90b2ec7867SKatayama Hirofumi MZ         *puCodePage = m_nCodePage;
91b2ec7867SKatayama Hirofumi MZ         return S_OK;
92b2ec7867SKatayama Hirofumi MZ     }
93b2ec7867SKatayama Hirofumi MZ 
94b2ec7867SKatayama Hirofumi MZ     *puCodePage = 0;
95b2ec7867SKatayama Hirofumi MZ 
96b2ec7867SKatayama Hirofumi MZ     LANGID LangID;
97b2ec7867SKatayama Hirofumi MZ     HRESULT hr = GetLangId(&LangID);
98b2ec7867SKatayama Hirofumi MZ     if (FAILED(hr))
99b2ec7867SKatayama Hirofumi MZ         return E_FAIL;
100b2ec7867SKatayama Hirofumi MZ 
101b2ec7867SKatayama Hirofumi MZ     WCHAR szBuff[12];
102b2ec7867SKatayama Hirofumi MZ     INT cch = ::GetLocaleInfoW(LangID, LOCALE_IDEFAULTANSICODEPAGE, szBuff, _countof(szBuff));
103b2ec7867SKatayama Hirofumi MZ     if (cch)
104b2ec7867SKatayama Hirofumi MZ     {
105b2ec7867SKatayama Hirofumi MZ         szBuff[cch] = 0;
106b2ec7867SKatayama Hirofumi MZ         m_nCodePage = *puCodePage = wcstoul(szBuff, NULL, 10);
107b2ec7867SKatayama Hirofumi MZ         m_dwFlags |= 2;
108b2ec7867SKatayama Hirofumi MZ     }
109b2ec7867SKatayama Hirofumi MZ 
110b2ec7867SKatayama Hirofumi MZ     return S_OK;
111b2ec7867SKatayama Hirofumi MZ }
112b2ec7867SKatayama Hirofumi MZ 
113b2ec7867SKatayama Hirofumi MZ /// @implemented
GetLangId(_Out_ LANGID * pLangID)114b2ec7867SKatayama Hirofumi MZ HRESULT CicProfile::GetLangId(_Out_ LANGID *pLangID)
115b2ec7867SKatayama Hirofumi MZ {
116b2ec7867SKatayama Hirofumi MZ     *pLangID = 0;
117b2ec7867SKatayama Hirofumi MZ 
118b2ec7867SKatayama Hirofumi MZ     if (!m_pIPProfiles)
119b2ec7867SKatayama Hirofumi MZ         return E_FAIL;
120b2ec7867SKatayama Hirofumi MZ 
121b2ec7867SKatayama Hirofumi MZ     if (m_dwFlags & 4)
122b2ec7867SKatayama Hirofumi MZ     {
123b2ec7867SKatayama Hirofumi MZ         *pLangID = m_LangID2;
124b2ec7867SKatayama Hirofumi MZ         return S_OK;
125b2ec7867SKatayama Hirofumi MZ     }
126b2ec7867SKatayama Hirofumi MZ 
127b2ec7867SKatayama Hirofumi MZ     HRESULT hr = m_pIPProfiles->GetCurrentLanguage(pLangID);
128b2ec7867SKatayama Hirofumi MZ     if (SUCCEEDED(hr))
129b2ec7867SKatayama Hirofumi MZ     {
130b2ec7867SKatayama Hirofumi MZ         m_dwFlags |= 4;
131b2ec7867SKatayama Hirofumi MZ         m_LangID2 = *pLangID;
132b2ec7867SKatayama Hirofumi MZ     }
133b2ec7867SKatayama Hirofumi MZ 
134b2ec7867SKatayama Hirofumi MZ     return hr;
135b2ec7867SKatayama Hirofumi MZ }
136b2ec7867SKatayama Hirofumi MZ 
137b2ec7867SKatayama Hirofumi MZ /// @implemented
138b2ec7867SKatayama Hirofumi MZ HRESULT
InitProfileInstance(_Inout_ TLS * pTLS)139b2ec7867SKatayama Hirofumi MZ CicProfile::InitProfileInstance(_Inout_ TLS *pTLS)
140b2ec7867SKatayama Hirofumi MZ {
141b2ec7867SKatayama Hirofumi MZ     HRESULT hr = TF_CreateInputProcessorProfiles(&m_pIPProfiles);
142b2ec7867SKatayama Hirofumi MZ     if (FAILED(hr))
143b2ec7867SKatayama Hirofumi MZ         return hr;
144b2ec7867SKatayama Hirofumi MZ 
145b2ec7867SKatayama Hirofumi MZ     if (!m_pActiveLanguageProfileNotifySink)
146b2ec7867SKatayama Hirofumi MZ     {
147b2ec7867SKatayama Hirofumi MZ         CActiveLanguageProfileNotifySink *pSink =
148b2ec7867SKatayama Hirofumi MZ             new(cicNoThrow) CActiveLanguageProfileNotifySink(
149b2ec7867SKatayama Hirofumi MZ                 CicProfile::ActiveLanguageProfileNotifySinkCallback, this);
150b2ec7867SKatayama Hirofumi MZ         if (!pSink)
151b2ec7867SKatayama Hirofumi MZ         {
152b2ec7867SKatayama Hirofumi MZ             m_pIPProfiles->Release();
153b2ec7867SKatayama Hirofumi MZ             m_pIPProfiles = NULL;
154b2ec7867SKatayama Hirofumi MZ             return E_FAIL;
155b2ec7867SKatayama Hirofumi MZ         }
156b2ec7867SKatayama Hirofumi MZ         m_pActiveLanguageProfileNotifySink = pSink;
157b2ec7867SKatayama Hirofumi MZ     }
158b2ec7867SKatayama Hirofumi MZ 
159b2ec7867SKatayama Hirofumi MZ     if (pTLS->m_pThreadMgr)
160b2ec7867SKatayama Hirofumi MZ         m_pActiveLanguageProfileNotifySink->_Advise(pTLS->m_pThreadMgr);
161b2ec7867SKatayama Hirofumi MZ 
162b2ec7867SKatayama Hirofumi MZ     return hr;
163b2ec7867SKatayama Hirofumi MZ }
164b2ec7867SKatayama Hirofumi MZ 
165b2ec7867SKatayama Hirofumi MZ /// @unimplemented
166b2ec7867SKatayama Hirofumi MZ HRESULT
GetActiveLanguageProfile(_In_ HKL hKL,_In_ REFGUID rguid,_Out_ TF_LANGUAGEPROFILE * pProfile)167b2ec7867SKatayama Hirofumi MZ CicProfile::GetActiveLanguageProfile(
168b2ec7867SKatayama Hirofumi MZ     _In_ HKL hKL,
169b2ec7867SKatayama Hirofumi MZ     _In_ REFGUID rguid,
170b2ec7867SKatayama Hirofumi MZ     _Out_ TF_LANGUAGEPROFILE *pProfile)
171b2ec7867SKatayama Hirofumi MZ {
172b2ec7867SKatayama Hirofumi MZ     return E_NOTIMPL;
173b2ec7867SKatayama Hirofumi MZ }
174*febb589eSKatayama Hirofumi MZ 
175*febb589eSKatayama Hirofumi MZ /// The return value of CicProfile::IsIME is brain-damaged.
176*febb589eSKatayama Hirofumi MZ /// @unimplemented
IsIME(HKL hKL)177*febb589eSKatayama Hirofumi MZ BOOL CicProfile::IsIME(HKL hKL)
178*febb589eSKatayama Hirofumi MZ {
179*febb589eSKatayama Hirofumi MZ     return TRUE;
180*febb589eSKatayama Hirofumi MZ }
181