diff --git a/AppKit/CPMenu/_CPMenuWindow.j b/AppKit/CPMenu/_CPMenuWindow.j index 531c745ba..77b8a40a8 100644 --- a/AppKit/CPMenu/_CPMenuWindow.j +++ b/AppKit/CPMenu/_CPMenuWindow.j @@ -90,16 +90,17 @@ var STICKY_TIME_INTERVAL = 500, - (id)init { self = [super initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessWindowMask]; - + if (self) { [self setLevel:CPPopUpMenuWindowLevel]; [self setHasShadow:YES]; [self setShadowStyle:CPMenuWindowShadowStyle]; [self setAcceptsMouseMovedEvents:YES]; - + + _constraintRect = _CGRectMakeZero(); _unconstrainedFrame = CGRectMakeZero(); - + var contentView = [self contentView]; _menuView = [[_CPMenuView alloc] initWithFrame:CGRectMakeZero()]; @@ -232,7 +233,7 @@ var STICKY_TIME_INTERVAL = 500, - (void)orderFront:(id)aSender { - [self setFrameWithConstraint:_unconstrainedFrame]; + [self setFrame:_unconstrainedFrame]; [super orderFront:aSender]; } @@ -240,6 +241,8 @@ var STICKY_TIME_INTERVAL = 500, - (void)setConstraintRect:(CGRect)aRect { _constraintRect = aRect; + + [self setFrame:_unconstrainedFrame]; } - (void)scrollUp @@ -249,7 +252,7 @@ var STICKY_TIME_INTERVAL = 500, _unconstrainedFrame.origin.y += 10; - [self setFrameWithConstraint:_unconstrainedFrame]; + [self setFrame:_unconstrainedFrame]; } - (void)scrollDown @@ -259,49 +262,44 @@ var STICKY_TIME_INTERVAL = 500, _unconstrainedFrame.origin.y -= 10; - [self setFrameWithConstraint:_unconstrainedFrame]; + [self setFrame:_unconstrainedFrame]; +} + +- (CGRect)unconstrainedFrame +{ + return _unconstrainedFrame; +} + +// We need this because if not this will call setFrame: with -frame instead of -unconstrainedFrame, turning +// the constrained frame into the unconstrained frame. +- (void)setFrameOrigin:(CGPoint)aPoint +{ + [super setFrame:_CGRectMake(aPoint.x, aPoint.y, _CGRectGetWidth(_unconstrainedFrame), _CGRectGetHeight(_unconstrainedFrame))]; } - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate { - [super setFrame:aFrame display:shouldDisplay animate:shouldAnimate]; - - if (!window.letitbe) - { - _unconstrainedFrame = aFrame; - console.log("setting unconstrained frame to : " + CPStringFromRect(_unconstrainedFrame)); - } - else - console.log("in here for some reason"); -} - -- (void)setFrameWithConstraint:(CGRect)aFrame -{console.log("setFrameWithConstraint:"); // FIXME: There are integral window issues with platform windows. // FIXME: This gets called far too often. - _unconstrainedFrame = aFrame; + _unconstrainedFrame = _CGRectMakeCopy(aFrame); - var isBrowser = [CPPlatform isBrowser], - visibleFrame = CGRectInset(isBrowser ? [[self platformWindow] contentBounds] : [[self screen] visibleFrame], 5.0, 5.0), - constrainedFrame = CGRectIntersection(_unconstrainedFrame, visibleFrame); + var constrainedFrame = CGRectIntersection(_unconstrainedFrame, _constraintRect); // We don't want to simply intersect the visible frame and the unconstrained frame. // We should be allowing as much of the width to fit as possible (pushing back and forward). constrainedFrame.origin.x = CGRectGetMinX(_unconstrainedFrame); constrainedFrame.size.width = CGRectGetWidth(_unconstrainedFrame); - if (CGRectGetWidth(constrainedFrame) > CGRectGetWidth(visibleFrame)) - constrainedFrame.size.width = CGRectGetWidth(visibleFrame); + if (CGRectGetWidth(constrainedFrame) > CGRectGetWidth(_constraintRect)) + constrainedFrame.size.width = CGRectGetWidth(_constraintRect); - if (CGRectGetMaxX(constrainedFrame) > CGRectGetMaxX(visibleFrame)) - constrainedFrame.origin.x -= CGRectGetMaxX(constrainedFrame) - CGRectGetMaxX(visibleFrame); + if (CGRectGetMaxX(constrainedFrame) > CGRectGetMaxX(_constraintRect)) + constrainedFrame.origin.x -= CGRectGetMaxX(constrainedFrame) - CGRectGetMaxX(_constraintRect); - if (CGRectGetMinX(constrainedFrame) < CGRectGetMinX(visibleFrame)) - constrainedFrame.origin.x = CGRectGetMinX(visibleFrame); + if (CGRectGetMinX(constrainedFrame) < CGRectGetMinX(_constraintRect)) + constrainedFrame.origin.x = CGRectGetMinX(_constraintRect); - window.letitbe = true; - [self setFrame:constrainedFrame]; - window.letitbe = false; + [super setFrame:constrainedFrame display:shouldDisplay animate:shouldAnimate]; // This needs to happen before changing the frame. var menuViewOrigin = CGPointMake(CGRectGetMinX(aFrame) + LEFT_MARGIN, CGRectGetMinY(aFrame) + TOP_MARGIN), @@ -429,7 +427,7 @@ var STICKY_TIME_INTERVAL = 500, _menuWindowStack.push(menuWindow); - [menuWindow setConstraintRect:CGRectInset([CPPlatform isBrowser] ? [[self platformWindow] contentBounds] : [[self screen] visibleFrame], 5.0, 5.0)]; + [menuWindow setConstraintRect:_constraintRect]; [menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle]; [menuWindow setFrameOrigin:aGlobalLocation]; [menuWindow orderFront:self]; diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j index afe5f8f1e..bbcb90097 100644 --- a/AppKit/CPPopUpButton.j +++ b/AppKit/CPPopUpButton.j @@ -638,7 +638,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); { if (![self isEnabled] || ![self numberOfItems]) return; - + [self highlight:YES]; var menu = [self menu], @@ -647,11 +647,13 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); [menuWindow setDelegate:self]; [menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle]; - + + var bounds = [self bounds]; + // Pull Down Menus show up directly below their buttons. if ([self pullsDown]) - var menuOrigin = [theWindow convertBaseToGlobal:[self convertPoint:CGPointMake(0.0, CGRectGetMaxY([self bounds])) toView:nil]]; - + var menuOrigin = [theWindow convertBaseToGlobal:[self convertPoint:CGPointMake(0.0, CGRectGetMaxY(bounds)) toView:nil]]; + // Pop Up Menus attempt to show up "on top" of the selected item. else { @@ -660,21 +662,22 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); // 1. So calculate where our content is, then calculate where the menu item is. // 2. Move LEFT by whatever indentation we have (offsetWidths, aka, window margin, item margin, etc). // 3. MOVE UP by the difference in sizes of the content and menu item, this will only work if the content is vertically centered. - var contentRect = [self convertRect:[self contentRectForBounds:[self bounds]] toView:nil], + var contentRect = [self convertRect:[self contentRectForBounds:bounds] toView:nil], menuOrigin = [theWindow convertBaseToGlobal:contentRect.origin], menuItemRect = [menuWindow rectForItemAtIndex:_selectedIndex]; - + menuOrigin.x -= CGRectGetMinX(menuItemRect) + [menuWindow overlapOffsetWidth] + [[[menu itemAtIndex:_selectedIndex] _menuItemView] overlapOffsetWidth]; menuOrigin.y -= CGRectGetMinY(menuItemRect) + (CGRectGetHeight(menuItemRect) - CGRectGetHeight(contentRect)) / 2.0; } [menuWindow setFrameOrigin:menuOrigin]; - var menuMaxX = CGRectGetMaxX([menuWindow frame]), - buttonMaxX = [theWindow convertBaseToGlobal:CGPointMake(CGRectGetMaxX([self convertRect:[self bounds] toView:nil]), 0.0)].x; + var menuWindowFrame = [menuWindow unconstrainedFrame], + menuMaxX = CGRectGetMaxX(menuWindowFrame), + buttonMaxX = [theWindow convertBaseToGlobal:CGPointMake(CGRectGetMaxX([self convertRect:bounds toView:nil]), 0.0)].x; if (menuMaxX < buttonMaxX) - [menuWindow setMinWidth:CGRectGetWidth([menuWindow frame]) + buttonMaxX - menuMaxX - ([self pullsDown] ? 0.0 : VISIBLE_MARGIN)]; + [menuWindow setMinWidth:CGRectGetWidth(menuWindowFrame) + buttonMaxX - menuMaxX - ([self pullsDown] ? 0.0 : VISIBLE_MARGIN)]; [menuWindow orderFront:self]; [menuWindow beginTrackingWithEvent:anEvent sessionDelegate:self didEndSelector:@selector(menuWindowDidFinishTracking:highlightedItem:)]; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 9143c17f2..65cebee65 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -610,6 +610,8 @@ CPTexturedBackgroundWindowMask */ - (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate { + aFrame = _CGRectMakeCopy(aFrame); + var value = aFrame.origin.x, delta = value - FLOOR(value);