Esempio n. 1
0
HRESULT CSampleIME::_SetInputString(TfEditCookie ec, _In_ ITfContext *pContext, _Out_opt_ ITfRange *pRange, _In_ const std::wstring &pstrAddString, BOOL exist_composing)
{
    ITfRange* pRangeInsert = nullptr;
    if (!exist_composing)
    {
        _InsertAtSelection(ec, pContext, pstrAddString, &pRangeInsert);
        if (pRangeInsert == nullptr)
        {
            return S_OK;
        }
        pRange = pRangeInsert;
    }
    if (pRange != nullptr)
    {
        pRange->SetText(ec, 0, pstrAddString.c_str(), pstrAddString.length());
    }

	/* sets GUID_PROP_LANGID */
    _SetCompositionLanguage(ec, pContext);
	/* sets GUID_PROP_ATTRIBUTE */
    _SetCompositionDisplayAttributes(ec, pContext, _gaDisplayAttributeInput);

    // update the selection, we'll make it an insertion point just past
    // the inserted text.
    ITfRange* pSelection = nullptr;
    TF_SELECTION sel;

    if ((pRange != nullptr) && (pRange->Clone(&pSelection) == S_OK))
    {
        pSelection->Collapse(ec, TF_ANCHOR_END);

        sel.range = pSelection;
        sel.style.ase = TF_AE_NONE;
        sel.style.fInterimChar = FALSE;
        pContext->SetSelection(ec, 1, &sel);
        pSelection->Release();
    }

    if (pRangeInsert)
    {
        pRangeInsert->Release();
    }


    return S_OK;
}
Esempio n. 2
0
HRESULT CDIME::_SetInputString(TfEditCookie ec, _In_ ITfContext *pContext, _Out_opt_ ITfRange *pRange, _In_ CStringRange *pstrAddString, BOOL exist_composing)
{
	debugPrint(L"CDIME::_SetInputString() exist_composing = %x", exist_composing);
    ITfRange* pRangeInsert = nullptr;
	HRESULT hr = S_OK;
    if (!exist_composing)
    {
        _InsertAtSelection(ec, pContext, pstrAddString, &pRangeInsert);
        if (pRangeInsert == nullptr)
        {
            return hr;
        }
        pRange = pRangeInsert;
    }
    if (pRange != nullptr)
    {
        hr = pRange->SetText(ec, 0, pstrAddString->Get(), (LONG)pstrAddString->GetLength());
		if (FAILED(hr))
		{
			debugPrint(L"CDIME::_SetInputString() pRange->SetText() failed with hr = %x", hr);			
			goto exit;
		}

    }
	
	if (!_SetCompositionLanguage(ec, pContext))
	{
		debugPrint(L"CDIME::_SetInputString() _SetCompositionLanguage failed");
		hr = E_FAIL;
		goto exit;
	}

	if (!_SetCompositionDisplayAttributes(ec, pContext, _gaDisplayAttributeInput))
	{
		debugPrint(L"CDIME::_SetInputString() _SetCompositionDisplayAttributes() failed");
		hr = E_FAIL;
		goto exit;
	}

    // update the selection, we'll make it an insertion point just past
    // the inserted text.
    ITfRange* pSelection = nullptr;
    TF_SELECTION sel;

    if ((pRange != nullptr) && (pRange->Clone(&pSelection) == S_OK))
    {
        hr = pSelection->Collapse(ec, TF_ANCHOR_END);
		if (FAILED(hr))
		{
			debugPrint(L"CDIME::_SetInputString() pSelection->Collapse() failed, hr = %x", hr);
			goto exit;
		}

        sel.range = pSelection;
        sel.style.ase = TF_AE_NONE;
        sel.style.fInterimChar = FALSE;
        pContext->SetSelection(ec, 1, &sel);
        pSelection->Release();
    }

exit:
    if (pRangeInsert)
        pRangeInsert->Release();

    return hr;
}