diff options
author | Alexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de> | 2004-06-21 13:19:32 +0000 |
---|---|---|
committer | Alexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de> | 2004-06-21 13:19:32 +0000 |
commit | d6e8b1affec7351549c0006cc63b6923091cdd68 (patch) | |
tree | 6e5e9dd1c1ec6e141349337df844b649bbf4277d /hw/xwin/winmultiwindowwndproc.c | |
parent | dfdbb60bf5f613b3554d5435f08f16bde72aa353 (diff) |
Bug 777: Merge from CYGWIN branch
Diffstat (limited to 'hw/xwin/winmultiwindowwndproc.c')
-rwxr-xr-x | hw/xwin/winmultiwindowwndproc.c | 418 |
1 files changed, 231 insertions, 187 deletions
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c index 83f3b02f6..ff18f2e42 100755 --- a/hw/xwin/winmultiwindowwndproc.c +++ b/hw/xwin/winmultiwindowwndproc.c @@ -35,19 +35,17 @@ #include "dixevents.h" #include "winmultiwindowclass.h" #include "winprefs.h" +#if CYGDEBUG +#include "winmessages.h" +#endif /* * External global variables */ -extern Bool g_fCursor; - - -/* - * Global variables - */ - -HICON g_hiconX = NULL; +extern Bool g_fCursor; +extern Bool g_fKeyboardHookLL; +extern Bool g_fSoftwareCursor; /* @@ -65,7 +63,6 @@ static UINT_PTR g_uipMousePollingTimerID = 0; #define WIN_MULTIWINDOW_SHAPE YES - /* * ConstrainSize - Taken from TWM sources - Respects hints for sizing */ @@ -206,8 +203,7 @@ ValidateSizing (HWND hwnd, WindowPtr pWin, { WinXSizeHints sizeHints; RECT *rect; - int iWidth, iHeight, iTopBorder; - POINT pt; + int iWidth, iHeight; /* Invalid input checking */ if (pWin==NULL || lParam==0) @@ -229,21 +225,19 @@ ValidateSizing (HWND hwnd, WindowPtr pWin, iWidth = rect->right - rect->left; iHeight = rect->bottom - rect->top; - /* Get title bar height, there must be an easier way?! */ - pt.x = pt.y = 0; - ClientToScreen(hwnd, &pt); - iTopBorder = pt.y - rect->top; - /* Now remove size of any borders */ iWidth -= 2 * GetSystemMetrics(SM_CXSIZEFRAME); - iHeight -= GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + iHeight -= (GetSystemMetrics(SM_CYCAPTION) + + 2 * GetSystemMetrics(SM_CYSIZEFRAME)); + /* Constrain the size to legal values */ ConstrainSize (sizeHints, &iWidth, &iHeight); /* Add back the borders */ iWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME); - iHeight += GetSystemMetrics(SM_CYSIZEFRAME) + iTopBorder; + iHeight += (GetSystemMetrics(SM_CYCAPTION) + + 2 * GetSystemMetrics(SM_CYSIZEFRAME)); /* Adjust size according to where we're dragging from */ switch(wParam) { @@ -296,6 +290,19 @@ winTopLevelWindowProc (HWND hwnd, UINT message, winWMMessageRec wmMsg; Bool fWMMsgInitialized = FALSE; static Bool s_fTracking = FALSE; + +#if CYGDEBUG + if (message >= WM_USER) + { + winDebug("winTopLevelWindowProc - Message WM_USER + %d", message - WM_USER); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } + else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message]) + { + winDebug("winTopLevelWindowProc - Message %s", MESSAGE_NAMES[message]); + winDebug(" wParam 0x%x lParam 0x%x\n", wParam, lParam); + } +#endif /* Check if the Windows window property for our X window pointer is valid */ if ((pWin = GetProp (hwnd, WIN_WINDOW_PROP)) != NULL) @@ -321,10 +328,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, wmMsg.hwndWindow = hwnd; wmMsg.iWindow = (Window)GetProp (hwnd, WIN_WID_PROP); - wmMsg.iX = pWinPriv->iX; - wmMsg.iY = pWinPriv->iY; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; + wmMsg.iX = pDraw->x; + wmMsg.iY = pDraw->y; + wmMsg.iWidth = pDraw->width; + wmMsg.iHeight = pDraw->height; fWMMsgInitialized = TRUE; @@ -373,9 +380,14 @@ winTopLevelWindowProc (HWND hwnd, UINT message, WIN_WID_PROP, (HANDLE)winGetWindowID (((LPCREATESTRUCT) lParam)->lpCreateParams)); + /* + * Make X windows' Z orders sync with Windows windows because + * there can be AlwaysOnTop windows overlapped on the window + * currently being created. + */ + winReorderWindowsMultiWindow (); return 0; - case WM_INIT_SYS_MENU: /* * Add whatever the setup file wants to for this window @@ -387,7 +399,33 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* * Any window menu items go through here */ - HandleCustomWM_COMMAND ((unsigned long)hwnd, LOWORD(wParam)); +#if CYGMULTIWINDOW_DEBUG + switch (wParam & 0xFFF0) /* See MSDN for the magic number 0xFFF0 */ + { + case SC_MINIMIZE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_MINIMIZE)\n"); + break; + + case SC_RESTORE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_RESTORE)\n"); + break; + + case SC_MAXIMIZE: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (SC_MAXIMIZE)\n"); + break; + + default: + ErrorF ("winTopLevelWindowProc - WM_SYSCOMMAND (UNKNOWN)\n"); +#endif + if (HandleCustomWM_COMMAND ((unsigned long)hwnd, LOWORD(wParam))) + { + /* Don't pass customized menus to DefWindowProc */ + return 0; + } +#if CYGMULTIWINDOW_DEBUG + break; + } +#endif break; case WM_INITMENU: @@ -481,7 +519,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, } /* Hide or show the Windows mouse cursor */ - if (g_fCursor) + if (g_fSoftwareCursor && g_fCursor) { /* Hide Windows cursor */ g_fCursor = FALSE; @@ -516,7 +554,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, break; /* Non-client mouse movement, show Windows cursor */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -540,7 +578,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message, s_fTracking = FALSE; /* Show the mouse cursor, if necessary */ - if (!g_fCursor) + if (g_fSoftwareCursor && !g_fCursor) { g_fCursor = TRUE; ShowCursor (TRUE); @@ -599,9 +637,23 @@ winTopLevelWindowProc (HWND hwnd, UINT message, SendMessage (hwndScreen, message, wParam, lParam); return 0; + case WM_SETFOCUS: + if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) + break; + + winRestoreModeKeyStates (); + + /* Add the keyboard hook if possible */ + if (g_fKeyboardHookLL) + g_fKeyboardHookLL = winInstallKeyboardHookLL (); + return 0; + case WM_KILLFOCUS: /* Pop any pressed keys since we are losing keyboard focus */ winKeybdReleaseKeys (); + + /* Remove our keyboard hook if it is installed */ + winRemoveKeyboardHookLL (); return 0; case WM_SYSDEADCHAR: @@ -635,6 +687,42 @@ winTopLevelWindowProc (HWND hwnd, UINT message, if (wParam == VK_F4 && (GetKeyState (VK_MENU) & 0x8000)) break; +#if CYGWINDOWING_DEBUG + if (wParam == VK_ESCAPE) + { + /* Place for debug: put any tests and dumps here */ + WINDOWPLACEMENT windPlace; + RECT rc; + LPRECT pRect; + + windPlace.length = sizeof (WINDOWPLACEMENT); + GetWindowPlacement (hwnd, &windPlace); + pRect = &windPlace.rcNormalPosition; + ErrorF ("\nCYGWINDOWING Dump:\n" + "\tdrawable: (%hd, %hd) - %hdx%hd\n", pDraw->x, + pDraw->y, pDraw->width, pDraw->height); + ErrorF ("\twindPlace: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + if (GetClientRect (hwnd, &rc)) + { + pRect = &rc; + ErrorF ("\tClientRect: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + } + if (GetWindowRect (hwnd, &rc)) + { + pRect = &rc; + ErrorF ("\tWindowRect: (%ld, %ld) - %ldx%ld\n", pRect->left, + pRect->top, pRect->right - pRect->left, + pRect->bottom - pRect->top); + } + ErrorF ("\n"); + return 0; + } +#endif + /* Pass the message to the root window */ SendMessage (hwndScreen, message, wParam, lParam); return 0; @@ -667,15 +755,18 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* Pass the message to the root window */ SendMessage (hwndScreen, message, wParam, lParam); - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - if (LOWORD(wParam) != WA_INACTIVE) { + /* Raise the window to the top in Z order */ + wmMsg.msg = WM_WM_RAISE; + if (fWMMsgInitialized) + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + /* Tell our Window Manager thread to activate the window */ wmMsg.msg = WM_WM_ACTIVATE; if (fWMMsgInitialized) - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + if (!pWin || !pWin->overrideRedirect) /* for OOo menus */ + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); } return 0; @@ -683,10 +774,11 @@ winTopLevelWindowProc (HWND hwnd, UINT message, #if CYGMULTIWINDOW_DEBUG ErrorF ("winTopLevelWindowProc - WM_ACTIVATEAPP\n"); #endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - return 0; + /* + * This message is also sent to the root window + * so we do nothing for individual multiwindow windows + */ + break; case WM_CLOSE: #if CYGMULTIWINDOW_DEBUG @@ -723,48 +815,23 @@ winTopLevelWindowProc (HWND hwnd, UINT message, winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); } + RemoveProp (hwnd, WIN_WINDOW_PROP); + RemoveProp (hwnd, WIN_WID_PROP); + RemoveProp (hwnd, WIN_NEEDMANAGE_PROP); + #if CYGMULTIWINDOW_DEBUG ErrorF ("winTopLevelWindowProc - WM_DESTROY\n"); #endif break; case WM_MOVE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_MOVE - %d ms\n", GetTickCount ()); -#endif - - /* Bail if Windows window is not actually moving */ - if (pWinPriv->iX == (short) LOWORD(lParam) - && pWinPriv->iY == (short) HIWORD(lParam)) - break; - - /* Also bail if we're maximizing, we'll do the whole thing in WM_SIZE */ - { - WINDOWPLACEMENT windPlace; - windPlace.length = sizeof (WINDOWPLACEMENT); - - /* Get current window placement */ - GetWindowPlacement (hwnd, &windPlace); - - /* Bail if maximizing */ - if (windPlace.showCmd == SW_MAXIMIZE - || windPlace.showCmd == SW_SHOWMAXIMIZED) - break; - } - - /* Get new position */ - pWinPriv->iX = (short) LOWORD(lParam); - pWinPriv->iY = (short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iX, pWinPriv->iY); +#if CYGWINDOWING_DEBUG + ErrorF ("winTopLevelWindowProc - WM_MOVE to (%d, %d) - %d ms\n", + (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), + (int)(GetTickCount ())); #endif - - winMoveXWindow (pWin, - (LOWORD(lParam) - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN)), - (HIWORD(lParam) - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN))); + /* Adjust the X Window to the moved Windows window */ + winAdjustXWindow (pWin, hwnd); return 0; case WM_SHOWWINDOW: @@ -772,6 +839,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, if (!wParam) return 0; +#if CYGWINDOWING_DEBUG + ErrorF ("winTopLevelWindowProc - WM_SHOWWINDOW\n"); +#endif + /* Tell X to map the window */ MapWindow (pWin, wClient(pWin)); @@ -795,10 +866,10 @@ winTopLevelWindowProc (HWND hwnd, UINT message, { /* Setup a rectangle with the X window position and size */ SetRect (&rcNew, - pWinPriv->iX, - pWinPriv->iY, - pWinPriv->iX + pWinPriv->iWidth, - pWinPriv->iY + pWinPriv->iHeight); + pDraw->x, + pDraw->y, + pDraw->x + pDraw->width, + pDraw->y + pDraw->height); #if 0 ErrorF ("winTopLevelWindowProc - (%d, %d)-(%d, %d)\n", @@ -813,8 +884,8 @@ winTopLevelWindowProc (HWND hwnd, UINT message, WS_EX_APPWINDOW); /* Calculate position deltas */ - iDx = pWinPriv->iX - rcNew.left; - iDy = pWinPriv->iY - rcNew.top; + iDx = pDraw->x - rcNew.left; + iDy = pDraw->y - rcNew.top; /* Calculate new rectangle */ rcNew.left += iDx; @@ -846,18 +917,24 @@ winTopLevelWindowProc (HWND hwnd, UINT message, SetForegroundWindow (hwnd); } } + else /* It is an overridden window so make it top of Z stack */ + { +#if CYGWINDOWING_DEBUG + ErrorF ("overridden window is shown\n"); +#endif + SetWindowPos (hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE); + } /* Setup the Window Manager message */ wmMsg.msg = WM_WM_MAP; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; + wmMsg.iWidth = pDraw->width; + wmMsg.iHeight = pDraw->height; /* Tell our Window Manager thread to map the window */ if (fWMMsgInitialized) winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; return 0; case WM_SIZING: @@ -865,119 +942,78 @@ winTopLevelWindowProc (HWND hwnd, UINT message, /* for applications like xterm */ return ValidateSizing (hwnd, pWin, wParam, lParam); - case WM_WINDOWPOSCHANGED: - { - LPWINDOWPOS pwindPos = (LPWINDOWPOS) lParam; - - /* Bail if window z order was not changed */ - if (pwindPos->flags & SWP_NOZORDER) - break; - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - hwndInsertAfter: %p\n", - pwindPos->hwndInsertAfter); + case WM_WINDOWPOSCHANGING: + if (lParam != 0) + { + WINDOWPOS *windowpos = (WINDOWPOS *)lParam; + HWND hwndprev = GetNextWindow(hwnd, GW_HWNDPREV); + HWND hwndafter = windowpos->hwndInsertAfter; +#if CYGDEBUG + char buffer[1024]; + char buffer2[1024]; + GetWindowText(hwndafter, buffer, sizeof(buffer)); + GetWindowText(hwndprev, buffer2, sizeof(buffer2)); + winDebug("%s - hwndInsertAfter = %x (%s), hwndPrev = %x (%s)\n", + __FUNCTION__, hwndafter, + (hwndafter==HWND_TOP?"HWND_TOP": + (hwndafter==HWND_BOTTOM?"HWND_BOTTOM": + (hwndafter==HWND_NOTOPMOST?"HWND_NOTOPMOST": + (hwndafter==HWND_TOPMOST?"HWND_TOPMOST": + buffer)))), + hwndprev, + (hwndprev==HWND_TOP?"HWND_TOP": + (hwndprev==HWND_BOTTOM?"HWND_BOTTOM": + (hwndprev==HWND_NOTOPMOST?"HWND_NOTOPMOST": + (hwndprev==HWND_TOPMOST?"HWND_TOPMOST": + buffer2))))); + winDebug("%s - flags: %s\n", __FUNCTION__, + (windowpos->flags & SWP_NOZORDER?"NOZORDER":"")); + #endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - } - return 0; + if (windowpos->flags & SWP_NOZORDER) + break; + if (TRUE || hwndafter == HWND_TOP || hwndafter != hwndprev) + { + wmMsg.msg = WM_WM_RAISE; + //if (fWMMsgInitialized) + winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + } + } + break; + case WM_WINDOWPOSCHANGED: + /* + * Pass the message to DefWindowProc to let the function + * break down WM_WINDOWPOSCHANGED to WM_MOVE and WM_SIZE. + */ + break; case WM_SIZE: /* see dix/window.c */ - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_SIZE - %d ms\n", GetTickCount ()); -#endif - - /* Branch on type of resizing occurring */ - switch (wParam) - { - case SIZE_MINIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\tSIZE_MINIMIZED\n"); -#endif - if (s_pScreenPriv != NULL) - s_pScreenPriv->fWindowOrderChanged = TRUE; - break; - - case SIZE_RESTORED: - case SIZE_MAXIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("SIZE_RESTORED || SIZE_MAXIMIZED\n"); -#endif - /* Break out if nothing to do */ - if (pWinPriv->iWidth == (short) LOWORD(lParam) - && pWinPriv->iHeight == (short) HIWORD(lParam)) +#if CYGWINDOWING_DEBUG + { + char buf[64]; + switch (wParam) + { + case SIZE_MINIMIZED: + strcpy(buf, "SIZE_MINIMIZED"); break; - - /* Get the dimensions of the resized Windows window */ - pWinPriv->iWidth = (short) LOWORD(lParam); - pWinPriv->iHeight = (short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iWidth, pWinPriv->iHeight); + case SIZE_MAXIMIZED: + strcpy(buf, "SIZE_MAXIMIZED"); + break; + case SIZE_RESTORED: + strcpy(buf, "SIZE_RESTORED"); + break; + default: + strcpy(buf, "UNKNOWN_FLAG"); + } + ErrorF ("winTopLevelWindowProc - WM_SIZE to %dx%d (%s) - %d ms\n", + (int)LOWORD(lParam), (int)HIWORD(lParam), buf, + (int)(GetTickCount ())); + } #endif - - /* - * If we're maximizing the window has been moved to upper left - * of current screen. Now it is safe for X to know about this. - */ - if (wParam == SIZE_MAXIMIZED) - { - POINT ptHome; - - /* Flag that we are being maximized and store info for restore */ - pWinPriv->fNeedRestore = TRUE; - pWinPriv->ptRestore.x = pWinPriv->iX; - pWinPriv->ptRestore.y = pWinPriv->iY; - - /* Get screen location of window root */ - ptHome.x = 0; - ptHome.y = 0; - ClientToScreen (hwnd, &ptHome); - - /* Map from screen (-X,-Y) to (0,0) root coords */ - winMoveXWindow (pWin, - ptHome.x - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN), - ptHome.y - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN)); - } - else if (wParam == SIZE_RESTORED && pWinPriv->fNeedRestore) - { - /* If need restore and !maximized then move to cached position */ - WINDOWPLACEMENT windPlace; - - windPlace.length = sizeof (WINDOWPLACEMENT); - - GetWindowPlacement (hwnd, &windPlace); - - if (windPlace.showCmd != SW_MAXIMIZE - && windPlace.showCmd != SW_SHOWMAXIMIZED) - { - pWinPriv->fNeedRestore = FALSE; - winMoveXWindow (pWin, - pWinPriv->ptRestore.x - wBorderWidth (pWin) - - GetSystemMetrics (SM_XVIRTUALSCREEN), - pWinPriv->ptRestore.y - wBorderWidth (pWin) - - GetSystemMetrics (SM_YVIRTUALSCREEN)); - } - } - - /* Perform the resize and notify the X client */ - winResizeXWindow (pWin, - (short) LOWORD(lParam), - (short) HIWORD(lParam)); - break; - - default: - break; - } - return 0; + /* Adjust the X Window to the moved Windows window */ + winAdjustXWindow (pWin, hwnd); + return 0; /* end of WM_SIZE handler */ case WM_MOUSEACTIVATE: #if CYGMULTIWINDOW_DEBUG @@ -997,6 +1033,14 @@ winTopLevelWindowProc (HWND hwnd, UINT message, } break; + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) + { + if (!g_fSoftwareCursor) SetCursor (s_pScreenPriv->cursor.handle); + return TRUE; + } + break; + default: break; } |