HRESULT CDIME::_AddComposingAndChar(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString) { debugPrint(L"CDIME::_AddComposingAndChar() reading string = %s", pstrAddString->Get()); HRESULT hr = S_OK; ULONG fetched = 0; TF_SELECTION tfSelection; if (pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched) != S_OK || fetched == 0) return S_FALSE; // // make range start to selection // ITfRange* pAheadSelection = nullptr; hr = pContext->GetStart(ec, &pAheadSelection); if (SUCCEEDED(hr) && pAheadSelection) { debugPrint(L"CDIME::_AddComposingAndChar() SUCCEEDED( pContext->GetStart( &pAheadSelection))"); hr = pAheadSelection->ShiftEndToRange(ec, tfSelection.range, TF_ANCHOR_START); if (SUCCEEDED(hr)) { debugPrint(L"CDIME::_AddComposingAndChar() SUCCEEDED( pAheadSelection->ShiftEndToRange())"); ITfRange* pRange = nullptr; BOOL exist_composing = _FindComposingRange(ec, pContext, pAheadSelection, &pRange); if (FAILED(_SetInputString(ec, pContext, pRange, pstrAddString, exist_composing))) debugPrint(L"CDIME::_AddComposingAndChar() _SetInputString() failed."); if (pRange) pRange->Release(); lastReadingString = *pstrAddString; } } tfSelection.range->Release(); if (pAheadSelection) { pAheadSelection->Release(); } return S_OK; }
HRESULT CSampleIME::_UpdateCandidateString(TfEditCookie ec, _In_ ITfContext *pContext, _In_ const std::wstring &pstrAddString) { HRESULT hr = S_OK; ULONG fetched = 0; TF_SELECTION tfSelection; if (pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched) != S_OK || fetched == 0) return S_FALSE; // // make range start to selection // ITfRange* pAheadSelection = nullptr; hr = pContext->GetStart(ec, &pAheadSelection); if (SUCCEEDED(hr)) { hr = pAheadSelection->ShiftEndToRange(ec, tfSelection.range, TF_ANCHOR_START); if (SUCCEEDED(hr)) { ITfRange* pRange = nullptr; /* existing_composing = true if text range is has a composition pRange = the composition range */ BOOL exist_composing = _FindComposingRange(ec, pContext, pAheadSelection, &pRange); // Well... since we want an initial 'u' // TODO: This is obviously inefficient allocation of memory for another string _SetInputString(ec, pContext, pRange, pstrAddString, exist_composing); if (pRange) { pRange->Release(); } } } tfSelection.range->Release(); if (pAheadSelection) { pAheadSelection->Release(); } return S_OK; }