2023-12-19 06:23:12 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Cicero
|
|
|
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
|
|
* PURPOSE: Locking and Unlocking IMC and IMCC handles
|
|
|
|
* COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-27 11:29:02 +00:00
|
|
|
// struct CTFIMECONTEXT;
|
2023-12-22 05:52:49 +00:00
|
|
|
// class CIC_IMCC_LOCK<T_DATA>;
|
|
|
|
// class CicIMCCLock<T_DATA>;
|
|
|
|
// class CIC_IMC_LOCK;
|
|
|
|
// class CicIMCLock;
|
2023-12-19 06:23:12 +00:00
|
|
|
|
2023-12-27 11:29:02 +00:00
|
|
|
class CicInputContext;
|
|
|
|
|
|
|
|
typedef struct tagCTFIMECONTEXT
|
|
|
|
{
|
|
|
|
CicInputContext *m_pCicIC;
|
|
|
|
DWORD m_dwCicFlags;
|
|
|
|
} CTFIMECONTEXT, *PCTFIMECONTEXT;
|
|
|
|
|
2023-12-19 06:23:12 +00:00
|
|
|
template <typename T_DATA>
|
2023-12-22 05:52:49 +00:00
|
|
|
class CIC_IMCC_LOCK
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
2023-12-19 07:12:12 +00:00
|
|
|
protected:
|
2023-12-19 06:23:12 +00:00
|
|
|
T_DATA *m_pIMCC;
|
2023-12-19 07:12:12 +00:00
|
|
|
|
|
|
|
public:
|
2023-12-19 06:23:12 +00:00
|
|
|
HIMCC m_hIMCC;
|
|
|
|
HRESULT m_hr;
|
|
|
|
|
2023-12-22 05:52:49 +00:00
|
|
|
CIC_IMCC_LOCK(HIMCC hIMCC)
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
m_pIMCC = NULL;
|
|
|
|
m_hr = S_OK;
|
|
|
|
m_hIMCC = hIMCC;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T_DATA>
|
2023-12-22 05:52:49 +00:00
|
|
|
class CicIMCCLock : public CIC_IMCC_LOCK<T_DATA>
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-12-22 05:52:49 +00:00
|
|
|
CicIMCCLock(HIMCC hIMCC) : CIC_IMCC_LOCK<T_DATA>(hIMCC)
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
2024-02-22 06:46:05 +00:00
|
|
|
this->m_hr = _LockIMCC(this->m_hIMCC, &this->m_pIMCC);
|
2023-12-19 06:23:12 +00:00
|
|
|
}
|
2023-12-22 05:52:49 +00:00
|
|
|
~CicIMCCLock()
|
2023-12-21 07:23:23 +00:00
|
|
|
{
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlock()
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
if (this->m_pIMCC)
|
2023-12-21 07:23:23 +00:00
|
|
|
{
|
2023-12-19 06:23:12 +00:00
|
|
|
_UnlockIMCC(this->m_hIMCC);
|
2023-12-21 07:23:23 +00:00
|
|
|
this->m_pIMCC = NULL;
|
|
|
|
}
|
2023-12-19 06:23:12 +00:00
|
|
|
}
|
2023-12-21 07:23:23 +00:00
|
|
|
|
2023-12-19 06:23:12 +00:00
|
|
|
operator T_DATA*() const
|
|
|
|
{
|
|
|
|
return this->m_pIMCC;
|
|
|
|
}
|
2023-12-19 07:12:12 +00:00
|
|
|
T_DATA& get() const
|
|
|
|
{
|
|
|
|
return *this->m_pIMCC;
|
|
|
|
}
|
2023-12-19 06:23:12 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
HRESULT _LockIMCC(HIMCC hIMCC, T_DATA **pptr)
|
|
|
|
{
|
|
|
|
if (!hIMCC)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
*pptr = (T_DATA*)::ImmLockIMCC(hIMCC);
|
|
|
|
return (*pptr ? S_OK : E_FAIL);
|
|
|
|
}
|
|
|
|
HRESULT _UnlockIMCC(HIMCC hIMCC)
|
|
|
|
{
|
|
|
|
if (!::ImmUnlockIMCC(hIMCC))
|
|
|
|
return (::GetLastError() ? E_FAIL : S_OK);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-12-22 05:52:49 +00:00
|
|
|
class CIC_IMC_LOCK
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
2023-12-19 07:12:12 +00:00
|
|
|
protected:
|
2023-12-19 06:23:12 +00:00
|
|
|
LPINPUTCONTEXTDX m_pIC;
|
2023-12-19 07:12:12 +00:00
|
|
|
|
|
|
|
public:
|
2023-12-19 06:23:12 +00:00
|
|
|
HIMC m_hIMC;
|
|
|
|
HRESULT m_hr;
|
|
|
|
DWORD m_dw3;
|
|
|
|
|
2023-12-22 05:52:49 +00:00
|
|
|
CIC_IMC_LOCK(HIMC hIMC)
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
m_pIC = NULL;
|
|
|
|
m_hIMC = hIMC;
|
|
|
|
m_hr = S_OK;
|
|
|
|
m_dw3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Invalid() const
|
|
|
|
{
|
|
|
|
return (!m_pIC || m_hr != S_OK);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-12-22 05:52:49 +00:00
|
|
|
class CicIMCLock : public CIC_IMC_LOCK
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-12-22 05:52:49 +00:00
|
|
|
CicIMCLock(HIMC hIMC) : CIC_IMC_LOCK(hIMC)
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
m_hr = _LockIMC(hIMC, &m_pIC);
|
|
|
|
}
|
2023-12-22 05:52:49 +00:00
|
|
|
~CicIMCLock()
|
2023-12-21 07:23:23 +00:00
|
|
|
{
|
|
|
|
unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlock()
|
2023-12-19 06:23:12 +00:00
|
|
|
{
|
|
|
|
if (m_pIC)
|
2023-12-21 07:23:23 +00:00
|
|
|
{
|
2023-12-19 06:23:12 +00:00
|
|
|
_UnlockIMC(m_hIMC);
|
2023-12-21 07:23:23 +00:00
|
|
|
m_pIC = NULL;
|
|
|
|
}
|
2023-12-19 06:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitContext()
|
|
|
|
{
|
|
|
|
if (!(m_pIC->fdwInit & INIT_COMPFORM))
|
|
|
|
m_pIC->cfCompForm.dwStyle = 0;
|
|
|
|
for (UINT i = 0; i < 4; ++i)
|
|
|
|
m_pIC->cfCandForm[i].dwStyle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ValidCompositionString()
|
|
|
|
{
|
|
|
|
if (ImmGetIMCCSize(m_pIC->hCompStr) < sizeof(COMPOSITIONSTRING))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-12-22 05:52:49 +00:00
|
|
|
CicIMCCLock<COMPOSITIONSTRING> imccLock(m_pIC->hCompStr);
|
2023-12-19 06:23:12 +00:00
|
|
|
if (!imccLock)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-12-19 07:12:12 +00:00
|
|
|
return imccLock.get().dwCompStrLen > 0;
|
2023-12-19 06:23:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 11:29:02 +00:00
|
|
|
BOOL ClearCand();
|
|
|
|
|
2023-12-19 06:23:12 +00:00
|
|
|
BOOL UseVerticalCompWindow() const
|
|
|
|
{
|
|
|
|
return m_pIC->cfCompForm.dwStyle && ((m_pIC->lfFont.A.lfEscapement / 900) % 4 == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator INPUTCONTEXTDX*() const
|
|
|
|
{
|
|
|
|
return m_pIC;
|
|
|
|
}
|
2023-12-19 07:12:12 +00:00
|
|
|
INPUTCONTEXTDX& get() const
|
|
|
|
{
|
|
|
|
return *m_pIC;
|
|
|
|
}
|
2023-12-19 06:23:12 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
HRESULT _LockIMC(HIMC hIMC, LPINPUTCONTEXTDX *ppIC)
|
|
|
|
{
|
|
|
|
if (!hIMC)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC);
|
|
|
|
*ppIC = pIC;
|
|
|
|
return (pIC ? S_OK : E_FAIL);
|
|
|
|
}
|
|
|
|
HRESULT _UnlockIMC(HIMC hIMC)
|
|
|
|
{
|
|
|
|
return ::ImmUnlockIMC(hIMC) ? S_OK : E_FAIL;
|
|
|
|
}
|
|
|
|
};
|