Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (63 sloc) 2.592 kb
68432eb Antonin Hildebrand initial CrashWatcher project as implemented in TotalFinder v1.2.2 (needs...
darwin authored
1 #import "ResizabilityExtensions.h"
2
3 @implementation NSView (ResizabilityExtentions)
4 -(void) breakpad_shiftVertically:(CGFloat)offset {
5 NSPoint origin = [self frame].origin;
6
7 origin.y += offset;
8 [self setFrameOrigin:origin];
9 }
10
11 -(void) breakpad_shiftHorizontally:(CGFloat)offset {
12 NSPoint origin = [self frame].origin;
13
14 origin.x += offset;
15 [self setFrameOrigin:origin];
16 }
17
18 @end
19
20 @implementation NSWindow (ResizabilityExtentions)
21 -(void) breakpad_adjustHeight:(CGFloat)heightDelta {
22 [[self contentView] setAutoresizesSubviews:NO];
23
24 NSRect windowFrame = [self frame];
25 windowFrame.size.height += heightDelta;
26 [self setFrame:windowFrame display:YES];
27 // For some reason the content view is resizing, but not adjusting its origin,
28 // so correct it manually.
29 [[self contentView] setFrameOrigin:NSMakePoint(0, 0)];
30
31 [[self contentView] setAutoresizesSubviews:YES];
32 }
33
34 @end
35
36 @implementation NSTextField (ResizabilityExtentions)
37 -(CGFloat) breakpad_adjustHeightToFit {
38 NSRect oldFrame = [self frame];
39 // Starting with the 10.5 SDK, height won't grow, so make it huge to start.
40 NSRect presizeFrame = oldFrame;
41
42 presizeFrame.size.height = MAXFLOAT;
43 // sizeToFit will blow out the width rather than making the field taller, so
44 // we do it manually.
45 NSSize newSize = [[self cell] cellSizeForBounds:presizeFrame];
46 NSRect newFrame = NSMakeRect(oldFrame.origin.x, oldFrame.origin.y,
47 NSWidth(oldFrame), newSize.height);
48 [self setFrame:newFrame];
49
50 return newSize.height - NSHeight(oldFrame);
51 }
52
53 -(CGFloat) breakpad_adjustWidthToFit {
54 NSRect oldFrame = [self frame];
55
56 [self sizeToFit];
57 return NSWidth([self frame]) - NSWidth(oldFrame);
58 }
59
60 @end
61
62 @implementation NSButton (ResizabilityExtentions)
63 -(CGFloat) breakpad_smartSizeToFit {
64 NSRect oldFrame = [self frame];
65
66 [self sizeToFit];
67 NSRect newFrame = [self frame];
68 // sizeToFit gives much worse results that IB's Size to Fit option. This is
69 // the amount of padding IB adds over a sizeToFit, empirically determined.
70 const float kExtraPaddingAmount = 12;
71 const float kMinButtonWidth = 70; // The default button size in IB.
72 newFrame.size.width = NSWidth(newFrame) + kExtraPaddingAmount;
73 if (NSWidth(newFrame) < kMinButtonWidth) {
74 newFrame.size.width = kMinButtonWidth; // Preserve the right edge location.
75 }
76 newFrame.origin.x = NSMaxX(oldFrame) - NSWidth(newFrame);
77 [self setFrame:newFrame];
78 return NSWidth(newFrame) - NSWidth(oldFrame);
79 }
80
81 @end
Something went wrong with that request. Please try again.