HRESULT CCandidateListUIPresenter::_CandidateChangeNotification(_In_ enum CANDWND_ACTION action)
{
    HRESULT hr = E_FAIL;

    TfClientId tfClientId = _pTextService->_GetClientId();
    ITfThreadMgr* pThreadMgr = nullptr;
    ITfDocumentMgr* pDocumentMgr = nullptr;
    ITfContext* pContext = nullptr;

    _KEYSTROKE_STATE KeyState;
    KeyState.Category = _Category;
    KeyState.Function = FUNCTION_FINALIZE_CANDIDATELIST;

    if (CAND_ITEM_SELECT != action)
    {
        goto Exit;
    }

    pThreadMgr = _pTextService->_GetThreadMgr();
    if (nullptr == pThreadMgr)
    {
        goto Exit;
    }

    hr = pThreadMgr->GetFocus(&pDocumentMgr);
    if (FAILED(hr))
    {
        goto Exit;
    }

    hr = pDocumentMgr->GetTop(&pContext);
    if (FAILED(hr))
    {
        pDocumentMgr->Release();
        goto Exit;
    }

    CKeyHandlerEditSession *pEditSession = new (std::nothrow) CKeyHandlerEditSession(_pTextService, pContext, 0, 0, KeyState);
    if (nullptr != pEditSession)
    {
        HRESULT hrSession = S_OK;
        hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hrSession);
        if (hrSession == TF_E_SYNCHRONOUS || hrSession == TS_E_READONLY)
        {
            hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession);
        }
        pEditSession->Release();
    }

    pContext->Release();
    pDocumentMgr->Release();

Exit:
    return hr;
}
/* static */
void CMarkTextService::_Menu_OnComposition(CMarkTextService *_this)
{
    ITfDocumentMgr *pFocusDoc;
    ITfContext *pContext;
    CCompositionEditSession *pCompositionEditSession;
    HRESULT hr;

    // get the focus document
    if (_this->_pThreadMgr->GetFocus(&pFocusDoc) != S_OK)
        return;

    // we want the topmost context, since the main doc context could be
    // superceded by a modal tip context
    if (pFocusDoc->GetTop(&pContext) != S_OK)
    {
        pContext = NULL;
        goto Exit;
    }

    if (pCompositionEditSession = new CCompositionEditSession(pContext, _this))
    {
        // we need a document write lock
        // the CCompositionEditSession will do all the work when the
        // CCompositionEditSession::DoEditSession method is called by the context
        pContext->RequestEditSession(_this->_tfClientId, pCompositionEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);

        pCompositionEditSession->Release();
    }

Exit:
    SafeRelease(pContext);
    pFocusDoc->Release();    
}
void CTextService::InsertHello()
{
    ITfDocumentMgr *pDocMgrFocus;
    ITfContext *pContext;
    CInsertHelloEditSession *pInsertHelloEditSession;
    HRESULT hr;

    // get the focus document
    if (_pThreadMgr->GetFocus(&pDocMgrFocus) != S_OK)
        return;

    // we want the topmost context, since the main doc context could be
    // superceded by a modal tip context
    if (pDocMgrFocus->GetTop(&pContext) != S_OK)
    {
        pContext = NULL;
        goto Exit;
    }

    if (pInsertHelloEditSession = new CInsertHelloEditSession(pContext))
    {
        // we need a document write lock to insert text
        // the CInsertHelloEditSession will do all the work when the
        // CInsertHelloEditSession::DoEditSession method is called by the context
        pContext->RequestEditSession(_tfClientId, pInsertHelloEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);

        pInsertHelloEditSession->Release();
    }

Exit:
    if (pContext)
        pContext->Release();    

    pDocMgrFocus->Release();    
}
Ejemplo n.º 4
0
void CTextService::_StartInputModeWindow()
{
	switch(inputmode)
	{
	case im_default:
	case im_hiragana:
	case im_katakana:
	case im_katakana_ank:
	case im_jlatin:
	case im_ascii:
		_EndInputModeWindow();

		ITfDocumentMgr *pDocumentMgr;
		if((_pThreadMgr->GetFocus(&pDocumentMgr) == S_OK) && (pDocumentMgr != nullptr))
		{
			ITfContext *pContext;
			if((pDocumentMgr->GetTop(&pContext) == S_OK) && (pContext != nullptr))
			{
				try
				{
					_pInputModeWindow = new CInputModeWindow();

					if(_pInputModeWindow->_Create(this, pContext, FALSE, nullptr))
					{
						HRESULT hr = E_FAIL;
						HRESULT hrSession = E_FAIL;

						try
						{
							CInputModeWindowEditSession *pEditSession = new CInputModeWindowEditSession(this, pContext, _pInputModeWindow);
							// Asynchronous, read-only
							hr = pContext->RequestEditSession(_ClientId, pEditSession, TF_ES_ASYNC | TF_ES_READ, &hrSession);
							SafeRelease(&pEditSession);

							// It is possible that asynchronous requests are treated as synchronous requests.
							if(hr != S_OK || (hrSession != TF_S_ASYNC && hrSession != S_OK))
							{
								_EndInputModeWindow();
							}
						}
						catch(...)
						{
						}
					}
				}
				catch(...)
				{
				}

				SafeRelease(&pContext);
			}

			SafeRelease(&pDocumentMgr);
		}
		break;
	default:
		break;
	}
}
void CTextService::_AttachStaticProperty(WCHAR *psz)
{
    ITfDocumentMgr *pDocMgrFocus;
    ITfContext *pContext;

    if ((_pThreadMgr->GetFocus(&pDocMgrFocus) == S_OK) &&
        (pDocMgrFocus != NULL))
    {
        if (pDocMgrFocus->GetTop(&pContext) == S_OK)
        {
            CStaticPropertyEditSession *pEditSession;
            if (pEditSession = new CStaticPropertyEditSession(this, pContext, psz))
            {
                HRESULT hr;
                pContext->RequestEditSession(_tfClientId, pEditSession, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
                pEditSession->Release();
            }
            pContext->Release();
        }
        pDocMgrFocus->Release();
    }

    return;
}