102 lines
2.7 KiB
C++
102 lines
2.7 KiB
C++
#include "Ipc.h"
|
|
#include "Private.h"
|
|
#include "MetasequoiaIME.h"
|
|
#include "CandidateListUIPresenter.h"
|
|
#include <debugapi.h>
|
|
#include "fmt/xchar.h"
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// ITfTextLayoutSink::OnSetThreadFocus
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
STDAPI CMetasequoiaIME::OnSetThreadFocus()
|
|
{
|
|
if (_pCandidateListUIPresenter)
|
|
{
|
|
ITfDocumentMgr *pCandidateListDocumentMgr = nullptr;
|
|
ITfContext *pTfContext = _pCandidateListUIPresenter->_GetContextDocument();
|
|
|
|
if ((nullptr != pTfContext) && SUCCEEDED(pTfContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
|
|
{
|
|
if (pCandidateListDocumentMgr == _pDocMgrLastFocused)
|
|
{
|
|
_pCandidateListUIPresenter->OnSetThreadFocus();
|
|
}
|
|
|
|
pCandidateListDocumentMgr->Release();
|
|
}
|
|
}
|
|
return S_OK;
|
|
}
|
|
|
|
//+---------------------------------------------------------------------------
|
|
//
|
|
// ITfTextLayoutSink::OnKillThreadFocus
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
STDAPI CMetasequoiaIME::OnKillThreadFocus()
|
|
{
|
|
if (_pCandidateListUIPresenter)
|
|
{
|
|
ITfDocumentMgr *pCandidateListDocumentMgr = nullptr;
|
|
ITfContext *pTfContext = _pCandidateListUIPresenter->_GetContextDocument();
|
|
|
|
if ((nullptr != pTfContext) && SUCCEEDED(pTfContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
|
|
{
|
|
if (_pDocMgrLastFocused)
|
|
{
|
|
_pDocMgrLastFocused->Release();
|
|
_pDocMgrLastFocused = nullptr;
|
|
}
|
|
_pDocMgrLastFocused = pCandidateListDocumentMgr;
|
|
if (_pDocMgrLastFocused)
|
|
{
|
|
_pDocMgrLastFocused->AddRef();
|
|
}
|
|
}
|
|
_pCandidateListUIPresenter->OnKillThreadFocus();
|
|
}
|
|
return S_OK;
|
|
}
|
|
|
|
BOOL CMetasequoiaIME::_InitThreadFocusSink()
|
|
{
|
|
ITfSource *pSource = nullptr;
|
|
|
|
if (FAILED(_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
if (FAILED(pSource->AdviseSink(IID_ITfThreadFocusSink, (ITfThreadFocusSink *)this, &_dwThreadFocusSinkCookie)))
|
|
{
|
|
pSource->Release();
|
|
return FALSE;
|
|
}
|
|
|
|
pSource->Release();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CMetasequoiaIME::_UninitThreadFocusSink()
|
|
{
|
|
ITfSource *pSource = nullptr;
|
|
|
|
if (FAILED(_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (FAILED(pSource->UnadviseSink(_dwThreadFocusSinkCookie)))
|
|
{
|
|
pSource->Release();
|
|
return;
|
|
}
|
|
|
|
pSource->Release();
|
|
}
|