当前位置: 首页>>代码示例>>C++>>正文


C++ ITfRange::Collapse方法代码示例

本文整理汇总了C++中ITfRange::Collapse方法的典型用法代码示例。如果您正苦于以下问题:C++ ITfRange::Collapse方法的具体用法?C++ ITfRange::Collapse怎么用?C++ ITfRange::Collapse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITfRange的用法示例。


在下文中一共展示了ITfRange::Collapse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoEditSession

STDAPI WeaselTSF::DoEditSession(TfEditCookie ec)
{
	ITfInsertAtSelection *pInsertAtSelection;
	ITfRange *pRange;
	TF_SELECTION tfSelection;

	if (_pEditSessionContext->QueryInterface(IID_ITfInsertAtSelection, (LPVOID *) &pInsertAtSelection) != S_OK)
		return E_FAIL;

	/* insert the text */
	if (pInsertAtSelection->InsertTextAtSelection(ec, 0, _pEditSessionText, _cEditSessionText, &pRange) != S_OK)
	{
		pInsertAtSelection->Release();
		return E_FAIL;
	}

	/* update the selection to an insertion point just past the inserted text. */
	pRange->Collapse(ec, TF_ANCHOR_END);

	tfSelection.range = pRange;
	tfSelection.style.ase = TF_AE_NONE;
	tfSelection.style.fInterimChar = FALSE;

	_pEditSessionContext->SetSelection(ec, 1, &tfSelection);

	pRange->Release();
	pInsertAtSelection->Release();

	return S_OK;
}
开发者ID:e42s,项目名称:weasel,代码行数:30,代码来源:EditSession.cpp

示例2: InsertTextAtSelection

void InsertTextAtSelection(TfEditCookie ec, ITfContext *pContext, const WCHAR *pchText, ULONG cchText)
{
    ITfInsertAtSelection *pInsertAtSelection;
    ITfRange *pRange;
    TF_SELECTION tfSelection;

    // we need a special interface to insert text at the selection
    if (pContext->QueryInterface(IID_ITfInsertAtSelection, (void **)&pInsertAtSelection) != S_OK)
        return;

    // insert the text
    if (pInsertAtSelection->InsertTextAtSelection(ec, 0, pchText, cchText, &pRange) != S_OK)
        goto Exit;

    // update the selection, we'll make it an insertion point just past
    // the inserted text.
    pRange->Collapse(ec, TF_ANCHOR_END);

    tfSelection.range = pRange;
    tfSelection.style.ase = TF_AE_NONE;
    tfSelection.style.fInterimChar = FALSE;

    pContext->SetSelection(ec, 1, &tfSelection);

    pRange->Release();

Exit:
    pInsertAtSelection->Release();
}
开发者ID:Ippei-Murofushi,项目名称:WindowsSDK7-Samples,代码行数:29,代码来源:InsertHello.cpp

示例3: DoEditSession

STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec)
{
	HRESULT hr = E_FAIL;
	ITfInsertAtSelection *pInsertAtSelection = NULL;
	ITfRange *pRangeComposition = NULL;
	if (_pContext->QueryInterface(IID_ITfInsertAtSelection, (LPVOID *) &pInsertAtSelection) != S_OK)
		goto Exit;
	if (pInsertAtSelection->InsertTextAtSelection(ec, TF_IAS_QUERYONLY, NULL, 0, &pRangeComposition) != S_OK)
		goto Exit;
	
	ITfContextComposition *pContextComposition = NULL;
	ITfComposition *pComposition = NULL;
	if (_pContext->QueryInterface(IID_ITfContextComposition, (LPVOID *) &pContextComposition) != S_OK)
		goto Exit;
	if ((pContextComposition->StartComposition(ec, pRangeComposition, _pTextService, &pComposition) == S_OK) && (pComposition != NULL))
	{
		_pTextService->_SetComposition(pComposition);
		
		/* set selection */
		/* WORKAROUND:
		 *   CUAS does not provide a correct GetTextExt() position unless the composition is filled with characters.
		 *   So we insert a dummy space character here.
		 *   This is the same workaround used by Microsoft Pinyin IME (New Experience).
		 */
		if (_fCUASWorkaroundEnabled)
		{
			pRangeComposition->SetText(ec, TF_ST_CORRECTION, L" ", 1);
			pRangeComposition->Collapse(ec, TF_ANCHOR_START);
		}
		TF_SELECTION tfSelection;
		tfSelection.range = pRangeComposition;
		tfSelection.style.ase = TF_AE_NONE;
		tfSelection.style.fInterimChar = FALSE;
		_pContext->SetSelection(ec, 1, &tfSelection);
	}
	
Exit:
	if (pContextComposition != NULL)
		pContextComposition->Release();
	if (pRangeComposition != NULL)
		pRangeComposition->Release();
	if (pInsertAtSelection != NULL)
		pInsertAtSelection->Release();

	return hr;
}
开发者ID:wyrover,项目名称:weasel,代码行数:46,代码来源:Composition.cpp

示例4: _SetInputString

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;
}
开发者ID:xkjyeah,项目名称:itf-unicode-db,代码行数:46,代码来源:CSI_Composition.cpp

示例5: ToggleCase

void ToggleCase(TfEditCookie ec, ITfRange *pRange, BOOL fIgnoreRangeEnd)
{
    ITfRange *pRangeToggle;
    ULONG cch;
    ULONG i;
    DWORD dwFlags;
    WCHAR achText[64];

    // backup the current range
    if (pRange->Clone(&pRangeToggle) != S_OK)
        return;

    dwFlags = TF_TF_MOVESTART | (fIgnoreRangeEnd ? TF_TF_IGNOREEND : 0);

    while (TRUE)
    {
        // grab the next block of chars
        if (pRange->GetText(ec, dwFlags, achText, ARRAYSIZE(achText), &cch) != S_OK)
            break;

        // out of text?
        if (cch == 0)
            break;

        // toggle the case
        for (i=0; i<cch; i++)
        {
            achText[i] = ToggleChar(achText[i]);
        }

        // shift pRangeToggle so it covers just the text we read
        if (pRangeToggle->ShiftEndToRange(ec, pRange, TF_ANCHOR_START) != S_OK)
            break;

        // replace the text
        pRangeToggle->SetText(ec, 0, achText, cch);

        // prepare for next iteration
        pRangeToggle->Collapse(ec, TF_ANCHOR_END);
    }
    
    pRangeToggle->Release();
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:43,代码来源:globals.cpp

示例6: _HandleCharShift

HRESULT CTextService::_HandleCharShift(TfEditCookie ec, ITfContext *pContext)
{
	if(showentry || (!inputkey && !kana.empty() && roman.empty()))
	{
		_EndCompletionList(ec, pContext);

		//leave composition
		cursoridx = kana.size();
		_Update(ec, pContext, TRUE);
		if(pContext != NULL)
		{
			ITfRange *pRange;
			if(_IsComposing() && _pComposition->GetRange(&pRange) == S_OK)
			{
				pRange->Collapse(ec, TF_ANCHOR_END);
				_pComposition->ShiftStart(ec, pRange);
				SafeRelease(&pRange);
			}
		}
		_ResetStatus();
	}

	return S_OK;
}
开发者ID:SGA-Takeshi-Tsukamoto,项目名称:corvusskk,代码行数:24,代码来源:KeyHandlerChar.cpp

示例7: _SetInputString

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;
}
开发者ID:jrywu,项目名称:DIME,代码行数:66,代码来源:Composition.cpp


注:本文中的ITfRange::Collapse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。