From 93135f3a7e695ffeb42c5b0c6bd1abc281c6905b Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sat, 1 Apr 2000 22:16:43 +0000 Subject: [PATCH] constrain attempts to change z-level --- widget/src/windows/nsWindow.cpp | 114 ++++++++++++++++++++++++-------- widget/src/windows/nsWindow.h | 3 + 2 files changed, 88 insertions(+), 29 deletions(-) diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 56951379075..b7579aa94b0 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -965,7 +965,7 @@ NS_METHOD nsWindow::Show(PRBool bState) if (mWnd) { if (bState) { DWORD flags = SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW; - if ((mIsVisible) || (mWindowType == eWindowType_popup)) { + if (mIsVisible || mWindowType == eWindowType_popup) { flags |= SWP_NOZORDER; } @@ -994,6 +994,20 @@ NS_METHOD nsWindow::IsVisible(PRBool & bState) return NS_OK; } +//------------------------------------------------------------------------- +// +// Position the window behind the given window +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::PlaceBehind(nsIWidget *aWidget) +{ + HWND behind; + behind = aWidget ? (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW) : HWND_TOP; + ::SetWindowPos(mWnd, behind, 0, 0, 0, 0, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOSIZE); + return NS_OK; +} + //------------------------------------------------------------------------- // Return PR_TRUE in aForWindow if the given event should be processed // assuming this is a modal window. @@ -2018,6 +2032,42 @@ BOOL nsWindow::OnChar( UINT mbcsCharCode, UINT virtualKeyCode, bool isMultiByte static PRBool gJustGotDeactivate = PR_FALSE; static PRBool gJustGotActivate = PR_FALSE; +void nsWindow::ConstrainZLevel(HWND *aAfter) { + + nsZLevelEvent event; + nsWindow *aboveWindow = 0; + + event.eventStructType = NS_ZLEVEL_EVENT; + InitEvent(event, NS_SETZLEVEL); + + if (*aAfter == HWND_BOTTOM) + event.mPlacement = nsWindowZBottom; + else if (*aAfter == HWND_TOP || *aAfter == HWND_TOPMOST || *aAfter == HWND_NOTOPMOST) + event.mPlacement = nsWindowZTop; + else { + event.mPlacement = nsWindowZRelative; + aboveWindow = (nsWindow*)::GetWindowLong(*aAfter, GWL_USERDATA); + } + event.mReqBelow = aboveWindow; + + event.mImmediate = PR_FALSE; + event.mAdjusted = PR_FALSE; + DispatchWindowEvent(&event); + + if (event.mAdjusted) { + if (event.mPlacement == nsWindowZBottom) + *aAfter = HWND_BOTTOM; + else if (event.mPlacement == nsWindowZTop) + *aAfter = HWND_TOP; + else { + *aAfter = (HWND)event.mActualBelow->GetNativeData(NS_NATIVE_WINDOW); + NS_IF_RELEASE(event.mActualBelow); + } + } + + NS_RELEASE(event.widget); +} + PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue) { static UINT vkKeyCached = 0; // caches VK code fon WM_KEYDOWN @@ -2051,7 +2101,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT break; case WM_SYSCOMMAND: - // all we care about right now are the minimize and maximize buttons if (wParam == SC_MINIMIZE || wParam == SC_MAXIMIZE || wParam == SC_RESTORE) { nsSizeModeEvent event; event.eventStructType = NS_SIZEMODE_EVENT; @@ -2333,45 +2382,52 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result = PR_TRUE; break; - case WM_ACTIVATE: - if (mEventCallback) { - PRInt32 fActive = LOWORD(wParam); - - if(WA_INACTIVE == fActive) { - gJustGotDeactivate = PR_TRUE; - } else { - gJustGotActivate = PR_TRUE; - nsMouseEvent event; - event.eventStructType = NS_GUI_EVENT; - InitEvent(event, NS_MOUSE_ACTIVATE); + case WM_ACTIVATE: + if (mEventCallback) { + PRInt32 fActive = LOWORD(wParam); - event.acceptActivation = PR_TRUE; + if(WA_INACTIVE == fActive) { + gJustGotDeactivate = PR_TRUE; + } else { + gJustGotActivate = PR_TRUE; + nsMouseEvent event; + event.eventStructType = NS_GUI_EVENT; + InitEvent(event, NS_MOUSE_ACTIVATE); - PRBool result = DispatchWindowEvent(&event); - NS_RELEASE(event.widget); - - if(event.acceptActivation) - *aRetValue = MA_ACTIVATE; - else - *aRetValue = MA_NOACTIVATE; - } - } - break; + event.acceptActivation = PR_TRUE; + + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + + if(event.acceptActivation) + *aRetValue = MA_ACTIVATE; + else + *aRetValue = MA_NOACTIVATE; + } + } + break; + + case WM_WINDOWPOSCHANGING: { + LPWINDOWPOS info = (LPWINDOWPOS) lParam; + if (!(info->flags & SWP_NOZORDER)) + ConstrainZLevel(&info->hwndInsertAfter); + break; + } case WM_SETFOCUS: result = DispatchFocus(NS_GOTFOCUS); - if(gJustGotActivate) { + if(gJustGotActivate) { gJustGotActivate = PR_FALSE; result = DispatchFocus(NS_ACTIVATE); - } + } break; case WM_KILLFOCUS: result = DispatchFocus(NS_LOSTFOCUS); - if(gJustGotDeactivate) { + if(gJustGotDeactivate) { gJustGotDeactivate = PR_FALSE; - result = DispatchFocus(NS_DEACTIVATE); - } + result = DispatchFocus(NS_DEACTIVATE); + } break; case WM_WINDOWPOSCHANGED: diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 742a08ec295..75f6f220e92 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -98,6 +98,7 @@ public: virtual nsIWidget* GetParent(void); NS_IMETHOD Show(PRBool bState); NS_IMETHOD IsVisible(PRBool & aState); + NS_IMETHOD PlaceBehind(nsIWidget *aWidget); NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow); @@ -240,6 +241,8 @@ protected: NS_IMETHOD PasswordFieldEnter(PRUint32& oSavedState); NS_IMETHOD PasswordFieldExit(PRUint32 aRestoredState); + void ConstrainZLevel(HWND *aAfter); + private: #ifdef DEBUG