コード例 #1
0
HRESULT CDIME::_ProbeCompositionRangeNotification(_In_ TfEditCookie ec, _In_ ITfContext *pContext)
{
	debugPrint(L"CDIME::_ProbeCompositionRangeNotification(), \n");


	HRESULT hr = S_OK;
	if(!_IsComposing())
		_StartComposition(pContext);
	
	hr = E_FAIL;
    ULONG fetched = 0;
    TF_SELECTION tfSelection;

    if ( pContext == nullptr || (hr = pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &fetched)) != S_OK || fetched != 1 ||tfSelection.range==nullptr)
	{
		_TerminateComposition(ec,pContext);
        return hr;
	}
	tfSelection.range->Release();
   
	
	ITfRange *pRange;
	ITfContextView* pContextView;
	ITfDocumentMgr* pDocumgr;
	if (_pComposition&&SUCCEEDED(_pComposition->GetRange(&pRange)) && pRange)
	{
		if(pContext && SUCCEEDED(pContext->GetActiveView(&pContextView)) && pContextView)
		{
			if(pContext && SUCCEEDED( pContext->GetDocumentMgr(&pDocumgr)) && pDocumgr && _pThreadMgr &&_pUIPresenter)
			{
				ITfDocumentMgr* pFocusDocuMgr;
				_pThreadMgr->GetFocus(&pFocusDocuMgr);
				if(pFocusDocuMgr == pDocumgr)
				{
					_pUIPresenter->_StartLayout(pContext, ec, pRange);
					_pUIPresenter->_MoveUIWindowsToTextExt();
				}
				else 
					_pUIPresenter->ClearNotify();

				pDocumgr->Release();
			}
		pContextView->Release();
		}
		pRange->Release();
	}


    
	_TerminateComposition(ec,pContext);
	return hr;
}
コード例 #2
0
ファイル: Composition.cpp プロジェクト: wyrover/weasel
/* Composition Window Handling */
BOOL WeaselTSF::_UpdateCompositionWindow(ITfContext *pContext)
{
	ITfContextView *pContextView = NULL;
	if (pContext->GetActiveView(&pContextView) != S_OK)
		return FALSE;
	CGetTextExtentEditSession *pEditSession;
	if ((pEditSession = new CGetTextExtentEditSession(this, pContext, pContextView, _pComposition)) != NULL)
	{
		HRESULT hr;
		pContext->RequestEditSession(_tfClientId, pEditSession, TF_ES_ASYNCDONTCARE | TF_ES_READ, &hr);
		pEditSession->Release();
		pContextView->Release();
		return TRUE;
	}
	pContextView->Release();
	return FALSE;
}
コード例 #3
0
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;
}
コード例 #4
0
	// 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;
	}
コード例 #5
0
ファイル: TextEditSink.cpp プロジェクト: deton/tsf-tutcode
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;
}
コード例 #6
0
ファイル: Composition.cpp プロジェクト: wyrover/weasel
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;
}
コード例 #7
0
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;
}
コード例 #8
0
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;
}
コード例 #9
0
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;
}
コード例 #10
0
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;
}