From 7e864891562681e438100955ceb845e12baf4f6f Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Thu, 6 Jan 2000 16:01:15 +0000 Subject: [PATCH] added GetScreenBounds. part of bug 5998. r:pierre --- widget/src/mac/nsMacWindow.cpp | 71 +++++++++++++++++++--------------- widget/src/mac/nsMacWindow.h | 1 + 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/widget/src/mac/nsMacWindow.cpp b/widget/src/mac/nsMacWindow.cpp index 996033993e1e..017a89c1d5a8 100644 --- a/widget/src/mac/nsMacWindow.cpp +++ b/widget/src/mac/nsMacWindow.cpp @@ -53,7 +53,7 @@ static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); // Windows and Mac. #define WINDOW_SIZE_TWEAKING -// these should come from the system, not be hard-coded. What if I'm running +// еее TODO: these should come from the system, not be hard-coded. What if I'm running // an elaborate theme with wide window borders? const short kWindowTitleBarHeight = 22; const short kWindowMarginWidth = 6; @@ -574,6 +574,9 @@ NS_METHOD nsWindow::Restore(void) // Move this window // //------------------------------------------------------------------------- +//------------------------------------------------------------------------- +// Move +//------------------------------------------------------------------------- NS_IMETHODIMP nsMacWindow::Move(PRInt32 aX, PRInt32 aY) { @@ -611,11 +614,22 @@ NS_IMETHODIMP nsMacWindow::Move(PRInt32 aX, PRInt32 aY) else if (((PRInt32)aX) > screenRect.right) aX = screenRect.right; - if (((PRInt32)aY) < screenRect.top) - aY = screenRect.top; - else if (((PRInt32)aY) > screenRect.bottom) + if (((PRInt32)aY) > screenRect.bottom-screenRect.top) aY = screenRect.bottom; + if (mIsDialog) + { + aX += kDialogMarginWidth; + aY += kDialogTitleBarHeight; + } + else + { + aX += kWindowMarginWidth; + aY += kWindowTitleBarHeight; + } + aX += screenRect.left; + aY += screenRect.top; + // move the window if it has not been moved yet // (ie. if this function isn't called in response to a DragWindow event) #if TARGET_CARBON @@ -625,35 +639,8 @@ NS_IMETHODIMP nsMacWindow::Move(PRInt32 aX, PRInt32 aY) macPoint = topLeft(mWindowPtr->portRect); #endif ::LocalToGlobal(&macPoint); - if ((macPoint.h != aX) || (macPoint.v != aY)) - { - // in that case, the window borders should be visible too - PRUint32 minX, minY; - if (mIsDialog) - { - minX = kDialogMarginWidth; -#if TARGET_CARBON - minY = kDialogTitleBarHeight + ::GetMBarHeight(); -#else - minY = kDialogTitleBarHeight + ::LMGetMBarHeight(); -#endif - } - else - { - minX = kWindowMarginWidth; -#if TARGET_CARBON - minY = kWindowTitleBarHeight + ::GetMBarHeight(); -#else - minY = kWindowTitleBarHeight + ::LMGetMBarHeight(); -#endif - } - if (aX < minX) - aX = minX; - if (aY < minY) - aY = minY; - + if (macPoint.h != aX || macPoint.v != aY) ::MoveWindow(mWindowPtr, aX, aY, false); - } // propagate the event in global coordinates Inherited::Move(aX, aY); @@ -698,6 +685,26 @@ NS_IMETHODIMP nsMacWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepai return NS_OK; } +NS_IMETHODIMP nsMacWindow::GetScreenBounds(nsRect &aRect) { + +#if TARGET_CARBON + Rect screenRect; + ::GetRegionBounds(::GetGrayRgn(), &screenRect); +#else + Rect screenRect = (**::GetGrayRgn()).rgnBBox; +#endif + + nsRect localBounds; + + GetBounds(localBounds); + WidgetToScreen(localBounds, aRect); + if (mIsDialog) + aRect.MoveBy(-kDialogMarginWidth-screenRect.left, -kDialogTitleBarHeight-screenRect.top); + else + aRect.MoveBy(-kWindowMarginWidth-screenRect.left, -kWindowTitleBarHeight-screenRect.top); + return NS_OK; +} + //------------------------------------------------------------------------- // // diff --git a/widget/src/mac/nsMacWindow.h b/widget/src/mac/nsMacWindow.h index a7cab109ac86..79bcab74e576 100644 --- a/widget/src/mac/nsMacWindow.h +++ b/widget/src/mac/nsMacWindow.h @@ -78,6 +78,7 @@ public: NS_IMETHOD Show(PRBool aState); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint); + NS_IMETHOD GetScreenBounds(nsRect &aRect); virtual PRBool OnPaint(nsPaintEvent &event); NS_IMETHOD SetTitle(const nsString& aTitle);