aboutsummaryrefslogtreecommitdiff
path: root/AppKit
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-08-27 16:45:23 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-08-27 16:45:23 +0000
commit4203884610ea0e0621aafdf5cced614447dbcd5e (patch)
tree05a08f840ba265cc01fc252e5c6e6db3d0731fa2 /AppKit
parent66fc63df47cd6714ca8ff034ae3f54de5ef58ea9 (diff)
[Author: thomasvl]
Update the textfield fixed width code to work with 10.5 (vs. 10.4 due to a change on apple's end). Add a unittest that captures the edge case. R=stuartmorgan,dmaclach DELTA=72 (66 added, 1 deleted, 5 changed)
Diffstat (limited to 'AppKit')
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweaker.m9
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweakerTest.m44
-rw-r--r--AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiffbin0 -> 9234 bytes
-rw-r--r--AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiffbin0 -> 15754 bytes
-rw-r--r--AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiffbin0 -> 16292 bytes
-rw-r--r--AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiffbin0 -> 19996 bytes
6 files changed, 47 insertions, 6 deletions
diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m
index d7494b2..1b5d8aa 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweaker.m
+++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m
@@ -92,11 +92,10 @@ static BOOL IsRightAnchored(NSView *view);
+ (CGFloat)sizeToFitFixedWidthTextField:(NSTextField *)textField {
NSRect initialFrame = [textField frame];
- NSSize newSize = [[textField cell] cellSizeForBounds:initialFrame];
- NSRect newFrame = initialFrame;
- newFrame.size.height = newSize.height;
- [textField setFrame:newFrame];
- return initialFrame.size.height - newSize.height;
+ NSRect sizeRect = NSMakeRect(0, 0, NSWidth(initialFrame), CGFLOAT_MAX);
+ NSSize newSize = [[textField cell] cellSizeForBounds:sizeRect];
+ [textField setFrameSize:newSize];
+ return newSize.height - NSHeight(initialFrame);
}
@end
diff --git a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m
index 10e83b1..e6320d5 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweakerTest.m
+++ b/AppKit/GTMUILocalizerAndLayoutTweakerTest.m
@@ -19,7 +19,7 @@
#import "GTMSenTestCase.h"
#import "GTMUILocalizerAndLayoutTweakerTest.h"
#import "GTMNSObject+UnitTesting.h"
-#import "GTMUILocalizer.h"
+#import "GTMUILocalizerAndLayoutTweaker.h"
static NSUInteger gTestPass = 0;
@@ -58,6 +58,48 @@ static NSUInteger gTestPass = 0;
}
}
+- (void)testSizeToFitFixedWidthTextField {
+ // 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.
+ NSString *kTestStrings[] = {
+ @"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. "
+ @"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.\nThe quick brown fox jumps "
+ @"over the lazy dog.\nThe quick brown fox jumps over the lazy dog.\n"
+ @"The quick brown fox jumps over the lazy dog.\nThe 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.\nThe 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. The quick brown fox jumps over the lazy dog.\n\nThe End.",
+ };
+ for (size_t lp = 0; lp < (sizeof(kTestStrings) / sizeof(NSString*)); ++lp) {
+ GTMUILocalizerAndLayoutTweakerTestWindowController *controller =
+ [[GTMUILocalizerAndLayoutTweakerTestWindowController alloc]
+ initWithWindowNibName:@"GTMUILocalizerAndLayoutTweakerTest3"];
+ NSWindow *window = [controller window];
+ STAssertNotNil(window, @"Pass %ld", (long)lp);
+ NSTextField *field;
+ GTM_FOREACH_OBJECT(field, [[window contentView] subviews]) {
+ STAssertTrue([field isMemberOfClass:[NSTextField class]],
+ @"Pass %ld", (long)lp);
+ [field setStringValue:kTestStrings[lp]];
+ [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:field];
+ }
+ NSString *imageName =
+ [NSString stringWithFormat:@"GTMUILocalizerAndLayoutTweakerTest3-%ld",
+ (long)lp];
+ GTMAssertObjectImageEqualToImageNamed(window, imageName,
+ @"Pass %ld", (long)lp);
+ [controller release];
+ }
+}
+
@end
@implementation GTMUILocalizerAndLayoutTweakerTestWindowController
diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff
new file mode 100644
index 0000000..6ea28e6
--- /dev/null
+++ b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-0.tiff
Binary files differ
diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff
new file mode 100644
index 0000000..fb0826c
--- /dev/null
+++ b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-1.tiff
Binary files differ
diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff
new file mode 100644
index 0000000..a9640a0
--- /dev/null
+++ b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-2.tiff
Binary files differ
diff --git a/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff
new file mode 100644
index 0000000..7f2f0a9
--- /dev/null
+++ b/AppKit/TestData/GTMUILocalizerAndLayoutTweakerTest3-3.tiff
Binary files differ