From edb9eb2865f530d6b12f4401d86f4dcae01a0ff9 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Tue, 6 Apr 2010 18:06:35 +0000 Subject: [Author: thomasvl] Add a radar number for the sizeToFit padding issue. Reorder two functions in the impl to match the header. R=dmaclach DELTA=55 (28 added, 27 deleted, 0 changed) --- AppKit/GTMUILocalizerAndLayoutTweaker.m | 59 +++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'AppKit/GTMUILocalizerAndLayoutTweaker.m') diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m index 4aa93c0..5e19cd0 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweaker.m +++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m @@ -44,6 +44,7 @@ NSString * const kForcedWrapString = @"\xA"; // gets as wide, resulting in a clipped control. This fudge factor is what is // added to try and avoid these by giving the size calls just enough slop to // handle the differences. +// radar://7831901 different wrapping between sizeToFit and drawing static const CGFloat kWrapperStringSlop = 0.9; #if GTM_USE_TYPESETTER @@ -247,33 +248,6 @@ static const CGFloat kWrapperStringSlop = 0.9; return newSize.height - NSHeight(initialFrame); } -+ (void)wrapButtonTitleForWidth:(NSButton *)button { - NSCell *cell = [button cell]; - NSRect frame = [button frame]; - - NSRect titleFrame = [cell titleRectForBounds:frame]; - - NSString* newTitle = [self wrapString:[button title] - width:NSWidth(titleFrame) - font:[button font]]; - [button setTitle:newTitle]; -} - -+ (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup { - NSSize cellSize = [radioGroup cellSize]; - NSRect tmpRect = NSMakeRect(0, 0, cellSize.width, cellSize.height); - NSFont *font = [radioGroup font]; - - NSCell *cell; - GTM_FOREACH_OBJECT(cell, [radioGroup cells]) { - NSRect titleFrame = [cell titleRectForBounds:tmpRect]; - NSString* newTitle = [self wrapString:[cell title] - width:NSWidth(titleFrame) - font:font]; - [cell setTitle:newTitle]; - } -} - #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + (CGFloat)sizeToFitFixedHeightTextField:(NSTextField *)textField { @@ -349,6 +323,33 @@ static const CGFloat kWrapperStringSlop = 0.9; #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ++ (void)wrapButtonTitleForWidth:(NSButton *)button { + NSCell *cell = [button cell]; + NSRect frame = [button frame]; + + NSRect titleFrame = [cell titleRectForBounds:frame]; + + NSString* newTitle = [self wrapString:[button title] + width:NSWidth(titleFrame) + font:[button font]]; + [button setTitle:newTitle]; +} + ++ (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup { + NSSize cellSize = [radioGroup cellSize]; + NSRect tmpRect = NSMakeRect(0, 0, cellSize.width, cellSize.height); + NSFont *font = [radioGroup font]; + + NSCell *cell; + GTM_FOREACH_OBJECT(cell, [radioGroup cells]) { + NSRect titleFrame = [cell titleRectForBounds:tmpRect]; + NSString* newTitle = [self wrapString:[cell title] + width:NSWidth(titleFrame) + font:font]; + [cell setTitle:newTitle]; + } +} + + (void)resizeWindowWithoutAutoResizingSubViews:(NSWindow*)window delta:(NSSize)delta { NSView *contentView = [window contentView]; @@ -568,7 +569,7 @@ static NSSize SizeToFit(NSView *view, NSPoint offset) { [view performSelector:@selector(sizeToFit)]; fitFrame = [view frame]; newFrame = fitFrame; - + if ([view isKindOfClass:[NSMatrix class]]) { NSMatrix *matrix = (NSMatrix *)view; // See note on kWrapperStringSlop for why this is done. @@ -581,7 +582,7 @@ static NSSize SizeToFit(NSView *view, NSPoint offset) { } } } - + } if ([view isKindOfClass:[NSButton class]]) { -- cgit v1.2.3