HRESULT CCandidateListUIPresenter::MakeCandidateWindow(_In_ ITfContext *pContextDocument, _In_ UINT wndWidth) { HRESULT hr = S_OK; if (nullptr != _pCandidateWnd) { return hr; } _pCandidateWnd = new (std::nothrow) CCandidateWindow(_CandWndCallback, this, _pIndexRange, _pTextService->_IsStoreAppMode()); if (_pCandidateWnd == nullptr) { hr = E_OUTOFMEMORY; goto Exit; } HWND parentWndHandle = nullptr; ITfContextView* pView = nullptr; if (SUCCEEDED(pContextDocument->GetActiveView(&pView))) { pView->GetWnd(&parentWndHandle); } if (!_pCandidateWnd->_Create(_atom, wndWidth, parentWndHandle)) { hr = E_OUTOFMEMORY; goto Exit; } Exit: return hr; }
BOOL CInputModeWindow::_Create(CTextService *pTextService, ITfContext *pContext, BOOL bCandidateWindow, HWND hWnd) { POINT pt = {0, 0}; if(pContext != nullptr) { _pContext = pContext; _pContext->AddRef(); if(_AdviseTextLayoutSink() != S_OK) { return FALSE; } } if(!bCandidateWindow && _pContext == nullptr) { return FALSE; } _pTextService = pTextService; _pTextService->AddRef(); _bCandidateWindow = bCandidateWindow; if(_bCandidateWindow) { _hwndParent = hWnd; } else { ITfContextView *pContextView; if(_pContext->GetActiveView(&pContextView) == S_OK) { if(FAILED(pContextView->GetWnd(&_hwndParent)) || _hwndParent == nullptr) { _hwndParent = GetFocus(); } SafeRelease(&pContextView); } } _hwnd = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE, InputModeWindowClass, L"", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _hwndParent, nullptr, g_hInst, this); if(_hwnd == nullptr) { return FALSE; } HDC hdc = GetDC(nullptr); _size = MulDiv(16, GetDeviceCaps(hdc, LOGPIXELSY), 96); ReleaseDC(nullptr, hdc); if(_bCandidateWindow) { RECT r; GetClientRect(_hwndParent, &r); pt.x = r.left; pt.y = r.bottom; ClientToScreen(_hwndParent, &pt); } SetWindowPos(_hwnd, HWND_TOPMOST, pt.x, pt.y + IM_MERGIN_Y, _size + IM_MERGIN_X * 2, _size + IM_MERGIN_Y * 2, SWP_NOACTIVATE); return TRUE; }
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 *pContext, TfEditCookie ec, ITfRange *pRange, BOOL reg, BOOL comp) { HRESULT hr = E_FAIL; TfEditCookie ecTextStore; ITfContextView *pContextView; HWND hwnd = NULL; _EndCandidateList(); if(pDocumentMgr->CreateContext(tfClientId, 0, NULL, &_pContextCandidateWindow, &ecTextStore) != S_OK) { return E_FAIL; } if(pDocumentMgr->Push(_pContextCandidateWindow) != S_OK) { goto exit; } _pDocumentMgr = pDocumentMgr; _pDocumentMgr->AddRef(); _pContextDocument = pContext; _pContextDocument->AddRef(); _pRangeComposition = pRange; _pRangeComposition->AddRef(); _ec = ec; _comp = comp; if(_AdviseContextKeyEventSink() != S_OK) { goto exit; } if(_AdviseTextLayoutSink() != S_OK) { goto exit; } try { _pCandidateWindow = new CCandidateWindow(_pTextService, this); if(pContext->GetActiveView(&pContextView) == S_OK) { if(!_pTextService->_UILessMode && _pCandidateWindow->_CanShowUIElement()) { if(FAILED(pContextView->GetWnd(&hwnd)) || hwnd == NULL) { hwnd = GetFocus(); } } SafeRelease(&pContextView); } if(!_pCandidateWindow->_Create(hwnd, NULL, 0, 0, reg, comp)) { goto exit; } HRESULT hrSession = E_FAIL; try { CCandidateWindowEditSession *pEditSession = new CCandidateWindowEditSession(_pTextService, _pContextDocument, _pRangeComposition, _pCandidateWindow); // Asynchronous pContext->RequestEditSession(ec, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession); SafeRelease(&pEditSession); } catch(...) { } if(hrSession != TF_S_ASYNC) { hr = E_FAIL; goto exit; } hr = S_OK; } catch(...) { } exit: if(hr != S_OK) { _EndCandidateList(); } return hr; }