* Source/NSMenuView.m (-setWindowFrameForAttachingToRect:...):

This method mixed user space and window base coordinates in some
places, which I fixed.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@32888 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-04-18 21:10:55 +00:00
parent 4e9b578bc5
commit 3067b0465d
2 changed files with 41 additions and 31 deletions

View file

@ -1,3 +1,9 @@
2011-04-18 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSMenuView.m (-setWindowFrameForAttachingToRect:...):
This method mixed user space and window base coordinates in some
places, which I fixed.
2011-04-18 Eric Wasylishen <ewasylishen@gmail.com> 2011-04-18 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSView.m (-_rebuildCoordinates): Remove assumption that * Source/NSView.m (-_rebuildCoordinates): Remove assumption that

View file

@ -1093,7 +1093,11 @@ static NSMapTable *viewInfo = 0;
int items = [_itemCells count]; int items = [_itemCells count];
BOOL growHeight = YES; BOOL growHeight = YES;
BOOL resizeCell = NO; BOOL resizeCell = NO;
BOOL resizeScreenRect = NO; CGFloat borderOffsetInBaseCoords;
// Our window needs to have a nonzero size for the
// -convertRect:fromView: and relatead methods to work.
[_window setFrame: NSMakeRect(0,0,1,1) display: NO];
// Make sure the menu entries are up to date // Make sure the menu entries are up to date
[self update]; [self update];
@ -1131,36 +1135,31 @@ static NSMapTable *viewInfo = 0;
} }
} }
// Convert the screen rect to our view cellFrame = screenRect;
cellFrame.size = screenRect.size;
cellFrame.origin = [_window convertScreenToBase: screenRect.origin];
cellFrame = [self convertRect: cellFrame fromView: nil];
/* /*
we should have the calculated cell size, grow the width we should have the calculated cell size, grow the width
if needed to match the screenRect and vice versa if needed to match the screenRect and vice versa
*/ */
if (cellFrame.size.width > _cellSize.width) if (cellFrame.size.width > [self convertSizeToBase: _cellSize].width)
{ {
_cellSize.width = cellFrame.size.width; _cellSize.width = [self convertSizeFromBase: cellFrame.size].width;
resizeCell = YES; resizeCell = YES;
} }
else else
{ {
cellFrame.size.width = _cellSize.width; cellFrame.size.width = [self convertSizeToBase: _cellSize].width;
resizeScreenRect = YES;
} }
/* certain pop-ups don't want the height resized */ /* certain pop-ups don't want the height resized */
if (growHeight && cellFrame.size.height > _cellSize.height) if (growHeight && cellFrame.size.height > [self convertSizeToBase: _cellSize].height)
{ {
_cellSize.height = cellFrame.size.height; _cellSize.height = [self convertSizeFromBase: cellFrame.size].height;
resizeCell = YES; resizeCell = YES;
} }
else else
{ {
cellFrame.size.height = _cellSize.height; cellFrame.size.height = [self convertSizeToBase: _cellSize].height;
resizeScreenRect = YES;
} }
/* /*
@ -1170,16 +1169,13 @@ static NSMapTable *viewInfo = 0;
if (resizeCell) if (resizeCell)
[self sizeToFit]; [self sizeToFit];
if (resizeScreenRect)
{
cellFrame = [self convertRect: cellFrame toView: nil];
}
/* /*
* Compute the frame * Compute the frame. popUpFrame is in screen coordinates
*/ */
popUpFrame.origin = screenRect.origin; popUpFrame = cellFrame;
popUpFrame.size = cellFrame.size;
borderOffsetInBaseCoords = [self convertSizeToBase: NSMakeSize(_leftBorderOffset, 0)].width;
if (items > 0) if (items > 0)
{ {
float f; float f;
@ -1187,10 +1183,10 @@ static NSMapTable *viewInfo = 0;
if (_horizontal == NO) if (_horizontal == NO)
{ {
f = cellFrame.size.height * (items - 1); f = cellFrame.size.height * (items - 1);
popUpFrame.size.height += f + _leftBorderOffset; popUpFrame.size.height += f + borderOffsetInBaseCoords;
popUpFrame.origin.y -= f; popUpFrame.origin.y -= f;
popUpFrame.size.width += _leftBorderOffset; popUpFrame.size.width += borderOffsetInBaseCoords;
popUpFrame.origin.x -= _leftBorderOffset; popUpFrame.origin.x -= borderOffsetInBaseCoords;
// If the menu is a pull down menu the first item, which would // If the menu is a pull down menu the first item, which would
// appear at the top of the menu, holds the title and is omitted // appear at the top of the menu, holds the title and is omitted
@ -1314,11 +1310,19 @@ static NSMapTable *viewInfo = 0;
} }
// Get the frameRect // Get the frameRect
r = [NSWindow frameRectForContentRect: popUpFrame {
styleMask: [_window styleMask]]; NSSize contentSize = [self convertSizeFromBase: popUpFrame.size];
NSRect contentRect = NSMakeRect(popUpFrame.origin.x,
popUpFrame.origin.y,
contentSize.width,
contentSize.height);
r = [_window frameRectForContentRect: contentRect];
// Set the window frame
// Set the window frame. r should be identical to popUpFrame except with
// any borders the window wanted to add.
[_window setFrame: r display: NO]; [_window setFrame: r display: NO];
}
} }
/* /*