STDAPI CCharHandlerEditSession::DoEditSession(TfEditCookie ec) { CStringRange candidateString; candidateString.Set(_wch, 1); HRESULT setTexthr = E_FAIL; ULONG fetched = 0; TF_SELECTION tfSelection; if ((setTexthr = _pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched)) != S_OK || fetched != 1) return setTexthr; setTexthr = tfSelection.range->SetText(ec, 0, (&candidateString)->Get(), (LONG)(&candidateString)->GetLength()); if (setTexthr == S_OK) { tfSelection.range->Collapse(ec, TF_ANCHOR_END); _pContext->SetSelection(ec, 1, &tfSelection); } tfSelection.range->Release(); HRESULT hResult = S_OK; return hResult; }
HRESULT CSampleIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hr = S_OK; DWORD_PTR candidateLen = 0; const WCHAR* pCandidateString = nullptr; CStringRange candidateString; if (nullptr == _pCandidateListUIPresenter) { goto NoPresenter; } candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString); candidateString.Set(pCandidateString, candidateLen); if (candidateLen) { hr = _AddComposingAndChar(ec, pContext, &candidateString); if (FAILED(hr)) { return hr; } } NoPresenter: _HandleComplete(ec, pContext); return hr; }
HRESULT CDIME::_AsyncReverseConversionNotification(_In_ TfEditCookie ec,_In_ ITfContext *pContext) { ec; debugPrint(L"CDIME::_AsyncReverseConversionNotification() pContext = %x\n", pContext); BSTR bstr; bstr = SysAllocStringLen(_commitString , (UINT) wcslen(_commitString)); if (bstr == nullptr) return E_OUTOFMEMORY; ITfReverseConversionList* reverseConversionList; if(SUCCEEDED(_pITfReverseConversion[Global::imeMode]->DoReverseConversion(bstr, &reverseConversionList)) && reverseConversionList) { UINT hasResult; if(reverseConversionList && SUCCEEDED(reverseConversionList->GetLength(&hasResult)) && hasResult) { BSTR bstrResult; if(SUCCEEDED(reverseConversionList->GetString(0, &bstrResult)) && bstrResult && SysStringLen(bstrResult)) { CStringRange reverseConvNotify; WCHAR* pwch = new (std::nothrow) WCHAR[SysStringLen(bstrResult)+1]; StringCchCopy(pwch, SysStringLen(bstrResult)+1, (WCHAR*) bstrResult); _pUIPresenter->ShowNotifyText(&reverseConvNotify.Set(pwch, wcslen(pwch))); } } reverseConversionList->Release(); return S_OK; } return S_FALSE; }
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; }
HRESULT COVTSF::_HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) { HRESULT hr = S_OK; WCHAR fullWidth = Global::FullWidthCharTable[wch - 0x20]; CStringRange fullWidthString; fullWidthString.Set(&fullWidth, 1); // Finalize character hr = _AddCharAndFinalize(ec, pContext, &fullWidthString); if (FAILED(hr)) { return hr; } _HandleCancel(ec, pContext); return S_OK; }
HRESULT COVTSF::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) { HRESULT hr = S_OK; if (_candidateMode != CANDIDATE_NONE && _pCandidateListUIPresenter) { DWORD_PTR candidateLen = 0; const WCHAR* pCandidateString = nullptr; candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString); CStringRange candidateString; candidateString.Set(pCandidateString, candidateLen); if (candidateLen) { _AddComposingAndChar(ec, pContext, &candidateString); } } // // Get punctuation char from composition processor engine // CCompositionProcessorEngine* pCompositionProcessorEngine = nullptr; pCompositionProcessorEngine = _pCompositionProcessorEngine; WCHAR punctuation = pCompositionProcessorEngine->GetPunctuation(wch); CStringRange punctuationString; punctuationString.Set(&punctuation, 1); // Finalize character hr = _AddCharAndFinalize(ec, pContext, &punctuationString); if (FAILED(hr)) { return hr; } _HandleCancel(ec, pContext); return S_OK; }
HRESULT CSampleIME::_HandlePhraseFinalize(TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hr = S_OK; DWORD phraseLen = 0; const WCHAR* pPhraseString = nullptr; phraseLen = (DWORD)_pCandidateListUIPresenter->_GetSelectedCandidateString(&pPhraseString); CStringRange phraseString; phraseString.Set(pPhraseString, phraseLen); if (phraseLen) { if ((hr = _AddCharAndFinalize(ec, pContext, &phraseString)) != S_OK) { return hr; } } _HandleComplete(ec, pContext); return S_OK; }
HRESULT CDIME::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pContext) { debugPrint(L"CDIME::_HandleCandidateWorker() \n"); HRESULT hr = S_OK; CStringRange commitString, convertedString; CDIMEArray<CCandidateListItem> candidatePhraseList; CStringRange lastChar; CStringRange notify; if (nullptr == _pUIPresenter) { goto Exit; //should not happen } const WCHAR* pCandidateString = nullptr; DWORD_PTR candidateLen = 0; BOOL arrayUsingSPCode =FALSE; if (!_IsComposing()) _StartComposition(pContext); if (Global::imeMode == IME_MODE_ARRAY)// check if the _strokebuffer is array special code { candidateLen = _pCompositionProcessorEngine->CollectWordFromArraySpeicalCode(&pCandidateString); if(candidateLen) arrayUsingSPCode = TRUE; } candidateLen = 0; candidateLen = _pUIPresenter->_GetSelectedCandidateString(&pCandidateString); if (candidateLen == 0) { if(_candidateMode == CANDIDATE_WITH_NEXT_COMPOSITION || _candidateMode == CANDIDATE_PHRASE) { _HandleCancel(ec, pContext); goto Exit; } else { hr = S_FALSE; _HandleCancel(ec, pContext); DoBeep(BEEP_COMPOSITION_ERROR); //beep for no valid mapping found goto Exit; } } if (_pCompositionProcessorEngine->IsArrayShortCode() && candidateLen == 1 && *pCandidateString == 0x2394) // empty position in arry short code table. { hr = S_FALSE; if (Global::imeMode == IME_MODE_PHONETIC) DoBeep(BEEP_WARNING); else { if (CConfig::GetClearOnBeep()) _HandleCancel(ec, pContext); DoBeep(BEEP_COMPOSITION_ERROR); //beep for no valid mapping found } goto Exit; } StringCchCopy(_commitString, 1, L"\0"); StringCchCatN(_commitString, MAX_COMMIT_LENGTH, pCandidateString, candidateLen); commitString.Set(_commitString, candidateLen); //_commitString = commitString; PWCHAR pwch = new (std::nothrow) WCHAR[2]; // pCandidateString will be destroyed after _detelteCanddiateList was called. if(candidateLen > 1) { StringCchCopyN(pwch, 2, pCandidateString + candidateLen -1, 1); }else // cnadidateLen ==1 { StringCchCopyN(pwch, 2, pCandidateString, 1); } lastChar.Set(pwch, 1 ); //-----------------do reverse conversion notify. We should not show notify in UI-less mode, thus cancel reverse conversion notify in UILess Mode if (!_IsUILessMode()) { if (_pITfReverseConversion[Global::imeMode]) { _AsyncReverseConversion(pContext); //asynchronized the reverse conversion with editsession for better perfomance } //-----------------or complete real key code when input with wildcard else if (_isCandidateWithWildcard) { const WCHAR* pCandidateKeyCode = nullptr; DWORD_PTR keyCodeLen = _pUIPresenter->_GetSelectedCandidateKeyCode(&pCandidateKeyCode); StringCchCopy(_commitKeyCode, 1, L"\0"); StringCchCatN(_commitKeyCode, MAX_KEY_LENGTH, pCandidateKeyCode, keyCodeLen); CStringRange commitKeyCode, convertedKeyCode; _pCompositionProcessorEngine->GetReadingString(&convertedKeyCode, NULL, &commitKeyCode.Set(_commitKeyCode, wcslen(_commitKeyCode))); _pUIPresenter->ShowNotifyText(&convertedKeyCode); } } //-----------------do array spcial code notify. We should not show notify in UI-less mode, thus cancel forceSP mode in UILess Mode--- BOOL ArraySPFound = FALSE; if(Global::imeMode == IME_MODE_ARRAY && !_IsUILessMode() && !arrayUsingSPCode && (CConfig::GetArrayForceSP() || CConfig::GetArrayNotifySP())) { CStringRange specialCode; CStringRange notifyText; ArraySPFound = _pCompositionProcessorEngine->GetArraySpeicalCodeFromConvertedText(&commitString, &specialCode); if(specialCode.Get()) _pUIPresenter->ShowNotifyText(&specialCode); } convertedString = commitString; //----------------- do TC to SC covert if required---------------------------------------------------------------------------------- if(CConfig::GetDoHanConvert()) { _pCompositionProcessorEngine->GetSCFromTC(&commitString, &convertedString); } //----------------- commit the selected string ------------------------------------------------------------------------------------ if(Global::imeMode == IME_MODE_ARRAY && !_IsUILessMode() && !arrayUsingSPCode && CConfig::GetArrayForceSP() && ArraySPFound ) { _HandleCancel(ec, pContext); DoBeep(BEEP_WARNING); return hr; } else { hr = _AddComposingAndChar(ec, pContext, &convertedString); if (FAILED(hr)) return hr; // Do not send _endcandidatelist (or handleComplete) here to avoid cand dissapear in win8 metro _HandleComplete(ec,pContext); } //-----------------do accociated phrase (make phrase)-------------------------------------------------------------------------------- if (CConfig::GetMakePhrase()) { _pCompositionProcessorEngine->GetCandidateStringInConverted(lastChar, &candidatePhraseList); // We have a candidate list if candidatePhraseList.Cnt is not 0 // If we are showing reverse conversion, use UIPresenter if (candidatePhraseList.Count()) { CStringRange emptyComposition; if (!_IsComposing()) _StartComposition(pContext); //StartCandidateList require a valid selection from a valid pComposition to determine the location to show the candidate window _AddComposingAndChar(ec, pContext, &emptyComposition.Set(L" ",1)); _pUIPresenter->_ClearCandidateList(); _pUIPresenter->_SetCandidateTextColor(CConfig::GetPhraseColor(), CConfig::GetItemBGColor()); // Text color is green _pUIPresenter->_SetCandidateSelectedTextColor(CConfig::GetSelectedColor(), CConfig::GetSelectedBGColor()); _pUIPresenter->_SetCandidateNumberColor(CConfig::GetNumberColor(), CConfig::GetItemBGColor()); _pUIPresenter->_SetCandidateFillColor(CConfig::GetItemBGColor());//(HBRUSH)(COLOR_WINDOW+1)); // Background color is window _pUIPresenter->_SetCandidateText(&candidatePhraseList, _pCompositionProcessorEngine->GetCandidateListIndexRange(), TRUE, _pCompositionProcessorEngine->GetCandidateWindowWidth()); _pUIPresenter->_SetCandidateSelection(-1, FALSE); // set selected index to -1 if showing phrase candidates _candidateMode = CANDIDATE_PHRASE; _isCandidateWithWildcard = FALSE; } else { //cancel the composition if the phrase lookup return 0 results _HandleCancel(ec,pContext); } } else _DeleteCandidateList(TRUE, pContext); // endCanddiateUI if not doing associated phrase. Exit: return hr; }
void CDIME::showFullHalfShapeNotify(BOOL isFullShape, UINT delayShow) { CStringRange notify; if ((CConfig::GetShowNotifyDesktop() || _IsStoreAppMode()) && _pUIPresenter) _pUIPresenter->ShowNotifyText(¬ify.Set(isFullShape ? L"全形" : L"半形", 2), delayShow, CHN_ENG_NOTIFY_DELAY, NOTIFY_CHN_ENG); }
void CDIME::showChnEngNotify(BOOL isChinese, UINT delayShow) { CStringRange notify; if ((CConfig::GetShowNotifyDesktop() || _IsStoreAppMode()) && _pUIPresenter) _pUIPresenter->ShowNotifyText(¬ify.Set(isChinese ? L"中文" : L"英文", 2), delayShow, CHN_ENG_NOTIFY_DELAY, NOTIFY_CHN_ENG); }
HRESULT CSampleIME::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hrReturn = E_FAIL; DWORD_PTR candidateLen = 0; const WCHAR* pCandidateString = nullptr; BSTR pbstr = nullptr; CStringRange candidateString; CSampleImeArray<CCandidateListItem> candidatePhraseList; if (nullptr == _pCandidateListUIPresenter) { hrReturn = S_OK; goto Exit; } candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString); if (0 == candidateLen) { hrReturn = S_FALSE; goto Exit; } candidateString.Set(pCandidateString, candidateLen); BOOL fMakePhraseFromText = _pCompositionProcessorEngine->IsMakePhraseFromText(); if (fMakePhraseFromText) { _pCompositionProcessorEngine->GetCandidateStringInConverted(candidateString, &candidatePhraseList); LCID locale = _pCompositionProcessorEngine->GetLocale(); _pCandidateListUIPresenter->RemoveSpecificCandidateFromList(locale, candidatePhraseList, candidateString); } // We have a candidate list if candidatePhraseList.Cnt is not 0 // If we are showing reverse conversion, use CCandidateListUIPresenter CANDIDATE_MODE tempCandMode = CANDIDATE_NONE; CCandidateListUIPresenter* pTempCandListUIPresenter = nullptr; if (candidatePhraseList.Count()) { tempCandMode = CANDIDATE_WITH_NEXT_COMPOSITION; pTempCandListUIPresenter = new (std::nothrow) CCandidateListUIPresenter(this, Global::AtomCandidateWindow, CATEGORY_CANDIDATE, _pCompositionProcessorEngine->GetCandidateListIndexRange(), FALSE); if (nullptr == pTempCandListUIPresenter) { hrReturn = E_OUTOFMEMORY; goto Exit; } } // call _Start*Line for CCandidateListUIPresenter or CReadingLine // we don't cache the document manager object so get it from pContext. ITfDocumentMgr* pDocumentMgr = nullptr; HRESULT hrStartCandidateList = E_FAIL; if (pContext->GetDocumentMgr(&pDocumentMgr) == S_OK) { ITfRange* pRange = nullptr; if (_pComposition->GetRange(&pRange) == S_OK) { if (pTempCandListUIPresenter) { hrStartCandidateList = pTempCandListUIPresenter->_StartCandidateList(_tfClientId, pDocumentMgr, pContext, ec, pRange, _pCompositionProcessorEngine->GetCandidateWindowWidth()); } pRange->Release(); } pDocumentMgr->Release(); } // set up candidate list if it is being shown if (SUCCEEDED(hrStartCandidateList)) { pTempCandListUIPresenter->_SetTextColor(RGB(0, 0x80, 0), GetSysColor(COLOR_WINDOW)); // Text color is green pTempCandListUIPresenter->_SetFillColor((HBRUSH)(COLOR_WINDOW+1)); // Background color is window pTempCandListUIPresenter->_SetText(&candidatePhraseList, FALSE); // Add composing character hrReturn = _AddComposingAndChar(ec, pContext, &candidateString); // close candidate list if (_pCandidateListUIPresenter) { _pCandidateListUIPresenter->_EndCandidateList(); delete _pCandidateListUIPresenter; _pCandidateListUIPresenter = nullptr; _candidateMode = CANDIDATE_NONE; _isCandidateWithWildcard = FALSE; } if (hrReturn == S_OK) { // copy temp candidate _pCandidateListUIPresenter = pTempCandListUIPresenter; _candidateMode = tempCandMode; _isCandidateWithWildcard = FALSE; } } else { hrReturn = _HandleCandidateFinalize(ec, pContext); } if (pbstr) { SysFreeString(pbstr); } Exit: return hrReturn; }
bool CPreprocessor::Preprocess(_IN CString& rText) { static CString Define(SCFTEXT("#define")); m_Text = rText; CStringRange DefinePotential = CStringRange(m_Text, 0, 7); CStringRange DefineName = CStringRange(m_Text, 0); CStringRange DefineValue = CStringRange(m_Text, 0); for (UINT i = 0; i < m_Text.Length(); i++) { DefinePotential.ChangeStart(i); if (DefinePotential == Define) { DefineName.ChangeStart(DefinePotential.Start() + DefinePotential.Length() + 1); DefineName.ChangeLength(m_Text.Length() - DefineName.Start()); if (ParseDefineName(DefineName)) { DefineValue.ChangeStart(DefineName.Start() + DefineName.Length() + 1); DefineValue.ChangeLength(m_Text.Length() - DefineValue.Start()); if (ParseDefineValue(DefineValue)) { m_Defines.AtPut(DefineName, DefineValue); } } } } return true; }