* Source/NSWindow.m (-constrainFrameRect:toScreen:) Handle

screen being nil and resize only if moving is not enough.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@39126 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2015-11-02 21:14:11 +00:00
parent eec45ae8a9
commit cd9a83f6ed
2 changed files with 79 additions and 32 deletions

View file

@ -1,3 +1,8 @@
2015-11-02 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSWindow.m (-constrainFrameRect:toScreen:) Handle screen
being nil and resize only if moving is not enough.
2015-11-02 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSOutlineView.m:

View file

@ -2096,47 +2096,89 @@ titleWithRepresentedFilename(NSString *representedFilename)
*/
- (NSRect) constrainFrameRect: (NSRect)frameRect toScreen: (NSScreen*)screen
{
NSRect screenRect = [screen visibleFrame];
NSRect screenRect;
CGFloat difference;
if (nil == screen)
{
return frameRect;
}
screenRect = [screen visibleFrame];
if (NSHeight(frameRect) < NSHeight(screenRect))
{
/* Move top edge of the window inside the screen */
difference = NSMaxY (frameRect) - NSMaxY (screenRect);
if (difference > 0)
{
frameRect.origin.y -= difference;
}
else
{
/* Move bottom edge of the window inside the screen */
difference = screenRect.origin.y - frameRect.origin.y;
if (difference > 0)
{
frameRect.origin.y += difference;
}
}
}
else
{
/* If the window is resizable, resize it so that
it fits on the screen. */
if (_styleMask & NSResizableWindowMask)
{
/* Ensure that resizing doesn't make window smaller than minimum */
if (_minimumSize.height < NSHeight(screenRect))
{
frameRect.origin.y = NSMinY(screenRect);
frameRect.size.height = NSHeight(screenRect);
}
else
{
frameRect.origin.y = NSMaxY(screenRect) - _minimumSize.height;
frameRect.size.height = _minimumSize.height;
}
}
}
/* Adjust X origin, if needed */
if (NSWidth(frameRect) < NSWidth(screenRect))
{
/* Move right edge of the window inside the screen */
difference = NSMaxX (frameRect) - NSMaxX (screenRect);
if (difference > 0)
{
frameRect.origin.x -= difference;
}
/* If the window is resizable, resize it (if needed) so that the
bottom edge is on the screen or can be on the screen when the user moves
the window */
difference = NSMaxY (screenRect) - NSMaxY (frameRect);
else
{
/* Move left edge of the window inside the screen */
difference = screenRect.origin.x - frameRect.origin.x;
if (difference > 0)
{
frameRect.origin.x += difference;
}
}
}
else
{
/* If the window is resizable, resize it so that
it fits on the screen. */
if (_styleMask & NSResizableWindowMask)
{
CGFloat difference2;
difference2 = screenRect.origin.y - frameRect.origin.y;
difference2 -= difference;
// Take in account the space between the top of window and the top of the
// screen which can be used to move the bottom of the window on the screen
if (difference2 > 0)
{
frameRect.size.height -= difference2;
frameRect.origin.y += difference2;
}
/* Ensure that resizing doesn't make window smaller than minimum */
difference2 = _minimumSize.height - frameRect.size.height;
if (difference2 > 0)
if (_minimumSize.width < NSWidth(screenRect))
{
frameRect.size.height += difference2;
frameRect.origin.y -= difference2;
frameRect.origin.x = NSMinX(screenRect);
frameRect.size.width = NSWidth(screenRect);
}
else
{
frameRect.origin.x = NSMaxX(screenRect) - _minimumSize.width;
frameRect.size.width = _minimumSize.width;
}
}
}