aboutsummaryrefslogtreecommitdiff
path: root/AppKit/GTMUILocalizerAndLayoutTweaker.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-02 20:30:38 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-02 20:30:38 +0000
commit4ee3b1359f5407ad4bb552bcc1c563970d355017 (patch)
tree7a32b511367746f60b003ad9cec7811dbec56d95 /AppKit/GTMUILocalizerAndLayoutTweaker.m
parenta8ff4e805f875b8d565df63ad1e9fd56e699b3e1 (diff)
[Author: thomasvl]
Add another window to the UILocalizer unittest that puts a bunch of items into boxes, splitters, and scroll views to make sure they are working. Support some NSBox attributes in AppKit+UnitTesting. Update the size to fit code to only special case regular push buttons and not other types of buttons. Update the expectations due to this change. Add a new unittest to test all button styles and sizes. Update how we decided to do vertical or horizontal layout on a width box because left aligning things is visual and doesn't actually align their frames, so instead we do a rect intersection instead. Added in the CompilerSDK on Mac OS builds to the paths searches. Update the comments on how paths are searched to be correct. R=dmaclach,stuartmorgan DELTA=2709 (2643 added, 8 deleted, 58 changed)
Diffstat (limited to 'AppKit/GTMUILocalizerAndLayoutTweaker.m')
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweaker.m41
1 files changed, 24 insertions, 17 deletions
diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m
index b8c6499..91c6ffc 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweaker.m
+++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m
@@ -26,7 +26,7 @@
static NSSize SizeToFit(NSView *view, NSPoint offset);
// Compare function for -[NSArray sortedArrayUsingFunction:context:]
static NSInteger CompareFrameX(id view1, id view2, void *context);
-// Check if the view is anchored on the right (fixed right, flexable left).
+// Check if the view is anchored on the right (fixed right, flexible left).
static BOOL IsRightAnchored(NSView *view);
@interface GTMUILocalizerAndLayoutTweaker (PrivateMethods)
@@ -122,9 +122,13 @@ static BOOL IsRightAnchored(NSView *view);
NSMutableArray *rightAlignedSubViews = nil;
NSMutableArray *rightAlignedSubViewDeltas = nil;
if ([subviews count] > 1) {
- // Do they share left edges (within a pixel)
- if (fabs(NSMinX([[subviews objectAtIndex:0] frame]) -
- NSMinX([[subviews objectAtIndex:1] frame])) > 1.0) {
+ // Check if the frames are in a row by seeing if when they are left aligned
+ // they overlap. If they don't overlap in this case, it means they are
+ // probably stacked instead.
+ NSRect rect1 = [[subviews objectAtIndex:0] frame];
+ NSRect rect2 = [[subviews objectAtIndex:1] frame];
+ rect1.origin.x = rect2.origin.x = 0;
+ if (NSIntersectsRect(rect1, rect2)) {
// No, so walk them x order moving them along so they don't overlap.
sumMode = YES;
subviews = [subviews sortedArrayUsingFunction:CompareFrameX context:NULL];
@@ -259,7 +263,6 @@ static NSSize SizeToFit(NSView *view, NSPoint offset) {
// to what is in them as they are for users to enter things so honor their
// current size.
} else {
-
// Genericaly fire a sizeToFit if it has one.
if ([view respondsToSelector:@selector(sizeToFit)]) {
[view performSelector:@selector(sizeToFit)];
@@ -267,19 +270,23 @@ static NSSize SizeToFit(NSView *view, NSPoint offset) {
newFrame = fitFrame;
}
- // -[NSButton sizeToFit] gives much worse results than IB's Size to Fit
- // option. This is the amount of padding IB adds over a sizeToFit,
- // empirically determined.
- // TODO: We need to check the type of button before doing this.
if ([view isKindOfClass:[NSButton class]]) {
- const float kExtraPaddingAmount = 12;
- // Width is tricky, new buttons in IB are 96 wide, Carbon seems to have
- // defaulted to 70, Cocoa seems to like 82. But we go with 96 since
- // that's what IB is doing these days.
- const float kMinButtonWidth = 96;
- newFrame.size.width = NSWidth(newFrame) + kExtraPaddingAmount;
- if (NSWidth(newFrame) < kMinButtonWidth) {
- newFrame.size.width = kMinButtonWidth;
+ NSButton *button = (NSButton *)view;
+ // -[NSButton sizeToFit] gives much worse results than IB's Size to Fit
+ // option for standard push buttons.
+ if (([button bezelStyle] == NSRoundedBezelStyle) &&
+ ([[button cell] controlSize] == NSRegularControlSize)) {
+ // This is the amount of padding IB adds over a sizeToFit, empirically
+ // determined.
+ const CGFloat kExtraPaddingAmount = 12.0;
+ // Width is tricky, new buttons in IB are 96 wide, Carbon seems to have
+ // defaulted to 70, Cocoa seems to like 82. But we go with 96 since
+ // that's what IB is doing these days.
+ const CGFloat kMinButtonWidth = (CGFloat)96.0;
+ newFrame.size.width = NSWidth(newFrame) + kExtraPaddingAmount;
+ if (NSWidth(newFrame) < kMinButtonWidth) {
+ newFrame.size.width = kMinButtonWidth;
+ }
}
}
}