本文整理汇总了C++中ITfRange类的典型用法代码示例。如果您正苦于以下问题:C++ ITfRange类的具体用法?C++ ITfRange怎么用?C++ ITfRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITfRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: _HandleCompositionArrowKey
HRESULT COVTSF::_HandleCompositionArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, KEYSTROKE_FUNCTION keyFunction)
{
ITfRange* pRangeComposition = nullptr;
TF_SELECTION tfSelection;
ULONG fetched = 0;
// get the selection
if (FAILED(pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched))
|| fetched != 1)
{
// no selection, eat the keystroke
return S_OK;
}
// get the composition range
if (FAILED(_pComposition->GetRange(&pRangeComposition)))
{
goto Exit;
}
// For incremental candidate list
if (_pCandidateListUIPresenter)
{
_pCandidateListUIPresenter->AdviseUIChangedByArrowKey(keyFunction);
}
pContext->SetSelection(ec, 1, &tfSelection);
pRangeComposition->Release();
Exit:
tfSelection.range->Release();
return S_OK;
}
示例3: debugPrint
HRESULT CDIME::_CreateAndStartCandidate(_In_ CCompositionProcessorEngine *pCompositionProcessorEngine, TfEditCookie ec, _In_ ITfContext *pContext)
{
debugPrint(L"CDIME::_CreateAndStartCandidate(), _candidateMode = %d", _candidateMode);
HRESULT hr = S_OK;
if ((_candidateMode == CANDIDATE_NONE) && (_pUIPresenter))
{
// we don't cache the document manager object. So get it from pContext.
ITfDocumentMgr* pDocumentMgr = nullptr;
if (SUCCEEDED(pContext->GetDocumentMgr(&pDocumentMgr)))
{
// get the composition range.
ITfRange* pRange = nullptr;
if (SUCCEEDED(_pComposition->GetRange(&pRange)))
{
hr = _pUIPresenter->_StartCandidateList(_tfClientId, pDocumentMgr, pContext, ec, pRange, pCompositionProcessorEngine->GetCandidateWindowWidth());
pRange->Release();
}
pDocumentMgr->Release();
}
}
return hr;
}
示例4: 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;
}
示例5: doEndCompositionEditSession
// callback from edit session for ending composition
HRESULT TextService::doEndCompositionEditSession(TfEditCookie cookie, EndCompositionEditSession* session) {
if(composition_) {
// move current insertion point to end of the composition string
ITfRange* compositionRange;
if(composition_->GetRange(&compositionRange) == S_OK) {
// clear display attribute for the composition range
ComPtr<ITfProperty> dispAttrProp;
if(session->context()->GetProperty(GUID_PROP_ATTRIBUTE, &dispAttrProp) == S_OK) {
dispAttrProp->Clear(cookie, compositionRange);
}
TF_SELECTION selection;
ULONG selectionNum;
if(session->context()->GetSelection(cookie, TF_DEFAULT_SELECTION, 1, &selection, &selectionNum) == S_OK) {
selection.range->ShiftEndToRange(cookie, compositionRange, TF_ANCHOR_END);
selection.range->Collapse(cookie, TF_ANCHOR_END);
session->context()->SetSelection(cookie, 1, &selection);
selection.range->Release();
}
compositionRange->Release();
}
// end composition and clean up
composition_->EndComposition(cookie);
// do some cleanup in the derived class here
onCompositionTerminated(false);
composition_->Release();
composition_ = NULL;
}
return S_OK;
}
示例6: doStartCompositionEditSession
// callback from edit session for starting composition
HRESULT TextService::doStartCompositionEditSession(TfEditCookie cookie, StartCompositionEditSession* session) {
ITfContext* context = session->context();
ITfContextComposition* contextComposition;
if(context->QueryInterface(IID_ITfContextComposition, (void**)&contextComposition) == S_OK) {
// get current insertion point in the current context
ITfRange* range = NULL;
ITfInsertAtSelection* insertAtSelection;
if(context->QueryInterface(IID_ITfInsertAtSelection, (void **)&insertAtSelection) == S_OK) {
// get current selection range & insertion position (query only, did not insert any text)
insertAtSelection->InsertTextAtSelection(cookie, TF_IAS_QUERYONLY, NULL, 0, &range);
insertAtSelection->Release();
}
if(range) {
if(contextComposition->StartComposition(cookie, range, (ITfCompositionSink*)this, &composition_) == S_OK) {
// according to the TSF sample provided by M$, we need to reset current
// selection here. (maybe the range is altered by StartComposition()?
// So mysterious. TSF is absolutely overly-engineered!
TF_SELECTION selection;
selection.range = range;
selection.style.ase = TF_AE_NONE;
selection.style.fInterimChar = FALSE;
context->SetSelection(cookie, 1, &selection);
// we did not release composition_ object. we store it for use later
}
range->Release();
}
contextComposition->Release();
}
return S_OK;
}
示例7: _SetCompositionDisplayAttributes
BOOL CTextService::_SetCompositionDisplayAttributes(TfEditCookie ec, ITfContext *pContext, TfGuidAtom gaDisplayAttribute)
{
ITfRange *pRangeComposition;
ITfProperty *pDisplayAttributeProperty;
HRESULT hr;
// we need a range and the context it lives in
if (_pComposition->GetRange(&pRangeComposition) != S_OK)
return FALSE;
hr = E_FAIL;
// get our the display attribute property
if (pContext->GetProperty(GUID_PROP_ATTRIBUTE, &pDisplayAttributeProperty) == S_OK)
{
VARIANT var;
// set the value over the range
// the application will use this guid atom to lookup the acutal rendering information
var.vt = VT_I4; // we're going to set a TfGuidAtom
var.lVal = gaDisplayAttribute;
hr = pDisplayAttributeProperty->SetValue(ec, pRangeComposition, &var);
pDisplayAttributeProperty->Release();
}
pRangeComposition->Release();
return (hr == S_OK);
}
示例8: isInsertionAllowed
// check if current insertion point is in the range of composition.
// if not in range, insertion is now allowed
bool TextService::isInsertionAllowed(EditSession* session) {
TfEditCookie cookie = session->editCookie();
TF_SELECTION selection;
ULONG selectionNum;
if(isComposing()) {
if(session->context()->GetSelection(cookie, TF_DEFAULT_SELECTION, 1, &selection, &selectionNum) == S_OK) {
ITfRange* compositionRange;
if(composition_->GetRange(&compositionRange) == S_OK) {
bool allowed = false;
// check if current selection is covered by composition range
LONG compareResult1;
LONG compareResult2;
if(selection.range->CompareStart(cookie, compositionRange, TF_ANCHOR_START, &compareResult1) == S_OK
&& selection.range->CompareStart(cookie, compositionRange, TF_ANCHOR_END, &compareResult2) == S_OK) {
if(compareResult1 == -1 && compareResult2 == +1)
allowed = true;
}
compositionRange->Release();
}
if(selection.range)
selection.range->Release();
}
}
return false;
}
示例9: _StartComposition
HRESULT CTextService::_HandleCharacterKey(TfEditCookie ec, ITfContext *pContext, WPARAM wParam)
{
if (!_IsComposing())
_StartComposition(pContext);
//
// create an instance of the candidate list class.
//
if (_pCandidateList == NULL)
_pCandidateList = new CCandidateList(this);
//
// The document manager object is not cached. Get it from pContext.
//
ITfDocumentMgr *pDocumentMgr;
if (pContext->GetDocumentMgr(&pDocumentMgr) == S_OK)
{
//
// get the composition range.
//
ITfRange *pRange;
if (_pComposition->GetRange(&pRange) == S_OK)
{
_pCandidateList->_StartCandidateList(_tfClientId, pDocumentMgr, pContext, ec, pRange);
pRange->Release();
}
pDocumentMgr->Release();
}
if (_IsComposing())
_TerminateComposition(ec, pContext);
return S_OK;
}
示例10: OnEndEdit
STDAPI CTextService::OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
{
BOOL fSelectionChanged;
IEnumTfRanges *pEnumTextChanges;
ITfRange *pRange;
//
// did the selection change?
// The selection change includes the movement of caret as well.
// The caret position is represent as the empty selection range when
// there is no selection.
//
if (pEditRecord->GetSelectionStatus(&fSelectionChanged) == S_OK &&
fSelectionChanged)
{
}
// text modification?
if (pEditRecord->GetTextAndPropertyUpdates(TF_GTP_INCL_TEXT, NULL, 0, &pEnumTextChanges) == S_OK)
{
if (pEnumTextChanges->Next(1, &pRange, NULL) == S_OK)
{
//
// pRange is the updated range.
//
pRange->Release();
}
pEnumTextChanges->Release();
}
return S_OK;
}
示例11: _ClearCompositionDisplayAttributes
void CMarkTextService::_ClearCompositionDisplayAttributes(TfEditCookie ec)
{
ITfRange *pRangeComposition;
ITfContext *pContext;
ITfProperty *pDisplayAttributeProperty;
// we need a range and the context it lives in
if (_pComposition->GetRange(&pRangeComposition) != S_OK)
return;
if (pRangeComposition->GetContext(&pContext) != S_OK)
{
pContext = NULL;
goto Exit;
}
// get our the display attribute property
if (pContext->GetProperty(GUID_PROP_ATTRIBUTE, &pDisplayAttributeProperty) != S_OK)
goto Exit;
// clear the value over the range
pDisplayAttributeProperty->Clear(ec, pRangeComposition);
pDisplayAttributeProperty->Release();
Exit:
pRangeComposition->Release();
SafeRelease(pContext);
}
示例12: OnEndEdit
STDAPI CCaseTextService::OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
{
BOOL fSelectionChanged;
IEnumTfRanges *pEnumTextChanges;
ITfRange *pRange;
// we'll use the endedit notification to update the snoop window
// did the selection change?
if (pEditRecord->GetSelectionStatus(&fSelectionChanged) == S_OK &&
fSelectionChanged)
{
_pSnoopWnd->_UpdateText(ecReadOnly, pContext, NULL);
return S_OK;
}
// text modification?
if (pEditRecord->GetTextAndPropertyUpdates(TF_GTP_INCL_TEXT, NULL, 0, &pEnumTextChanges) == S_OK)
{
if (pEnumTextChanges->Next(1, &pRange, NULL) == S_OK)
{
// arbitrary update the snoop window with the first change
// there may be more than one in the enumerator, but we don't care here
_pSnoopWnd->_UpdateText(ecReadOnly, pContext, pRange);
pRange->Release();
}
pEnumTextChanges->Release();
}
// if we get here, only property values changed
return S_OK;
}
示例13: _HandleCompositionBackspace
HRESULT COVTSF::_HandleCompositionBackspace(TfEditCookie ec, _In_ ITfContext *pContext)
{
ITfRange* pRangeComposition = nullptr;
TF_SELECTION tfSelection;
ULONG fetched = 0;
BOOL isCovered = TRUE;
// Start the new (std::nothrow) compositon if there is no composition.
if (!_IsComposing())
{
return S_OK;
}
// first, test where a keystroke would go in the document if we did an insert
if (FAILED(pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched)) || fetched != 1)
{
return S_FALSE;
}
// is the insertion point covered by a composition?
if (SUCCEEDED(_pComposition->GetRange(&pRangeComposition)))
{
isCovered = _IsRangeCovered(ec, tfSelection.range, pRangeComposition);
pRangeComposition->Release();
if (!isCovered)
{
goto Exit;
}
}
//
// Add virtual key to composition processor engine
//
CCompositionProcessorEngine* pCompositionProcessorEngine = nullptr;
pCompositionProcessorEngine = _pCompositionProcessorEngine;
DWORD_PTR vKeyLen = pCompositionProcessorEngine->GetVirtualKeyLength();
if (vKeyLen)
{
pCompositionProcessorEngine->RemoveVirtualKey(vKeyLen - 1);
if (pCompositionProcessorEngine->GetVirtualKeyLength())
{
_HandleCompositionInputWorker(pCompositionProcessorEngine, ec, pContext);
}
else
{
_HandleCancel(ec, pContext);
}
}
Exit:
tfSelection.range->Release();
return S_OK;
}
示例14: _AddCharAndFinalize
HRESULT COVTSF::_HandleCompositionFinalize(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isCandidateList)
{
HRESULT hr = S_OK;
if (isCandidateList && _pCandidateListUIPresenter)
{
// Finalize selected candidate string from CCandidateListUIPresenter
DWORD_PTR candidateLen = 0;
const WCHAR *pCandidateString = nullptr;
candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString);
CStringRange candidateString;
candidateString.Set(pCandidateString, candidateLen);
if (candidateLen)
{
// Finalize character
hr = _AddCharAndFinalize(ec, pContext, &candidateString);
if (FAILED(hr))
{
return hr;
}
}
}
else
{
// Finalize current text store strings
if (_IsComposing())
{
ULONG fetched = 0;
TF_SELECTION tfSelection;
if (FAILED(pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched)) || fetched != 1)
{
return S_FALSE;
}
ITfRange* pRangeComposition = nullptr;
if (SUCCEEDED(_pComposition->GetRange(&pRangeComposition)))
{
if (_IsRangeCovered(ec, tfSelection.range, pRangeComposition))
{
_EndComposition(pContext);
}
pRangeComposition->Release();
}
tfSelection.range->Release();
}
}
_HandleCancel(ec, pContext);
return S_OK;
}
示例15: _HandleCharacterKey
HRESULT CTextService::_HandleCharacterKey(TfEditCookie ec, ITfContext *pContext, WPARAM wParam)
{
ITfRange *pRangeComposition;
TF_SELECTION tfSelection;
ULONG cFetched;
WCHAR ch;
BOOL fCovered;
// Start the new compositon if there is no composition.
OutputDebugString("test compositing");
if (!_IsComposing())
_StartComposition(pContext);
OutputDebugString("after test compositing");
//
// Assign VK_ value to the char. So the inserted the character is always
// uppercase.
//
ch = (WCHAR)wParam;
// first, test where a keystroke would go in the document if an insert is done
if (pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &cFetched) != S_OK || cFetched != 1)
return S_FALSE;
// is the insertion point covered by a composition?
if (_pComposition->GetRange(&pRangeComposition) == S_OK)
{
fCovered = IsRangeCovered(ec, tfSelection.range, pRangeComposition);
pRangeComposition->Release();
if (!fCovered)
{
goto Exit;
}
}
// insert the text
// use SetText here instead of InsertTextAtSelection because a composition was already started
//Don't allow to the app to adjust the insertion point inside the composition
if (tfSelection.range->SetText(ec, 0, &ch, 1) != S_OK)
goto Exit;
// update the selection, make it an insertion point just past
// the inserted text.
tfSelection.range->Collapse(ec, TF_ANCHOR_END);
pContext->SetSelection(ec, 1, &tfSelection);
//
// set the display attribute to the composition range.
//
_SetCompositionDisplayAttributes(ec, pContext, _gaDisplayAttributeInput);
Exit:
tfSelection.range->Release();
return S_OK;
}