implement new method ConstrainPosition. bug 31516 r=saari@netscape.com

This commit is contained in:
danm%netscape.com 2000-08-04 14:48:33 +00:00
Родитель b3dfb63d25
Коммит aef2763295
10 изменённых файлов: 134 добавлений и 47 удалений

Просмотреть файл

@ -554,6 +554,17 @@ NS_IMETHODIMP nsWidget::IsVisible(PRBool &aState)
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWidget::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Move this component
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsWidget::Move(PRInt32 aX, PRInt32 aY)
{
if (mMozBox)

Просмотреть файл

@ -105,6 +105,7 @@ public:
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD IsVisible(PRBool &aState);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth,

Просмотреть файл

@ -73,6 +73,8 @@ extern "C" int usleep(unsigned int);
#define WANT_PAINT_FLASHING \
(CAPS_LOCK_IS_ON && debug_WantPaintFlashing())
#define kWindowPositionSlop 10
gint handle_toplevel_focus_in (
GtkWidget * aWidget,
GdkEventFocus * aGdkFocusEvent,
@ -2568,6 +2570,24 @@ NS_IMETHODIMP nsWindow::CaptureMouse(PRBool aCapture)
return NS_OK;
}
NS_IMETHODIMP nsWindow::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
if (mIsToplevel && mShell)
{
PRInt32 screenWidth = gdk_screen_width();
PRInt32 screenHeight = gdk_screen_height();
if (*aX < kWindowPositionSlop - mBounds.width)
*aX = kWindowPositionSlop - mBounds.width;
if (*aX > screenWidth - kWindowPositionSlop)
*aX = screenWidth - kWindowPositionSlop;
if (*aY < kWindowPositionSlop - mBounds.height)
*aY = kWindowPositionSlop - mBounds.height;
if (*aY > screenHeight - kWindowPositionSlop)
*aY = screenHeight - kWindowPositionSlop;
}
return NS_OK;
}
NS_IMETHODIMP nsWindow::Move(PRInt32 aX, PRInt32 aY)
{
mBounds.x = aX;
@ -2575,15 +2595,15 @@ NS_IMETHODIMP nsWindow::Move(PRInt32 aX, PRInt32 aY)
if (mIsToplevel && mShell)
{
#ifdef DEBUG
// complain if a window is moved offscreen (legal, but potentially worrisome)
PRInt32 screenWidth = gdk_screen_width();
PRInt32 screenHeight = gdk_screen_height();
if(aX >= screenWidth)
aX = screenWidth - mBounds.width;
if(aY >= screenHeight)
aY = screenHeight - mBounds.height;
// no annoying assertions. just mention the issue.
if (aX < 0 || aX >= screenWidth || aY < 0 || aY >= screenHeight)
printf("window moved to offscreen position\n");
#endif
// do it the way it should be done period.
if (mParent && mWindowType == eWindowType_popup) {
// *VERY* stupid hack to make gfx combo boxes work

Просмотреть файл

@ -65,6 +65,7 @@ public:
NS_IMETHOD Show(PRBool aShow);
NS_IMETHOD CaptureMouse(PRBool aCapture);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);

Просмотреть файл

@ -55,6 +55,8 @@ static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
// Windows and Mac.
#define WINDOW_SIZE_TWEAKING
#define kWindowPositionSlop 10
// ¥¥¥ 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;
@ -553,6 +555,47 @@ NS_METHOD nsWindow::Restore(void)
}
*/
NS_IMETHODIMP nsMacWindow::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
if (eWindowType_popup == mWindowType || !mWindowMadeHere)
return NS_OK;
// Sanity check against screen size
// make sure the window stays visible
Rect screenRect;
::GetRegionBounds(::GetGrayRgn(), &screenRect);
// Need to use non-negative coordinates
PRInt32 screenWidth;
if(screenRect.left < 0)
screenWidth = screenRect.right - screenRect.left;
else
screenWidth = screenRect.right;
PRInt32 screenHeight;
if(screenRect.top < 0)
screenHeight = screenRect.bottom - screenRect.top;
else
screenHeight = screenRect.bottom;
Rect portBounds;
::GetWindowPortBounds(mWindowPtr, &portBounds);
short windowWidth = portBounds.right - portBounds.left;
short windowHeight = portBounds.bottom - portBounds.top;
if (*aX <= screenRect.left - windowWidth + kWindowPositionSlop)
*aX = screenRect.left - windowWidth + kWindowPositionSlop;
else if (*aX >= screenWidth - kWindowPositionSlop)
*aX = screenWidth - kWindowPositionSlop;
if (*aY < 0) // position is relative to screenRect.top
*aY = 0;
else if (*aY >= screenHeight - screenRect.top - kWindowPositionSlop)
*aY = screenHeight - screenRect.top - kWindowPositionSlop;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Move this window
@ -565,8 +608,8 @@ NS_IMETHODIMP nsMacWindow::Move(PRInt32 aX, PRInt32 aY)
{
if (eWindowType_popup == mWindowType) {
PRInt32 xOffset=0,yOffset=0;
nsRect localRect,globalRect;
PRInt32 xOffset=0,yOffset=0;
nsRect localRect,globalRect;
// convert to screen coordinates
localRect.x = aX;
@ -583,43 +626,16 @@ NS_IMETHODIMP nsMacWindow::Move(PRInt32 aX, PRInt32 aY)
return NS_OK;
} else if (mWindowMadeHere){
// Sanity check against screen size
// make sure the window stays visible
Rect screenRect;
::GetRegionBounds(::GetGrayRgn(), &screenRect);
// Need to use non-negative coordinates
PRInt32 screenWidth;
if(screenRect.left < 0)
screenWidth = screenRect.right - screenRect.left;
else
screenWidth = screenRect.right;
PRInt32 screenHeight;
if(screenRect.top < 0)
screenHeight = screenRect.bottom - screenRect.top;
else
screenHeight = screenRect.bottom;
Rect portBounds;
::GetWindowPortBounds(mWindowPtr, &portBounds);
short windowWidth = portBounds.right - portBounds.left;
if (aX <= screenRect.left - windowWidth)
aX = screenRect.left;
else if (aX >= screenWidth)
aX = 0;
if (aY >= screenRect.bottom - screenRect.top)
aY = 0;
if (mIsDialog)
{
if (mIsDialog) {
aX += kDialogMarginWidth;
aY += kDialogTitleBarHeight;
}
else
{
} else {
aX += kWindowMarginWidth;
aY += kWindowTitleBarHeight;
}

Просмотреть файл

@ -78,6 +78,7 @@ public:
nsNativeWidget aNativeParent = nsnull);
NS_IMETHOD Show(PRBool aState);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD PlaceBehind(nsIWidget *aWidget);
NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);

Просмотреть файл

@ -685,6 +685,11 @@ NS_METHOD nsWindow::SetBounds(const nsRect &aRect)
}
NS_IMETHODIMP nsWindow::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Move this component

Просмотреть файл

@ -99,6 +99,7 @@ public:
NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent,
PRBool *aForWindow);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);

Просмотреть файл

@ -72,6 +72,8 @@
#include "nsITimer.h"
#include "nsITimerQueue.h"
#define kWindowPositionSlop 10
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_CID(kTimerManagerCID, NS_TIMERMANAGER_CID);
@ -1244,6 +1246,35 @@ NS_METHOD nsWindow::ModalEventFilter(PRBool aRealEvent, void *aEvent,
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Constrain a potential move to fit onscreen
//
//-------------------------------------------------------------------------
NS_METHOD nsWindow::ConstrainPosition(PRInt32 *aX, PRInt32 *aY)
{
if (mWnd && mIsTopWidgetWindow) { // only a problem for top-level windows
// XXX: Needs multiple monitor support
HDC dc = ::GetDC(mWnd);
if(dc) {
if (::GetDeviceCaps(dc, TECHNOLOGY) == DT_RASDISPLAY) {
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
if (*aX < 0)
*aX = 0;
if (*aX >= workArea.right - kWindowPositionSlop)
*aX = workArea.right - kWindowPositionSlop;
if (*aY < 0)
*aY = 0;
if (*aY >= workArea.bottom - kWindowPositionSlop)
*aY = workArea.bottom - kWindowPositionSlop;
}
::ReleaseDC(mWnd, dc);
}
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Move this component
@ -1286,25 +1317,24 @@ NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY)
mBounds.y = aY;
if (mWnd) {
// make sure this isn't a child window
if (mIsTopWidgetWindow) {
#ifdef DEBUG
// complain if a window is moved offscreen (legal, but potentially worrisome)
if (mIsTopWidgetWindow) { // only a problem for top-level windows
// Make sure this window is actually on the screen before we move it
// XXX: Needs multiple monitor support
HDC dc = ::GetDC(mWnd);
if(dc) {
if (::GetDeviceCaps(dc, TECHNOLOGY) == DT_RASDISPLAY)
{
if (::GetDeviceCaps(dc, TECHNOLOGY) == DT_RASDISPLAY) {
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
if(mBounds.x >= workArea.right)
aX = mBounds.x = workArea.left;
if(mBounds.y >= workArea.bottom)
aY = mBounds.y = workArea.top;
// no annoying assertions. just mention the issue.
if (aX < 0 || aX >= workArea.right || aY < 0 || aY >= workArea.bottom)
printf("window moved to offscreen position\n");
}
::ReleaseDC(mWnd, dc);
}
}
#endif
nsIWidget *par = GetParent();
HDWP deferrer = NULL;

Просмотреть файл

@ -104,6 +104,7 @@ public:
PRBool *aForWindow);
NS_IMETHOD CaptureMouse(PRBool aCapture);
NS_IMETHOD ConstrainPosition(PRInt32 *aX, PRInt32 *aY);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth,
PRInt32 aHeight,