STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec){ RECT rc; BOOL fClipped; if (SUCCEEDED(_pContextView->GetTextExt(ec, _pRangeComposition, &rc, &fClipped))) _pCandidateWindow->_Move(rc.left, rc.bottom); return S_OK; }
// ITfEditSession STDMETHODIMP DoEditSession(TfEditCookie ec) { ITfContextView *pContextView; if(_pContext->GetActiveView(&pContextView) == S_OK) { RECT rc; BOOL fClipped; if(pContextView->GetTextExt(ec, _pRangeComposition, &rc, &fClipped) == S_OK) { _pCandidateWindow->_Move(&rc); } SafeRelease(&pContextView); } _pCandidateWindow->_BeginUIElement(); _pCandidateWindow->_Redraw(); return S_OK; }
STDAPI CTextService::OnEndEdit(ITfContext *pic, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord) { if(_IsComposing() && pic != nullptr) { ITfRange *pRange = nullptr; if(SUCCEEDED(_pComposition->GetRange(&pRange)) && (pRange != nullptr)) { // clear when auto completion BOOL fEmpty = FALSE; if(SUCCEEDED(pRange->IsEmpty(ecReadOnly, &fEmpty)) && fEmpty) { if(!roman.empty() || !kana.empty()) { _ResetStatus(); _EndComposition(pic); } } // reposition candidate window if(_pCandidateList != nullptr) { ITfContextView *pContextView = nullptr; if(SUCCEEDED(pic->GetActiveView(&pContextView)) && (pContextView != nullptr)) { RECT rc = {}; BOOL fClipped; if(SUCCEEDED(pContextView->GetTextExt(ecReadOnly, pRange, &rc, &fClipped))) { _pCandidateList->_Move(&rc, ecReadOnly, pic); } SafeRelease(&pContextView); } } SafeRelease(&pRange); } } return S_OK; }
STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec) { ITfInsertAtSelection *pInsertAtSelection = NULL; ITfRange *pRangeComposition = NULL; RECT rc; BOOL fClipped; 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; if ((_pContextView->GetTextExt(ec, pRangeComposition, &rc, &fClipped)) == S_OK) _pTextService->_SetCompositionPosition(rc); Exit: if (pRangeComposition != NULL) pRangeComposition->Release(); if (pInsertAtSelection != NULL) pInsertAtSelection->Release(); return S_OK; }
void CExtentMonitorTextService::_DumpExtent(TfEditCookie ec, ITfContext *pContext, UINT nEventId) { if (!_pMemStream) return; ClearStream(_pMemStream); switch (nEventId) { case DE_EVENTID_ACTIVATE: AddStringToStream(_pMemStream, L"Event: Activate\r\n"); break; case DE_EVENTID_ONSETFOCUS: AddStringToStream(_pMemStream, L"Event: OnSetFocus\r\n"); break; case DE_EVENTID_ONENDEDIT: AddStringToStream(_pMemStream, L"Event: OnEndEdit\r\n"); break; case DE_EVENTID_ONLAYOUTCHANGE: AddStringToStream(_pMemStream, L"Event: OnLayoutChange\r\n"); break; case DE_EVENTID_FROMLANGUAGEBAR: AddStringToStream(_pMemStream, L"Event: From LanguageBar\r\n"); break; default: AddStringToStream(_pMemStream, L"Event: Unknoen\r\n"); break; } WCHAR sz[512]; ITfContextView *pView = NULL; TF_SELECTION sel; memset(&_rcStartPos , 0, sizeof(RECT)); memset(&_rcEndPos , 0, sizeof(RECT)); memset(&_rcSelection , 0, sizeof(RECT)); memset(&_rcView , 0, sizeof(RECT)); if (SUCCEEDED(pContext->GetActiveView(&pView))) { ITfRange *pRange; RECT rc; BOOL fClipped; HWND hwnd; AddStringToStream(_pMemStream, L"Wnd Handle - "); if (SUCCEEDED(pView->GetWnd(&hwnd))) { WCHAR szWndClass[32]; if (IsWindow(hwnd)) { GetClassNameW(hwnd, szWndClass, ARRAYSIZE(szWndClass)); StringCchPrintf(sz, ARRAYSIZE(sz), L"%08x %s\r\n", (DWORD)(ULONG_PTR)hwnd, szWndClass); AddStringToStream(_pMemStream, sz); } else { AddStringToStream(_pMemStream, L"null window handle\r\n"); } } AddStringToStream(_pMemStream, L"Screen Ext\r\n"); if (SUCCEEDED(pView->GetScreenExt(&rc))) { StringCchPrintf(sz, ARRAYSIZE(sz), L" (%d, %d, %d, %d) - (%d, %d)\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top); AddStringToStream(_pMemStream, sz); _rcView = rc; } AddStringToStream(_pMemStream, L"Start Pos\r\n"); if (SUCCEEDED(pContext->GetStart(ec, &pRange))) { if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped))) { StringCchPrintf(sz, ARRAYSIZE(sz), L" (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L""); AddStringToStream(_pMemStream, sz); _rcStartPos = rc; } pRange->Release(); } AddStringToStream(_pMemStream, L"End Pos\r\n"); if (SUCCEEDED(pContext->GetEnd(ec, &pRange))) { if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped))) { StringCchPrintf(sz, ARRAYSIZE(sz), L" (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L""); AddStringToStream(_pMemStream, sz); _rcEndPos = rc; } pRange->Release(); } AddStringToStream(_pMemStream, L"Selection Pos\r\n"); ULONG cFetched; if (SUCCEEDED(pContext->GetSelection(ec, 0, 1, &sel, &cFetched))) { if (sel.range) { if (SUCCEEDED(pView->GetTextExt(ec, sel.range, &rc, &fClipped))) { StringCchPrintf(sz, ARRAYSIZE(sz), L" (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L""); AddStringToStream(_pMemStream, sz); _rcSelection = rc; } AddStringToStream(_pMemStream, L" "); _DumpRange(ec, sel.range); AddStringToStream(_pMemStream, L"\r\n"); sel.range->Release(); } } AddStringToStream(_pMemStream, L"Char Pos\r\n"); if (SUCCEEDED(pContext->GetStart(ec, &pRange))) { LONG cch; memset(&_rcRanges[0] , 0, sizeof(RECT) * ARRAYSIZE(_rcRanges)); if (SUCCEEDED(pRange->ShiftEnd(ec, 1, &cch, NULL)) && cch) { for (int i = 0; i < ARRAYSIZE(_rcRanges); i++) { if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped))) { StringCchPrintf(sz, ARRAYSIZE(sz), L" (%d, %d, %d, %d) - (%d, %d) %s", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L""); AddStringToStream(_pMemStream, sz); AddStringToStream(_pMemStream, L" "); ITfRange *pRangeTmp; if (SUCCEEDED(pRange->Clone(&pRangeTmp))) { _DumpRange(ec, pRangeTmp); pRangeTmp->Release(); } AddStringToStream(_pMemStream, L"\r\n"); OffsetRect(&rc, 0 - _rcView.left, 0 - _rcView.top); _rcRanges[i] = rc; } if (FAILED(pRange->ShiftEnd(ec, 1, &cch, NULL)) || !cch) break; if (FAILED(pRange->ShiftStart(ec, 1, &cch, NULL)) || !cch) break; } } pRange->Release(); } pView->Release(); } _EnsurePopupWindow(); if (IsShownExtentVisualWindows()) _UpdateExtentVisualWindows(); if (IsShownRangeExtentViewer()) _UpdateRangeExtentViewer(); return; }
HRESULT CCandidateList::_StartCandidateList(TfClientId tfClientId, ITfDocumentMgr *pDocumentMgr, ITfContext *pContextDocument, TfEditCookie ec, ITfRange *pRangeComposition){ TfEditCookie ecTmp; HRESULT hr = E_FAIL; BOOL fClipped; // clear the previous candidate list. // only one candidate window is supported. _EndCandidateList(); // create a new context on the document manager object for // the candidate ui. if (FAILED(pDocumentMgr->CreateContext(tfClientId, 0, NULL, &_pContextCandidateWindow, &ecTmp))) return E_FAIL; // push the new context. if (FAILED(pDocumentMgr->Push(_pContextCandidateWindow))) goto Exit; _pDocumentMgr = pDocumentMgr; _pDocumentMgr->AddRef(); _pContextDocument = pContextDocument; _pContextDocument->AddRef(); _pRangeComposition = pRangeComposition; _pRangeComposition->AddRef(); // advise ITfContextKeyEventSink to the new context. if (FAILED(_AdviseContextKeyEventSink())) goto Exit; // advise ITfTextLayoutSink to the document context. if (FAILED(_AdviseTextLayoutSink())) goto Exit; //ÉêÇ뻺³åÇø int cchMax = 10; wchar_t *pchText = new wchar_t[cchMax]; //»ñµÃÊäÈë×Ö·û ULONG pcch = 0; if(_pRangeComposition->GetText(ec, NULL, pchText, cchMax, &pcch) == S_OK){ pchText[pcch] = 0; } //²éѯºòÑ¡×Ö if(!CandidateTree->ForwardTo(pchText[pcch - 1])){ _pRangeComposition->Collapse(ec, TF_ANCHOR_END); _pTextService->_TerminateComposition(ec, _pContextDocument); }else{ CCandidateTree::Node *node = CandidateTree->GetCurrent(); if(node != NULL){ //ÏÔʾ/ÊäÈëºòÑ¡×Ö if(node->IsEnd()){ _InputDefaultCandidate(ec); // create an instance of CCandidateWindow class. }else if(_pCandidateWindow = new CCandidateWindow()){ RECT rc; ITfContextView *pContextView; // get an active view of the document context. if (FAILED(pContextDocument->GetActiveView(&pContextView))) goto Exit; // get text extent for the range of the composition. if (FAILED(pContextView->GetTextExt(ec, pRangeComposition, &rc, &fClipped))) goto Exit; pContextView->Release(); // create the dummy candidate window if (!_pCandidateWindow->_Create()) goto Exit; _pCandidateWindow->_Move(rc.left, rc.bottom); _pCandidateWindow->_Show(); hr = S_OK; } } } //ÊÍ·Å»º³åÇø delete[] pchText; Exit: if (FAILED(hr)) { _EndCandidateList(); } return hr; }