Skip to content

Commit

Permalink
1. bug fixed on follow caret in outlook.com mail composition
Browse files Browse the repository at this point in the history
2. bug fixed on bounced back to foreground window when a child window is
active (like office ->share -> email as attachement
  • Loading branch information
jrywu committed Aug 26, 2013
1 parent 652b68f commit d84f853
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 20 deletions.
10 changes: 6 additions & 4 deletions BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ void CBaseWindow::_Move(int x, int y)
{
if (_wndHandle != nullptr)
{
// set the zorder to be above all non topmost windows to avoid bounce back on child windows (like office share->email)
SetWindowPos(_wndHandle, HWND_TOPMOST, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE);
// do not aluter zorder to to avoid bounce back on child windows (like office share->email)
SetWindowPos(_wndHandle, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE |SWP_NOZORDER);
}
else
{
Expand Down Expand Up @@ -194,11 +194,13 @@ void CBaseWindow::_Show(BOOL isShowWnd)
{
if (isShowWnd)
{
ShowWindow(_wndHandle, SW_SHOWNA);
SetWindowPos(_wndHandle, NULL, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW |SWP_NOZORDER);
}
else
{
ShowWindow(_wndHandle, SW_HIDE);
SetWindowPos(_wndHandle, NULL, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_HIDEWINDOW |SWP_NOZORDER);
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions NotifyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ CNotifyWindow::CNotifyWindow(_In_ NOTIFYWNDCALLBACK pfnCallback, _In_ void *pv)
_pObj = pv;

_pShadowWnd = nullptr;
//_cxTitle = 100;
//_cyTitle = 100;

_x =0;
_y =0;

Expand Down Expand Up @@ -88,6 +87,7 @@ BOOL CNotifyWindow::_CreateMainWindow(_In_opt_ HWND parentWndHandle)
{
return FALSE;
}

SetLayeredWindowAttributes(_GetWnd(), 0, (255 * 95) / 100, LWA_ALPHA);

return TRUE;
Expand Down Expand Up @@ -117,7 +117,7 @@ BOOL CNotifyWindow::_CreateBackGroundShadowWindow()
void CNotifyWindow::_ResizeWindow()
{
debugPrint(L"CNotifyWindow::_ResizeWindow() , _x = %d, _y= %d, _cx= %d, _cy= %d", _x, _y, _cxTitle, _cyTitle);
CBaseWindow::_Resize(_x, _y, _cxTitle, _cyTitle);
CBaseWindow::_Resize(_x, _y, _cxTitle, _cyTitle);
_InvalidateRect();
}

Expand Down
86 changes: 73 additions & 13 deletions UIPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Derived from Microsoft Sample IME by Jeremy '13,7,17
//
//
#define DEBUG_PRINT
//#define DEBUG_PRINT

#include "Private.h"
#include "CandidateWindow.h"
Expand Down Expand Up @@ -747,22 +747,51 @@ BOOL CUIPresenter::_MoveCandidatePage(_In_ int offSet)
void CUIPresenter::_MoveUIWindowsToTextExt()
{
debugPrint(L"CUIPresenter::_MoveCandidateWindowToTextExt()");
RECT rc;
RECT compRect;

if (FAILED(_GetTextExt(&rc)))
if (FAILED(_GetTextExt(&compRect)))
{
return;
}
debugPrint(L"CUIPresenter::_MoveCandidateWindowToTextExt(), top = %d, bottom = %d, right = %d, left = %d", compRect.top, compRect.bottom, compRect.right, compRect.left);
ITfContext *pContext = _GetContextDocument();
ITfContextView * pView = nullptr;
HWND parentWndHandle;
if (SUCCEEDED(pContext->GetActiveView(&pView)))
{
POINT pt;
pView->GetWnd(&parentWndHandle);
GetCaretPos(&pt);
ClientToScreen(parentWndHandle, &pt);
debugPrint(L"current caret position from GetCaretPos, x = %d, y = %d", pt.x, pt.y);
if(pt.x <compRect.right && pt.x >=compRect.left) compRect.left = pt.x;
if(pt.y <=compRect.bottom && pt.y >compRect.top && (compRect.bottom - pt.y < pt.y - compRect.top) ) compRect.bottom = pt.y;

GUITHREADINFO* guiInfo = new GUITHREADINFO;
guiInfo->cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(NULL, guiInfo);
if(guiInfo->hwndCaret)
{ //for acient non TSF aware apps with a floating composition window. The caret position we can get is always the caret in the flaoting comosition window.

pt.x = guiInfo->rcCaret.left;
pt.y = guiInfo->rcCaret.bottom;
ClientToScreen(parentWndHandle, &pt);
debugPrint(L"current caret position from GetGUIThreadInfo, x = %d, y = %d", pt.x, pt.y);
if(pt.x <compRect.right && pt.x >=compRect.left) compRect.left = pt.x;
if(pt.y <=compRect.bottom && pt.y >compRect.top && (compRect.bottom - pt.y < pt.y - compRect.top) ) compRect.bottom = pt.y;
}

}
if(_pCandidateWnd)
{
_pCandidateWnd->_Move(rc.left, rc.bottom);
_candLocation.x = rc.left;
_candLocation.y = rc.bottom;
_pCandidateWnd->_Move(compRect.left, compRect.bottom);
_candLocation.x = compRect.left;
_candLocation.y = compRect.bottom;
}
if(_pNotifyWnd)
{
_notifyLocation.x = rc.left;
_notifyLocation.y = rc.bottom;
_notifyLocation.x = compRect.left;
_notifyLocation.y = compRect.bottom;
if(_notifyLocation.x < (int) _pNotifyWnd->_GetWidth() )
_pNotifyWnd->_Move(_notifyLocation.x + _pCandidateWnd->_GetWidth() , _notifyLocation.y);
else
Expand All @@ -779,18 +808,49 @@ VOID CUIPresenter::_LayoutChangeNotification(_In_ RECT *lpRect)
{
debugPrint(L"CUIPresenter::_LayoutChangeNotification(), top = %d, bottom = %d, right = %d, left = %d", lpRect->top, lpRect->bottom, lpRect->right, lpRect->left);
if(lpRect == nullptr) return;
RECT compRect = * lpRect;
RECT candRect = {0, 0, 0, 0};
RECT notifyRect = {0, 0, 0, 0};
POINT candPt = {0, 0};
POINT notifyPt = {0, 0};

ITfContext *pContext = _GetContextDocument();
ITfContextView * pView = nullptr;
HWND parentWndHandle;
if (SUCCEEDED(pContext->GetActiveView(&pView)))
{
POINT pt;
pView->GetWnd(&parentWndHandle);
GetCaretPos(&pt);
ClientToScreen(parentWndHandle, &pt);
debugPrint(L"current caret position from GetCaretPos, x = %d, y = %d", pt.x, pt.y);
if(pt.x <compRect.right && pt.x >=compRect.left) compRect.left = pt.x;
if(pt.y <=compRect.bottom && pt.y >compRect.top && (compRect.bottom - pt.y < pt.y - compRect.top) ) compRect.bottom = pt.y;

GUITHREADINFO* guiInfo = new GUITHREADINFO;
guiInfo->cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(NULL, guiInfo);
if(guiInfo->hwndCaret)
{ //for acient non TSF aware apps with a floating composition window. The caret position we can get is always the caret in the flaoting comosition window.

pt.x = guiInfo->rcCaret.left;
pt.y = guiInfo->rcCaret.bottom;
ClientToScreen(parentWndHandle, &pt);
debugPrint(L"current caret position from GetGUIThreadInfo, x = %d, y = %d", pt.x, pt.y);
if(pt.x <compRect.right && pt.x >=compRect.left) compRect.left = pt.x;
if(pt.y <=compRect.bottom && pt.y >compRect.top && (compRect.bottom - pt.y < pt.y - compRect.top) ) compRect.bottom = pt.y;
}

}
if(_pCandidateWnd
&& (lpRect->bottom - lpRect->top >1) && (lpRect->right - lpRect->left >1) ) // confirm the extent rect is valid.
{
_pCandidateWnd->_GetClientRect(&candRect);
_pCandidateWnd->_GetWindowExtent(lpRect, &candRect, &candPt);
_pCandidateWnd->_GetWindowExtent(&compRect, &candRect, &candPt);
_pCandidateWnd->_Move(candPt.x, candPt.y);
_candLocation.x = candPt.x;
_candLocation.y = candPt.y;
debugPrint(L"move cand to x = %d, y = %d", candPt.x, candPt.y);
}
if(_pNotifyWnd
&& (lpRect->bottom - lpRect->top >1) && (lpRect->right - lpRect->left >1) ) // confirm the extent rect is valid.
Expand All @@ -809,14 +869,14 @@ VOID CUIPresenter::_LayoutChangeNotification(_In_ RECT *lpRect)
{
_pNotifyWnd->_InvalidateRect();
_pNotifyWnd->_GetClientRect(&notifyRect);
_pNotifyWnd->_GetWindowExtent(lpRect, &candRect, &notifyPt);
_pNotifyWnd->_GetWindowExtent(&compRect, &candRect, &notifyPt);
_pNotifyWnd->_Move(notifyPt.x, notifyPt.y);
_notifyLocation.x = notifyPt.x;
_notifyLocation.y = notifyPt.y;
}

debugPrint(L"move notify to x = %d, y = %d", _notifyLocation.x, _notifyLocation.y);
}
_rectCompRange = *lpRect;
_rectCompRange = compRect;
}

void CUIPresenter::GetCandLocation(POINT *lpPoint)
Expand Down Expand Up @@ -1237,7 +1297,7 @@ void CUIPresenter::ShowNotifyText(_In_ CStringRange *pNotifyText, _In_ int timeT
pt->x = guiInfo->rcCaret.left;
pt->y = guiInfo->rcCaret.bottom;
ClientToScreen(parentWndHandle, pt);
debugPrint(L"current caret position from GetGUIThreadInfo, x = %d, y = %d, focus hwd = %x", guiInfo->rcCaret.left, guiInfo->rcCaret.bottom);
debugPrint(L"current caret position from GetGUIThreadInfo, x = %d, y = %d, focus hwd = %x", pt->x, pt->y);
if(_notifyLocation.x < 0) _notifyLocation.x = pt->x;
if(_notifyLocation.y < 0) _notifyLocation.y = pt->y;
}
Expand Down

0 comments on commit d84f853

Please sign in to comment.