From e1c938bc73510d64b908408bf404eb10a419001e Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Fri, 30 Oct 2009 18:35:16 +0000 Subject: [Author: thomasvl] Add a helper for doing view resizing without resizing subviews. Fix the fixed width call to not change the width. Update the unittest to make sure the fixed width call doesn't change the width. R=stuartmorgan,dmaclach DELTA=41 (30 added, 0 deleted, 11 changed) --- AppKit/GTMUILocalizerAndLayoutTweaker.h | 12 +++++++----- AppKit/GTMUILocalizerAndLayoutTweaker.m | 20 ++++++++++++++++++++ AppKit/GTMUILocalizerAndLayoutTweakerTest.m | 3 +++ AppKit/GTMUILocalizerAndLayoutTweakerTest3.xib | 4 ++-- .../GTMUILocalizerAndLayoutTweakerTest3-0.tiff | Bin 9234 -> 8652 bytes .../GTMUILocalizerAndLayoutTweakerTest3-1.tiff | Bin 15754 -> 9252 bytes .../GTMUILocalizerAndLayoutTweakerTest3-2.tiff | Bin 16292 -> 15768 bytes .../GTMUILocalizerAndLayoutTweakerTest3-3.tiff | Bin 19996 -> 16290 bytes .../GTMUILocalizerAndLayoutTweakerTest3-4.tiff | Bin 0 -> 20016 bytes 9 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-4.tiff (limited to 'AppKit') diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.h b/AppKit/GTMUILocalizerAndLayoutTweaker.h index abcb758..3c5c864 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweaker.h +++ b/AppKit/GTMUILocalizerAndLayoutTweaker.h @@ -42,7 +42,7 @@ // This checks to see if |view| implements @selector(sizeToFit) and calls it. // It then checks the class of |view| and does some fixup for known issues -// where sizeToFit doesn't product a view that meets UI guidelines. +// where sizeToFit doesn't produce a view that meets UI guidelines. // Returns the amount the view changed in size. + (NSSize)sizeToFitView:(NSView *)view; @@ -60,13 +60,15 @@ + (void)wrapButtonTitleForWidth:(NSButton *)button; + (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup; -// Resizes |window| by |delta| without letting the subviews of |window| get +// Resizes |window| or |view| by |delta| without letting the subviews get // resized. Useful when you've done manual tweaking by things like -// +sizeToFitFixedWidthTextField. The window's origin is not adjusted. Passes -// |NO| to for -setFrame:display:'s |displayViews| flag on the assumptions -// the caller is doing all the invals/updates needed. +// +sizeToFitFixedWidthTextField. The origin is not adjusted. For windows, +// passes |NO| to for -setFrame:display:'s |displayViews| flag on the +// assumptions the caller is doing all the invals/updates needed. + (void)resizeWindowWithoutAutoResizingSubViews:(NSWindow*)window delta:(NSSize)delta; ++ (void)resizeViewWithoutAutoResizingSubViews:(NSView*)view + delta:(NSSize)delta; @end diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m index dca167a..382871c 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweaker.m +++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m @@ -223,6 +223,7 @@ static BOOL IsRightAnchored(NSView *view); NSRect initialFrame = [textField frame]; NSRect sizeRect = NSMakeRect(0, 0, NSWidth(initialFrame), CGFLOAT_MAX); NSSize newSize = [[textField cell] cellSizeForBounds:sizeRect]; + newSize.width = NSWidth(initialFrame); [textField setFrameSize:newSize]; return newSize.height - NSHeight(initialFrame); } @@ -278,6 +279,25 @@ static BOOL IsRightAnchored(NSView *view); } } ++ (void)resizeViewWithoutAutoResizingSubViews:(NSView*)view + delta:(NSSize)delta { + // Clear autosizesSubviews (saving the state). + BOOL autoresizesSubviews = [view autoresizesSubviews]; + if (autoresizesSubviews) { + [view setAutoresizesSubviews:NO]; + } + + NSRect rect = [view frame]; + rect.size.width += delta.width; + rect.size.height += delta.height; + [view setFrame:rect]; + + // Restore autosizesSubviews. + if (autoresizesSubviews) { + [view setAutoresizesSubviews:YES]; + } +} + @end @implementation GTMWidthBasedTweaker diff --git a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m index 51dd9ff..5d2375f 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m +++ b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m @@ -63,7 +63,10 @@ static NSUInteger gTestPass = 0; // In the xib, the one field is over sized, the other is undersized, this // way we make sure the code handles both condions as there was a bahavior // change between the 10.4 and 10.5 SDKs. + // The right field is also right aligned to make sure the width of the text + // field stays constant. NSString *kTestStrings[] = { + @"The fox jumps the dog.", @"The quick brown fox jumps over the lazy dog.", @"The quick brown fox jumps over the lazy dog. The quick brown fox jumps " @"over the lazy dog. The quick brown fox jumps over the lazy dog. " diff --git a/AppKit/GTMUILocalizerAndLayoutTweakerTest3.xib b/AppKit/GTMUILocalizerAndLayoutTweakerTest3.xib index d0e3e21..36a6fc5 100644 --- a/AppKit/GTMUILocalizerAndLayoutTweakerTest3.xib +++ b/AppKit/GTMUILocalizerAndLayoutTweakerTest3.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -93,7 +93,7 @@ YES 67239424 - 272891904 + 71565312 Multiline Label diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff index 6ea28e6..30c2a89 100644 Binary files a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff and b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff differ diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff index fb0826c..d949898 100644 Binary files a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff and b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff differ diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff index a9640a0..2d51e31 100644 Binary files a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff and b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff differ diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff index 7f2f0a9..eb7b8fa 100644 Binary files a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff and b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff differ diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-4.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-4.tiff new file mode 100644 index 0000000..041b683 Binary files /dev/null and b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-4.tiff differ -- cgit v1.2.3