Skip to content

Commit

Permalink
[MSCTFIME][CICERO] Implement CFnDocFeed (#6513)
Browse files Browse the repository at this point in the history
Supporting TIPs...
JIRA issue: CORE-19360
- Add missing CicInputContext methods.
- Implement CFnDocFeed class.
  • Loading branch information
katahiromz authored Feb 22, 2024
1 parent 0086d05 commit f53f133
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 58 deletions.
13 changes: 3 additions & 10 deletions dll/ime/msctfime/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ CicBridge::CreateInputContext(
_In_ HIMC hIMC)
{
CicIMCLock imcLock(hIMC);
HRESULT hr = imcLock.m_hr;
if (!imcLock)
hr = E_FAIL;
if (FAILED(hr))
return hr;
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

if (!imcLock.get().hCtfImeContext)
{
Expand Down Expand Up @@ -126,7 +123,7 @@ CicBridge::CreateInputContext(
imeContext.get().m_pCicIC = pCicIC;
}

hr = pCicIC->CreateInputContext(pTLS->m_pThreadMgr, imcLock);
HRESULT hr = pCicIC->CreateInputContext(pTLS->m_pThreadMgr, imcLock);
if (FAILED(hr))
{
pCicIC->Release();
Expand All @@ -149,8 +146,6 @@ HRESULT CicBridge::DestroyInputContext(TLS *pTLS, HIMC hIMC)
{
CicIMCLock imcLock(hIMC);
HRESULT hr = imcLock.m_hr;
if (!imcLock)
hr = E_FAIL;
if (FAILED(hr))
return hr;

Expand Down Expand Up @@ -217,8 +212,6 @@ CicBridge::SelectEx(
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCtfImeContext);
if (!imeContext)
imeContext.m_hr = E_FAIL;
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;

Expand Down
100 changes: 93 additions & 7 deletions dll/ime/msctfime/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,112 @@ STDMETHODIMP_(ULONG) CFnDocFeed::Release()
return m_cRefs;
}

/// @unimplemented
/// @implemented
STDMETHODIMP CFnDocFeed::DocFeed()
{
return E_NOTIMPL;
TLS *pTLS = TLS::GetTLS();
if (!pTLS)
return E_OUTOFMEMORY;

HIMC hIMC = GetActiveContext();
CicIMCLock imcLock(hIMC);
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCtfImeContext);
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;
CicInputContext *pCicIC = imeContext.get().m_pCicIC;
if (!pCicIC)
return E_FAIL;

UINT uCodePage = CP_ACP;
pTLS->m_pProfile->GetCodePageA(&uCodePage);
pCicIC->SetupDocFeedString(imcLock, uCodePage);
return S_OK;
}

/// @unimplemented
/// @implemented
STDMETHODIMP CFnDocFeed::ClearDocFeedBuffer()
{
return E_NOTIMPL;
if (!TLS::GetTLS())
return E_OUTOFMEMORY;

HIMC hIMC = GetActiveContext();
CicIMCLock imcLock(hIMC);
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCtfImeContext);
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;

CicInputContext *pCicIC = imeContext.get().m_pCicIC;
if (!pCicIC)
return E_FAIL;

pCicIC->EscbClearDocFeedBuffer(imcLock, TRUE);
return S_OK;
}

/// @unimplemented
STDMETHODIMP CFnDocFeed::StartReconvert()
{
return E_NOTIMPL;
TLS *pTLS = TLS::GetTLS();
if (!pTLS)
return E_OUTOFMEMORY;
auto *pThreadMgr = pTLS->m_pThreadMgr;
if (!pThreadMgr)
return E_OUTOFMEMORY;

HIMC hIMC = GetActiveContext();
CicIMCLock imcLock(hIMC);
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCtfImeContext);
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;
CicInputContext *pCicIC = imeContext.get().m_pCicIC;
if (!pCicIC)
return E_FAIL;

UINT uCodePage = CP_ACP;
pTLS->m_pProfile->GetCodePageA(&uCodePage);

pCicIC->m_bReconverting = TRUE;
pCicIC->SetupReconvertString(imcLock, pThreadMgr, uCodePage, 0, 0);
pCicIC->EndReconvertString(imcLock);
pCicIC->m_bReconverting = FALSE;
return S_OK;
}

/// @unimplemented
/// @implemented
STDMETHODIMP CFnDocFeed::StartUndoCompositionString()
{
return E_NOTIMPL;
TLS *pTLS = TLS::GetTLS();
if (!pTLS)
return E_OUTOFMEMORY;
auto *pThreadMgr = pTLS->m_pThreadMgr;
if (!pThreadMgr)
return E_OUTOFMEMORY;

HIMC hIMC = GetActiveContext();
CicIMCLock imcLock(hIMC);
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCtfImeContext);
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;
CicInputContext *pCicIC = imeContext.get().m_pCicIC;
if (!pCicIC)
return E_FAIL;

UINT uCodePage = CP_ACP;
pTLS->m_pProfile->GetCodePageA(&uCodePage);

pCicIC->SetupReconvertString(imcLock, pThreadMgr, uCodePage, 0, TRUE);
pCicIC->EndReconvertString(imcLock);
return S_OK;
}
41 changes: 34 additions & 7 deletions dll/ime/msctfime/inputcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CicInputContext::OnStartComposition(
ITfCompositionView *pComposition,
BOOL *pfOk)
{
if ((m_cCompLocks <= 0) || m_dwUnknown6_5)
if ((m_cCompLocks <= 0) || m_bReconverting)
{
*pfOk = TRUE;
++m_cCompLocks;
Expand Down Expand Up @@ -103,13 +103,10 @@ CicInputContext::GetGuidAtom(
_Out_opt_ LPDWORD pdwGuidAtom)
{
CicIMCCLock<CTFIMECONTEXT> imeContext(imcLock.get().hCompStr);
HRESULT hr = imeContext.m_hr;
if (!imeContext)
hr = E_FAIL;
if (FAILED(hr))
return hr;
if (FAILED(imeContext.m_hr))
return imeContext.m_hr;

hr = E_FAIL;
HRESULT hr = E_FAIL;
if (iAtom < m_cGuidAtoms)
{
*pdwGuidAtom = m_adwGuidAtoms[iAtom];
Expand Down Expand Up @@ -251,6 +248,36 @@ CicInputContext::OnCleanupContext(
return S_OK;
}

/// @unimplemented
HRESULT CicInputContext::SetupDocFeedString(CicIMCLock& imcLock, UINT uCodePage)
{
return E_NOTIMPL;
}

/// @unimplemented
HRESULT CicInputContext::EscbClearDocFeedBuffer(CicIMCLock& imcLock, BOOL bFlag)
{
return E_NOTIMPL;
}

/// @unimplemented
HRESULT
CicInputContext::SetupReconvertString(
CicIMCLock& imcLock,
ITfThreadMgr_P *pThreadMgr,
UINT uCodePage,
DWORD dwUnknown61,
BOOL bUndo)
{
return E_NOTIMPL;
}

/// @unimplemented
HRESULT CicInputContext::EndReconvertString(CicIMCLock& imcLock)
{
return E_NOTIMPL;
}

/// Retrieves the IME information.
/// @implemented
HRESULT
Expand Down
12 changes: 11 additions & 1 deletion dll/ime/msctfime/inputcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CicInputContext
GUID m_guid;
DWORD m_dwUnknown6[11];
BOOL m_bSelecting;
DWORD m_dwUnknown6_5;
BOOL m_bReconverting;
LONG m_cCompLocks;
DWORD m_dwUnknown7[5];
WORD m_cGuidAtoms;
Expand Down Expand Up @@ -88,4 +88,14 @@ class CicInputContext

HRESULT CreateInputContext(_Inout_ ITfThreadMgr *pThreadMgr, _Inout_ CicIMCLock& imcLock);
HRESULT DestroyInputContext();

HRESULT SetupDocFeedString(CicIMCLock& imcLock, UINT uCodePage);
HRESULT EscbClearDocFeedBuffer(CicIMCLock& imcLock, BOOL bFlag);
HRESULT SetupReconvertString(
CicIMCLock& imcLock,
ITfThreadMgr_P *pThreadMgr,
UINT uCodePage,
DWORD dwUnknown61,
BOOL bUndo);
HRESULT EndReconvertString(CicIMCLock& imcLock);
};
35 changes: 6 additions & 29 deletions dll/ime/msctfime/msctfime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ HRESULT InitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread)
return hr;
}

HIMC GetActiveContext(VOID)
{
HWND hwndFocus = ::GetFocus();
if (!hwndFocus)
hwndFocus = ::GetActiveWindow();
return ::ImmGetContext(hwndFocus);
}

/// @implemented
HRESULT UninitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread)
{
Expand Down Expand Up @@ -184,8 +176,6 @@ InternalSelectEx(
_In_ LANGID LangID)
{
CicIMCLock imcLock(hIMC);
if (!imcLock)
imcLock.m_hr = E_FAIL;
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

Expand Down Expand Up @@ -608,25 +598,17 @@ CtfImeGetGuidAtom(
TRACE("(%p, 0x%lX, %p)\n", hIMC, dwUnknown, pdwGuidAtom);

CicIMCLock imcLock(hIMC);

HRESULT hr = imcLock.m_hr;
if (!imcLock)
hr = E_FAIL;
if (FAILED(hr))
return hr;
if (FAILED(imcLock.m_hr))
return imcLock.m_hr;

CicIMCCLock<CTFIMECONTEXT> imccLock(imcLock.get().hCtfImeContext);
hr = imccLock.m_hr;
if (!imccLock)
hr = E_FAIL;
if (FAILED(hr))
return hr;
if (FAILED(imccLock.m_hr))
return imccLock.m_hr;

if (!imccLock.get().m_pCicIC)
return E_OUTOFMEMORY;

hr = imccLock.get().m_pCicIC->GetGuidAtom(imcLock, dwUnknown, pdwGuidAtom);
return hr;
return imccLock.get().m_pCicIC->GetGuidAtom(imcLock, dwUnknown, pdwGuidAtom);
}

/***********************************************************************
Expand All @@ -641,13 +623,8 @@ CtfImeIsGuidMapEnable(
TRACE("(%p)\n", hIMC);

BOOL ret = FALSE;
HRESULT hr;
CicIMCLock imcLock(hIMC);

hr = imcLock.m_hr;
if (!imcLock)
hr = E_FAIL;
if (SUCCEEDED(hr))
if (SUCCEEDED(imcLock.m_hr))
ret = !!(imcLock.get().fdwInit & INIT_GUIDMAP);

return ret;
Expand Down
8 changes: 8 additions & 0 deletions dll/ime/msctfime/msctfime.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ EXTERN_C BOOLEAN WINAPI DllShutdownInProgress(VOID);
HRESULT InitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread);
HRESULT UninitDisplayAttrbuteLib(PCIC_LIBTHREAD pLibThread);

static inline HIMC GetActiveContext(VOID)
{
HWND hwndFocus = ::GetFocus();
if (!hwndFocus)
hwndFocus = ::GetActiveWindow();
return ::ImmGetContext(hwndFocus);
}

DEFINE_GUID(GUID_COMPARTMENT_CTFIME_DIMFLAGS, 0xA94C5FD2, 0xC471, 0x4031, 0x95, 0x46, 0x70, 0x9C, 0x17, 0x30, 0x0C, 0xB9);
DEFINE_GUID(GUID_COMPARTMENT_CTFIME_CICINPUTCONTEXT, 0x85A688F7, 0x6DC8, 0x4F17, 0xA8, 0x3A, 0xB1, 0x1C, 0x09, 0xCD, 0xD7, 0xBF);

Expand Down
2 changes: 0 additions & 2 deletions dll/ime/msctfime/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ STDMETHODIMP_(LRESULT)
CDefCompFrameWindow::OnWindowPosChanged(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CicIMCLock imcLock(m_hIMC);
if (!imcLock)
imcLock.m_hr = E_FAIL;
if (SUCCEEDED(imcLock.m_hr))
::SendMessage(imcLock.get().hWnd, WM_IME_NOTIFY, 0xF, (LPARAM)m_hIMC);
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
Expand Down
3 changes: 1 addition & 2 deletions sdk/lib/cicero/cicimc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class CicIMCCLock : public CIC_IMCC_LOCK<T_DATA>
public:
CicIMCCLock(HIMCC hIMCC) : CIC_IMCC_LOCK<T_DATA>(hIMCC)
{
if (hIMCC)
_LockIMCC(this->m_hIMCC, &this->m_pIMCC);
this->m_hr = _LockIMCC(this->m_hIMCC, &this->m_pIMCC);
}
~CicIMCCLock()
{
Expand Down

0 comments on commit f53f133

Please sign in to comment.