HRESULT CCompartmentEventSink::_Advise(_In_ IUnknown *punk, _In_ REFGUID guidCompartment)
{
    HRESULT hr = S_OK;
    ITfCompartmentMgr* pCompartmentMgr = nullptr;
    ITfSource* pSource = nullptr;

    hr = punk->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompartmentMgr);
    if (FAILED(hr))
    {
        return hr;
    }

    hr = pCompartmentMgr->GetCompartment(guidCompartment, &_pCompartment);
    if (SUCCEEDED(hr))
    {
        hr = _pCompartment->QueryInterface(IID_ITfSource, (void **)&pSource);
        if (SUCCEEDED(hr))
        {
            hr = pSource->AdviseSink(IID_ITfCompartmentEventSink, this, &_dwCookie);
            pSource->Release();
        }
    }

    pCompartmentMgr->Release();

    return hr;
}
BOOL CSampleIME::_InitTextEditSink(_In_ ITfDocumentMgr *pDocMgr)
{
    ITfSource* pSource = nullptr;
    BOOL ret = TRUE;

    // clear out any previous sink first
    if (_textEditSinkCookie != TF_INVALID_COOKIE)
    {
        if (SUCCEEDED(_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource)))
        {
            pSource->UnadviseSink(_textEditSinkCookie);
            pSource->Release();
        }

        _pTextEditSinkContext->Release();
        _pTextEditSinkContext = nullptr;
        _textEditSinkCookie = TF_INVALID_COOKIE;
    }

    if (pDocMgr == nullptr)
    {
        return TRUE; // caller just wanted to clear the previous sink
    }

    if (FAILED(pDocMgr->GetTop(&_pTextEditSinkContext)))
    {
        return FALSE;
    }

    if (_pTextEditSinkContext == nullptr)
    {
        return TRUE; // empty document, no sink possible
    }

    ret = FALSE;
    if (SUCCEEDED(_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource)))
    {
        if (SUCCEEDED(pSource->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &_textEditSinkCookie)))
        {
            ret = TRUE;
        }
        else
        {
            _textEditSinkCookie = TF_INVALID_COOKIE;
        }
        pSource->Release();
    }

    if (ret == FALSE)
    {
        _pTextEditSinkContext->Release();
        _pTextEditSinkContext = nullptr;
    }

    return ret;
}
Example #3
0
BOOL CTextService::_InitTextEditSink(ITfDocumentMgr *pDocumentMgr)
{
	BOOL fRet = FALSE;

	if(_pTextEditSinkContext != nullptr && _dwTextEditSinkCookie != TF_INVALID_COOKIE)
	{
		ITfSource *pSource = nullptr;
		if(SUCCEEDED(_pTextEditSinkContext->QueryInterface(IID_PPV_ARGS(&pSource))) && (pSource != nullptr))
		{
			pSource->UnadviseSink(_dwTextEditSinkCookie);
			SafeRelease(&pSource);
		}

		SafeRelease(&_pTextEditSinkContext);
		_dwTextEditSinkCookie = TF_INVALID_COOKIE;
	}

	if(pDocumentMgr == nullptr)
	{
		return TRUE;
	}

	if(FAILED(pDocumentMgr->GetTop(&_pTextEditSinkContext)))
	{
		return FALSE;
	}

	if(_pTextEditSinkContext == nullptr)
	{
		return TRUE;
	}

	{
		ITfSource *pSource = nullptr;
		if(SUCCEEDED(_pTextEditSinkContext->QueryInterface(IID_PPV_ARGS(&pSource))) && (pSource != nullptr))
		{
			if(SUCCEEDED(pSource->AdviseSink(IID_IUNK_ARGS((ITfTextEditSink *)this), &_dwTextEditSinkCookie)))
			{
				fRet = TRUE;
			}
			else
			{
				_dwTextEditSinkCookie = TF_INVALID_COOKIE;
			}
			SafeRelease(&pSource);
		}
	}

	if(fRet == FALSE)
	{
		SafeRelease(&_pTextEditSinkContext);
	}

	return fRet;
}
BOOL CTextService::_InitTextEditSink(ITfDocumentMgr *pDocMgr)
{
    ITfSource *pSource;
    BOOL fRet;

    // clear out any previous sink first

    if (_dwTextEditSinkCookie != TF_INVALID_COOKIE)
    {
        if (_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
        {
            pSource->UnadviseSink(_dwTextEditSinkCookie);
            pSource->Release();
        }

        _pTextEditSinkContext->Release();
        _pTextEditSinkContext = NULL;
        _dwTextEditSinkCookie = TF_INVALID_COOKIE;
    }

    if (pDocMgr == NULL)
        return TRUE; // caller just wanted to clear the previous sink

    // setup a new sink advised to the topmost context of the document

    if (pDocMgr->GetTop(&_pTextEditSinkContext) != S_OK)
        return FALSE;

    if (_pTextEditSinkContext == NULL)
        return TRUE; // empty document, no sink possible

    fRet = FALSE;

    if (_pTextEditSinkContext->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
    {
        if (pSource->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &_dwTextEditSinkCookie) == S_OK)
        {
            fRet = TRUE;
        }
        else
        {
            _dwTextEditSinkCookie = TF_INVALID_COOKIE;
        }
        pSource->Release();
    }

    if (fRet == FALSE)
    {
        _pTextEditSinkContext->Release();
        _pTextEditSinkContext = NULL;
    }

    return fRet;
}
BOOL CExtentMonitorTextService::_InitThreadFocusSink()
{
    ITfSource *pSource;

    if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
    {
        pSource->AdviseSink(IID_ITfThreadFocusSink, (ITfThreadFocusSink *)this, &_dwThreadFocusCookie);
        pSource->Release();
    }

    return TRUE;
}
BOOL WeaselTSF::_InitThreadMgrEventSink()
{
	ITfSource *pSource;
	if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **) &pSource) != S_OK)
		return FALSE;
	if (pSource->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *) this, &_dwThreadMgrEventSinkCookie) != S_OK)
	{
		_dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
		pSource->Release();
		return FALSE;
	}
	return TRUE;
}
HRESULT CCandidateList::_AdviseContextKeyEventSink()
{
	HRESULT hr = E_FAIL;

	ITfSource *pSource;
	if(_pContextCandidateWindow->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK)
	{
		hr = pSource->AdviseSink(IID_IUNK_ARGS((ITfContextKeyEventSink *)this), &_dwCookieContextKeyEventSink);
		SafeRelease(&pSource);
	}

	return hr;
}
Example #8
0
HRESULT CInputModeWindow::_AdviseTextLayoutSink()
{
	HRESULT hr = E_FAIL;

	ITfSource *pSource;
	if(_pContext->QueryInterface(IID_PPV_ARGS(&pSource)) == S_OK)
	{
		hr = pSource->AdviseSink(IID_IUNK_ARGS((ITfTextLayoutSink *)this), &_dwCookieTextLayoutSink);
		SafeRelease(&pSource);
	}

	return hr;
}
Example #9
0
HRESULT CCandidateList::_AdviseContextKeyEventSink(){
    HRESULT hr;
    ITfSource *pSource = NULL;

    hr = E_FAIL;

    if (FAILED(_pContextCandidateWindow->QueryInterface(IID_ITfSource, (void **)&pSource)))
        goto Exit;

    if (FAILED(pSource->AdviseSink(IID_ITfContextKeyEventSink, (ITfContextKeyEventSink *)this, &_dwCookieContextKeyEventSink)))
        goto Exit;

    hr = S_OK;

Exit:
    if (pSource != NULL)
        pSource->Release();
    return hr;
}
Example #10
0
BOOL CIME::_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;
}
Example #11
0
BOOL CTextService::_InitThreadMgrEventSink()
{
	BOOL fRet = FALSE;

	ITfSource *pSource = nullptr;
	if(SUCCEEDED(_pThreadMgr->QueryInterface(IID_PPV_ARGS(&pSource))) && (pSource != nullptr))
	{
		if(SUCCEEDED(pSource->AdviseSink(IID_IUNK_ARGS((ITfThreadMgrEventSink *)this), &_dwThreadMgrEventSinkCookie)))
		{
			fRet = TRUE;
		}
		else
		{
			_dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
		}
		SafeRelease(&pSource);
	}

	return fRet;
}
HRESULT touchmind::control::DWriteEditControlTextEditSink::Advise(ITfContext *pTfContext)
{
    HRESULT hr = E_FAIL;

    ITfSource *source = nullptr;
    hr = pTfContext->QueryInterface(IID_ITfSource, (void **)&source);
    if (FAILED(hr)) {
        LOG(SEVERITY_LEVEL_ERROR) << L"QueryInterface failed";
    }

    if (SUCCEEDED(hr)) {
        hr = source->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &m_editCookie);
        if (FAILED(hr)) {
            LOG(SEVERITY_LEVEL_ERROR) << L"AdviseSink failed";
        }
    }
    SafeRelease(&source);
    //AddRef(); // don't need
    return hr;
}
BOOL AdviseSink(IUnknown *pSourceIn, IUnknown *pSink, REFIID riid, DWORD *pdwCookie)
{
    ITfSource *pSource;
    HRESULT hr;

    if (pSourceIn->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
        return FALSE;

    hr = pSource->AdviseSink(riid, pSink, pdwCookie);

    pSource->Release();

    if (hr != S_OK)
    {
        // make sure we don't try to Unadvise pdwCookie later
        *pdwCookie = TF_INVALID_COOKIE;
        return FALSE;
    }

    return TRUE;
}
BOOL CSampleIME::_InitThreadMgrEventSink()
{
    ITfSource* pSource = nullptr;
    BOOL ret = FALSE;

    if (FAILED(_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource)))
    {
        return ret;
    }

    if (FAILED(pSource->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *)this, &_threadMgrEventSinkCookie)))
    {
        _threadMgrEventSinkCookie = TF_INVALID_COOKIE;
        goto Exit;
    }

    ret = TRUE;

Exit:
    pSource->Release();
    return ret;
}
BOOL COVTSF::_InitActiveLanguageProfileNotifySink()
{
    ITfSource* pSource = nullptr;
    BOOL ret = FALSE;

    if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
    {
        return ret;
    }

    if (pSource->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, (ITfActiveLanguageProfileNotifySink *)this, &_activeLanguageProfileNotifySinkCookie) != S_OK)
    {
        _activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE;
        goto Exit;
    }

    ret = TRUE;

Exit:
    pSource->Release();
    return ret;
}
BOOL CCaseTextService::_InitThreadMgrSink()
{
    ITfSource *pSource;
    BOOL fRet;

    if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
        return FALSE;

    fRet = FALSE;

    if (pSource->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *)this, &_dwThreadMgrEventSinkCookie) != S_OK)
    {
        // make sure we don't try to Unadvise _dwThreadMgrEventSinkCookie later
        _dwThreadMgrEventSinkCookie = TF_INVALID_COOKIE;
        goto Exit;
    }

    fRet = TRUE;

Exit:
    pSource->Release();
    return fRet;
}
HRESULT CTextEditSink::_Advise(ITfContext *pic)
{
    HRESULT hr;
    ITfSource *source = NULL;

    _pic = NULL;
    hr = E_FAIL;

    if (FAILED(pic->QueryInterface(IID_ITfSource, (void **)&source)))
        goto Exit;

    if (FAILED(source->AdviseSink(IID_ITfTextEditSink, (ITfTextEditSink *)this, &_dwEditCookie)))
        goto Exit;

    _pic = pic;
    _pic->AddRef();

    hr = S_OK;

Exit:
    if (source)
        source->Release();
    return hr;
}
HRESULT CCompartmentMonitor::Initialize(    const GUID *pguidCompartment,
        PCOMPARTMENTMONITORPROC pCallback,
        LPARAM lParam)
{
    if(!IsEqualGUID(m_guidCompartment, GUID_NULL))
    {
        //Initialize() has already been called
        return E_UNEXPECTED;
    }

    m_guidCompartment = *pguidCompartment;
    m_pCallback = pCallback;
    m_lParam = lParam;

    HRESULT         hr;
    ITfThreadMgr    *pThreadMgr;

    //create a thread manager object
    hr = CoCreateInstance(CLSID_TF_ThreadMgr,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_ITfThreadMgr,
                          (void**)&pThreadMgr);

    if(SUCCEEDED(hr))
    {
        ITfCompartmentMgr   *pCompMgr;

        //get the global compartment manager
        hr = pThreadMgr->GetGlobalCompartment(&pCompMgr);
        if(SUCCEEDED(hr))
        {
            //get the Speech UI compartment
            hr = pCompMgr->GetCompartment(m_guidCompartment,
                                          &m_pCompartment);
            if(SUCCEEDED(hr))
            {
                ITfSource   *pSource;

                //install the advise sink
                hr = m_pCompartment->QueryInterface(IID_ITfSource,
                                                    (LPVOID*)&pSource);
                if(SUCCEEDED(hr))
                {
                    hr = pSource->AdviseSink(IID_ITfCompartmentEventSink,
                                             (ITfCompartmentEventSink*)this,
                                             &m_dwCookie);
                }

                //if something went wrong, release the member interface
                if(FAILED(hr))
                {
                    m_pCompartment->Release();
                    m_pCompartment = NULL;
                }
            }

            //release the compartment manager
            pCompMgr->Release();
        }

        //release the thread manager
        pThreadMgr->Release();
    }

    return hr;
}