forked from thmghtd/InspectorKit.framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInspectorPaneContainerIntegration.m
186 lines (138 loc) · 5.51 KB
/
InspectorPaneContainerIntegration.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// InspectorPaneContainerIntegration.m
// InspectorPane
//
// Created by Steven on 3/8/09.
// Copyright 2009 Thoughtful Tree Software. All rights reserved.
//
#import <InterfaceBuilderKit/InterfaceBuilderKit.h>
#import <InspectorKit/InspectorPaneContainer.h>
#import "InspectorPaneContainerInspector.h"
#import "NSWindow+Geometry.h"
#import "NSBezierPath+StrokeExtensions.h"
@interface InspectorPaneContainer ( InspectorPaneContainer )
- (void) adjustIBWindowFrame;
- (void) adjustPaneFrames;
@end
@implementation InspectorPaneContainer ( InspectorPaneContainer )
- (void)ibPopulateKeyPaths:(NSMutableDictionary *)keyPaths {
[super ibPopulateKeyPaths:keyPaths];
[[keyPaths objectForKey:IBAttributeKeyPaths] addObjectsFromArray:[NSArray arrayWithObjects:/* @"MyFirstProperty", @"MySecondProperty",*/ nil]];
}
- (void)ibPopulateAttributeInspectorClasses:(NSMutableArray *)classes {
[super ibPopulateAttributeInspectorClasses:classes];
[classes addObject:[InspectorPaneContainerInspector class]];
}
- (NSView *)ibDesignableContentView {
return self;
}
- (void)drawRect:(NSRect)rect {
NSRect frame = [self bounds];
frame.origin.x += 0.5;
frame.origin.y += 0.5;
frame.size.width -= 1.0;
frame.size.height -= 1.0;
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Geneva" size:10.0], NSFontAttributeName,
// [NSColor whiteColor], NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName,
nil];
NSRect bottomRect;
NSRect mainRect;
NSDivideRect(frame, &bottomRect, &mainRect, 20.0, NSMinYEdge);
[[NSColor lightGrayColor] setStroke];
float mainRadius = 12.0;
mainRect = NSInsetRect(mainRect, 2.0, 2.0);
CGFloat dashArray[] = { 15.0, 7.0 };
NSBezierPath *containerPath = [NSBezierPath bezierPathWithRoundedRect:mainRect xRadius:mainRadius yRadius:mainRadius];
[containerPath setLineWidth:3.0];
[containerPath setLineDash:dashArray count:2 phase:0.0];
[containerPath strokeInside];
bottomRect.size.height = 17.0;
bottomRect = NSInsetRect(bottomRect, -1.0, -1.0);
[[NSColor lightGrayColor] setFill];
NSRectFill(bottomRect);
NSRect bottomBorderRect = bottomRect;
bottomBorderRect.origin.y = bottomBorderRect.size.height;
bottomBorderRect.size.height = 1.0;
[[NSColor darkGrayColor] setFill];
NSRectFill(bottomBorderRect);
NSRect textRect = bottomRect;
textRect.origin.y -= 1.0;
[@"Click here to select Inspector Container" drawInRect:textRect withAttributes:attributes];
// NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:bottomRect xRadius:r yRadius:r];
// [path setLineWidth:1.0];
// [path setLineDash:dashArray count:2 phase:0.0];
// [path strokeInside];
}
- (void) adjustPaneFrames {
NSDisableScreenUpdates();
NSRect mainFrame = [self frame];
float distanceFromTop = NSHeight([[self superview] frame]) - NSMaxY(mainFrame);
float totalHeight = 20.0;
for (NSView *subview in [self subviews])
totalHeight += NSHeight([subview frame]);
mainFrame.origin.y = NSHeight([[self superview] frame]) - distanceFromTop - totalHeight;
mainFrame.size.height = totalHeight;
[self setFrame:mainFrame];
totalHeight = 20.0;
for (NSView *subview in [[self subviews] reverseObjectEnumerator]) {
NSRect frame = [subview frame];
// testing
frame.origin.y = totalHeight;
frame.origin.x = 0;
frame.size.width = mainFrame.size.width;
[subview setFrame:frame];
totalHeight += NSHeight(frame);
}
//[self adjustIBWindowFrame];
NSEnableScreenUpdates();
}
- (void)didAddSubview:(NSView *)subview {
[super didAddSubview:subview];
[self performSelector:@selector(adjustPaneFrames) withObject:nil afterDelay:0.0];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(adjustSubviewFramesDuringDesignTime:)
name:NSViewFrameDidChangeNotification
object:subview];
}
- (void)willRemoveSubview:(NSView *)subview {
// When designers drag around the container, this is called continuously, and falsely
if ([[self subviews] containsObject:subview] == NO)
return;
[super willRemoveSubview:subview];
[self performSelector:@selector(adjustPaneFrames) withObject:nil afterDelay:0.0];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSViewFrameDidChangeNotification
object:subview];
}
- (void) adjustSubviewFramesDuringDesignTime:(NSNotification*)notification {
[self adjustPaneFrames];
[self performSelector:@selector(adjustPaneFrames) withObject:nil afterDelay:0.0];
}
- (void) setFrame:(NSRect)newFrame {
[super setFrame:newFrame];
if ([self window])
[self performSelector:@selector(adjustIBWindowFrame) withObject:nil afterDelay:0.0];
}
- (void)viewDidMoveToWindow {
if ([self window])
[self performSelector:@selector(adjustIBWindowFrame) withObject:nil afterDelay:0.0];
}
- (void) adjustIBWindowFrame {
NSPoint origin = [self frame].origin;
origin.x = 0;
[self setFrameOrigin:origin];
// float bottomMargin = NSMinY([self frame]);
topMargin = NSHeight([[self superview] frame]) - NSMaxY([self frame]);
// if (bottomMargin < 0) {
NSSize contentViewSize = [[[self window] contentView] frame].size;
contentViewSize.width = NSWidth([self frame]);
// contentViewSize.height += (0.0 - bottomMargin);
contentViewSize.height = NSHeight([self frame]) + topMargin;
[[self window] setContentViewSize:contentViewSize display:YES animate:NO];
// }
}
@end