本文整理汇总了C++中ITfContext类的典型用法代码示例。如果您正苦于以下问题:C++ ITfContext类的具体用法?C++ ITfContext怎么用?C++ ITfContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITfContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setCompositionString
void TextService::setCompositionString(EditSession* session, const wchar_t* str, int len) {
ITfContext* context = session->context();
if(context) {
TfEditCookie editCookie = session->editCookie();
TF_SELECTION selection;
ULONG selectionNum;
// get current selection/insertion point
if(context->GetSelection(editCookie, TF_DEFAULT_SELECTION, 1, &selection, &selectionNum) == S_OK) {
ComPtr<ITfRange> compositionRange;
if(composition_->GetRange(&compositionRange) == S_OK) {
bool selPosInComposition = true;
// if current insertion point is not covered by composition, we cannot insert text here.
if(selPosInComposition) {
// replace context of composion area with the new string.
compositionRange->SetText(editCookie, TF_ST_CORRECTION, str, len);
// move the insertion point to end of the composition string
selection.range->Collapse(editCookie, TF_ANCHOR_END);
context->SetSelection(editCookie, 1, &selection);
}
// set display attribute to the composition range
ComPtr<ITfProperty> dispAttrProp;
if(context->GetProperty(GUID_PROP_ATTRIBUTE, &dispAttrProp) == S_OK) {
VARIANT val;
val.vt = VT_I4;
val.lVal = module_->inputAttrib()->atom();
dispAttrProp->SetValue(editCookie, compositionRange, &val);
}
}
selection.range->Release();
}
}
}
示例2: 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;
}
示例3: _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);
}
示例4: _Menu_OnComposition
/* static */
void CMarkTextService::_Menu_OnComposition(CMarkTextService *_this)
{
ITfDocumentMgr *pFocusDoc;
ITfContext *pContext;
CCompositionEditSession *pCompositionEditSession;
HRESULT hr;
// get the focus document
if (_this->_pThreadMgr->GetFocus(&pFocusDoc) != S_OK)
return;
// we want the topmost context, since the main doc context could be
// superceded by a modal tip context
if (pFocusDoc->GetTop(&pContext) != S_OK)
{
pContext = NULL;
goto Exit;
}
if (pCompositionEditSession = new CCompositionEditSession(pContext, _this))
{
// we need a document write lock
// the CCompositionEditSession will do all the work when the
// CCompositionEditSession::DoEditSession method is called by the context
pContext->RequestEditSession(_this->_tfClientId, pCompositionEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);
pCompositionEditSession->Release();
}
Exit:
SafeRelease(pContext);
pFocusDoc->Release();
}
示例5: debugPrint
STDAPI CDIME::OnCompositionTerminated(TfEditCookie ecWrite, _In_ ITfComposition *pComposition)
{
debugPrint(L"CDIME::OnCompositionTerminated()");
HRESULT hr = S_OK;
ITfContext* pContext = _pContext;
// Clear dummy composition
_RemoveDummyCompositionForComposing(ecWrite, pComposition);
// Clear display attribute and end composition, _EndComposition will release composition for us
if (pContext)
{
pContext->AddRef();
}
_EndComposition(pContext);
_DeleteCandidateList(TRUE, pContext);
if (pContext)
{
pContext->Release();
pContext = nullptr;
}
return hr;
}
示例6: InsertHello
void CTextService::InsertHello()
{
ITfDocumentMgr *pDocMgrFocus;
ITfContext *pContext;
CInsertHelloEditSession *pInsertHelloEditSession;
HRESULT hr;
// get the focus document
if (_pThreadMgr->GetFocus(&pDocMgrFocus) != S_OK)
return;
// we want the topmost context, since the main doc context could be
// superceded by a modal tip context
if (pDocMgrFocus->GetTop(&pContext) != S_OK)
{
pContext = NULL;
goto Exit;
}
if (pInsertHelloEditSession = new CInsertHelloEditSession(pContext))
{
// we need a document write lock to insert text
// the CInsertHelloEditSession will do all the work when the
// CInsertHelloEditSession::DoEditSession method is called by the context
pContext->RequestEditSession(_tfClientId, pInsertHelloEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);
pInsertHelloEditSession->Release();
}
Exit:
if (pContext)
pContext->Release();
pDocMgrFocus->Release();
}
示例7: _InitTextEditSink
STDAPI CExtentMonitorTextService::OnSetFocus(ITfDocumentMgr *pDocMgrFocus, ITfDocumentMgr *pDocMgrPrevFocus)
{
//
// Whenever focus is changed, we initialize the TextEditSink.
//
ITfDocumentMgr *pDocMgrTarget = NULL;
if (GetNonTransitoryDim(pDocMgrFocus, &pDocMgrTarget) != S_OK)
{
if (pDocMgrFocus)
{
pDocMgrTarget = pDocMgrFocus;
pDocMgrTarget->AddRef();
}
}
_InitTextEditSink(pDocMgrTarget);
if (pDocMgrTarget)
{
ITfContext *pContext;
if (SUCCEEDED(pDocMgrTarget->GetBase(&pContext)))
{
DumpExtent(pContext, DE_EVENTID_ONSETFOCUS);
pContext->Release();
}
pDocMgrTarget->Release();
}
return S_OK;
}
示例8: _CandidateChangeNotification
HRESULT CCandidateListUIPresenter::_CandidateChangeNotification(_In_ enum CANDWND_ACTION action)
{
HRESULT hr = E_FAIL;
TfClientId tfClientId = _pTextService->_GetClientId();
ITfThreadMgr* pThreadMgr = nullptr;
ITfDocumentMgr* pDocumentMgr = nullptr;
ITfContext* pContext = nullptr;
_KEYSTROKE_STATE KeyState;
KeyState.Category = _Category;
KeyState.Function = FUNCTION_FINALIZE_CANDIDATELIST;
if (CAND_ITEM_SELECT != action)
{
goto Exit;
}
pThreadMgr = _pTextService->_GetThreadMgr();
if (nullptr == pThreadMgr)
{
goto Exit;
}
hr = pThreadMgr->GetFocus(&pDocumentMgr);
if (FAILED(hr))
{
goto Exit;
}
hr = pDocumentMgr->GetTop(&pContext);
if (FAILED(hr))
{
pDocumentMgr->Release();
goto Exit;
}
CKeyHandlerEditSession *pEditSession = new (std::nothrow) CKeyHandlerEditSession(_pTextService, pContext, 0, 0, KeyState);
if (nullptr != pEditSession)
{
HRESULT hrSession = S_OK;
hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hrSession);
if (hrSession == TF_E_SYNCHRONOUS || hrSession == TS_E_READONLY)
{
hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession);
}
pEditSession->Release();
}
pContext->Release();
pDocumentMgr->Release();
Exit:
return hr;
}
示例9: DumpExtentFocusContext
void CExtentMonitorTextService::DumpExtentFocusContext(UINT nEventId)
{
ITfDocumentMgr *pDocMgrFocus;
if ((_pThreadMgr->GetFocus(&pDocMgrFocus) == S_OK) &&
(pDocMgrFocus != NULL))
{
ITfContext *pContext;
if (SUCCEEDED(pDocMgrFocus->GetBase(&pContext)))
{
DumpExtent(pContext, nEventId);
pContext->Release();
}
pDocMgrFocus->Release();
}
}
示例10: _UpdateLanguageBarOnSetFocus
void CIME::_UpdateLanguageBarOnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus)
{
BOOL needDisableButtons = FALSE;
if (!pDocMgrFocus)
{
needDisableButtons = TRUE;
}
else
{
IEnumTfContexts* pEnumContext = nullptr;
if (FAILED(pDocMgrFocus->EnumContexts(&pEnumContext)) || !pEnumContext)
{
needDisableButtons = TRUE;
}
else
{
ULONG fetched = 0;
ITfContext* pContext = nullptr;
if (FAILED(pEnumContext->Next(1, &pContext, &fetched)) || fetched != 1)
{
needDisableButtons = TRUE;
}
if (!pContext)
{
// context is not associated
needDisableButtons = TRUE;
}
else
{
pContext->Release();
}
}
if (pEnumContext)
{
pEnumContext->Release();
}
}
CCompositionProcessorEngine* pCompositionProcessorEngine = nullptr;
pCompositionProcessorEngine = _pCompositionProcessorEngine;
pCompositionProcessorEngine->SetLanguageBarStatus(TF_LBI_STATUS_DISABLED, needDisableButtons);
}
示例11: debugPrint
BOOL CDIME::_UpdateLanguageBarOnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus)
{
debugPrint(L"_UpdateLanguageBarOnSetFocus()");
BOOL needDisableButtons = FALSE;
if (!pDocMgrFocus)
{
needDisableButtons = TRUE;
}
else
{
IEnumTfContexts* pEnumContext = nullptr;
if (FAILED(pDocMgrFocus->EnumContexts(&pEnumContext)) || !pEnumContext)
{
needDisableButtons = TRUE;
}
else
{
ULONG fetched = 0;
ITfContext* pContext = nullptr;
if (FAILED(pEnumContext->Next(1, &pContext, &fetched)) || fetched != 1)
{
needDisableButtons = TRUE;
}
if (pContext == nullptr)
{
// context is not associated
needDisableButtons = TRUE;
}
else
{
pContext->Release();
}
}
if (pEnumContext)
{
pEnumContext->Release();
}
}
SetLanguageBarStatus(TF_LBI_STATUS_DISABLED, needDisableButtons);
return needDisableButtons;
}
示例12: _InitTextEditSink
STDAPI CSampleIME::OnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus, _In_ ITfDocumentMgr *pDocMgrPrevFocus)
{
pDocMgrPrevFocus;
_InitTextEditSink(pDocMgrFocus);
_UpdateLanguageBarOnSetFocus(pDocMgrFocus);
//
// We have to hide/unhide candidate list depending on whether they are
// associated with pDocMgrFocus.
//
if (_pCandidateListUIPresenter)
{
ITfDocumentMgr* pCandidateListDocumentMgr = nullptr;
ITfContext* pTfContext = _pCandidateListUIPresenter->_GetContextDocument();
if ((nullptr != pTfContext) && SUCCEEDED(pTfContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
{
if (pCandidateListDocumentMgr != pDocMgrFocus)
{
_pCandidateListUIPresenter->OnKillThreadFocus();
}
else
{
_pCandidateListUIPresenter->OnSetThreadFocus();
}
pCandidateListDocumentMgr->Release();
}
}
if (_pDocMgrLastFocused)
{
_pDocMgrLastFocused->Release();
_pDocMgrLastFocused = nullptr;
}
_pDocMgrLastFocused = pDocMgrFocus;
if (_pDocMgrLastFocused)
{
_pDocMgrLastFocused->AddRef();
}
return S_OK;
}
示例13: currentContext
ComPtr<ITfCompartment> TextService::contextCompartment(const GUID& key, ITfContext* context) {
ITfContext* curContext = NULL;
if(!context) {
curContext = currentContext();
context = curContext;
}
if(context) {
ComQIPtr<ITfCompartmentMgr> compartmentMgr = context;
if(compartmentMgr) {
ComPtr<ITfCompartment> compartment;
compartmentMgr->GetCompartment(key, &compartment);
return compartment;
}
}
if(curContext)
curContext->Release();
return NULL;
}
示例14: currentContext
// called when the keyboard is opened or closed
// virtual
void TextService::onKeyboardStatusChanged(bool opened) {
Ime::TextService::onKeyboardStatusChanged(opened);
if(client_)
client_->onKeyboardStatusChanged(opened);
if(opened) { // keyboard is opened
}
else { // keyboard is closed
if(isComposing()) {
// end current composition if needed
ITfContext* context = currentContext();
if(context) {
endComposition(context);
context->Release();
}
}
if(showingCandidates()) // disable candidate window if it's opened
hideCandidates();
hideMessage(); // hide message window, if there's any
}
}
示例15: OnSetThreadFocus
STDAPI CIME::OnSetThreadFocus()
{
if (_pCandidateListUIPresenter)
{
ITfDocumentMgr* pCandidateListDocumentMgr = nullptr;
ITfContext* pTfContext = _pCandidateListUIPresenter->_GetContextDocument();
if ((nullptr != pTfContext) && SUCCEEDED(pTfContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
{
if (pCandidateListDocumentMgr == _pDocMgrLastFocused)
{
_pCandidateListUIPresenter->OnSetThreadFocus();
}
pCandidateListDocumentMgr->Release();
}
}
return S_OK;
}