[MSCTFIME][MSCTF][SDK] Add compartment helper functions (#6202)

- Implement GetCompartment,
  SetCompartmentDWORD,
  GetCompartmentDWORD,
  SetCompartmentUnknown, and
  ClearCompartment helper functions.
- Add TF_DllDetachInOther prototype
  to "msctf.idl".
CORE-19360
This commit is contained in:
Katayama Hirofumi MZ 2023-12-20 17:51:37 +09:00 committed by GitHub
parent 0d8e6e781c
commit 9d495475f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 144 additions and 3 deletions

View file

@ -164,6 +164,146 @@ void TFUninitLib_Thread(PLIBTHREAD pLibThread)
}
}
HRESULT
GetCompartment(
IUnknown *pUnknown,
REFGUID rguid,
ITfCompartment **ppComp,
BOOL bThread)
{
ITfThreadMgr *pThreadMgr = NULL;
ITfCompartmentMgr *pCompMgr = NULL;
*ppComp = NULL;
HRESULT hr;
if (bThread)
{
hr = pUnknown->QueryInterface(IID_ITfThreadMgr, (void **)&pThreadMgr);
if (FAILED(hr))
return hr;
hr = pThreadMgr->GetGlobalCompartment(&pCompMgr);
}
else
{
hr = pUnknown->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr);
}
if (SUCCEEDED(hr))
{
if (pCompMgr)
hr = pCompMgr->GetCompartment(rguid, ppComp);
else
hr = E_FAIL;
}
if (pThreadMgr)
pThreadMgr->Release();
return hr;
}
HRESULT
SetCompartmentDWORD(
TfEditCookie cookie,
IUnknown *pUnknown,
REFGUID rguid,
VARTYPE type,
BOOL bThread)
{
ITfCompartment *pComp = NULL;
HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, bThread);
if (FAILED(hr))
return hr;
VARIANT vari;
V_I4(&vari) = type;
V_VT(&vari) = VT_I4;
hr = pComp->SetValue(cookie, &vari);
pComp->Release();
return hr;
}
HRESULT
GetCompartmentDWORD(
IUnknown *pUnknown,
REFGUID rguid,
ITfCompartment *pComp,
BOOL bThread)
{
HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, bThread);
if (FAILED(hr))
return hr;
VARIANT vari;
hr = pComp->GetValue(&vari);
pComp->Release();
return hr;
}
HRESULT
SetCompartmentUnknown(
TfEditCookie cookie,
IUnknown *pUnknown,
REFGUID rguid,
IUnknown *pUnknown2)
{
ITfCompartment *pComp = NULL;
HRESULT hr = GetCompartment(pUnknown, rguid, &pComp, FALSE);
if (FAILED(hr))
return hr;
VARIANT vari;
V_UNKNOWN(&vari) = pUnknown2;
V_VT(&vari) = VT_UNKNOWN;
hr = pComp->SetValue(cookie, &vari);
pComp->Release();
return hr;
}
HRESULT
ClearCompartment(
TfClientId tid,
IUnknown *pUnknown,
REFGUID rguid,
BOOL bThread)
{
ITfCompartmentMgr *pCompMgr = NULL;
ITfThreadMgr *pThreadMgr = NULL;
HRESULT hr;
if (bThread)
{
hr = pUnknown->QueryInterface(IID_ITfThreadMgr, (void **)&pThreadMgr);
if (FAILED(hr))
return hr;
hr = pThreadMgr->GetGlobalCompartment(&pCompMgr);
}
else
{
hr = pUnknown->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr);
}
if (SUCCEEDED(hr))
{
hr = E_FAIL;
if (pCompMgr)
{
hr = pCompMgr->ClearCompartment(tid, rguid);
pCompMgr->Release();
}
}
if (pThreadMgr)
pThreadMgr->Release();
return hr;
}
/* FIXME */
class CicInputContext : public ITfContextOwnerCompositionSink
{
@ -2155,7 +2295,7 @@ VOID ProcessDetach(HINSTANCE hinstDLL)
}
/**
* @unimplemented
* @implemented
*/
EXTERN_C BOOL WINAPI
DllMain(
@ -2182,7 +2322,7 @@ DllMain(
}
case DLL_THREAD_DETACH:
{
// FIXME
TF_DllDetachInOther();
CtfImeThreadDetach();
TLS::InternalDestroyTLS();
break;

View file

@ -15,7 +15,7 @@
@ stdcall TF_CreateLangBarItemMgr(ptr)
@ stdcall TF_CreateLangBarMgr(ptr)
@ stdcall TF_CreateThreadMgr(ptr)
@ stub TF_DllDetachInOther
@ stdcall -stub TF_DllDetachInOther()
@ stdcall -stub TF_GetGlobalCompartment(ptr)
@ stub TF_GetInputScope
@ stub TF_GetLangIcon

View file

@ -40,6 +40,7 @@ cpp_quote("EXTERN_C HRESULT WINAPI TF_CreateLangBarItemMgr(_Out_ ITfLangBarItemM
cpp_quote("EXTERN_C HANDLE WINAPI TF_CreateCicLoadMutex(_Out_ LPBOOL pfWinLogon);")
cpp_quote("EXTERN_C HRESULT WINAPI TF_InvalidAssemblyListCache(VOID);")
cpp_quote("EXTERN_C HRESULT WINAPI TF_InvalidAssemblyListCacheIfExist(VOID);")
cpp_quote("EXTERN_C HRESULT WINAPI TF_DllDetachInOther(VOID);")
cpp_quote("EXTERN_C const GUID GUID_PROP_TEXTOWNER;")
cpp_quote("EXTERN_C const GUID GUID_PROP_ATTRIBUTE;")