Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 290 lines (233 sloc) 5.95 kB
dc5be1c Initial check-in.
uli authored
1 //
2 // UKViewListView.m
3 // UKViewListView
4 //
5 // Created by Uli Kusterer on 14.10.06.
720b0e7 @uliwitness Added licensing information to the source files.
authored
6 // Copyright 2006 Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c Initial check-in.
uli authored
26 //
27
28 #import "UKViewListView.h"
29 #import "NSView+SetFrameSizePinnedToTopLeft.h"
30
31
32 @implementation UKViewListView
33
34 - (id)initWithFrame:(NSRect)frame
35 {
36 self = [super initWithFrame:frame];
37 if( self )
38 {
39 // Initialization code here.
40 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(viewFrameDidChange:) name: NSViewFrameDidChangeNotification object: self];
41 interViewSpacing = -1;
42 forceToContentHeight = YES;
6b785b9 UKViewListView can animate.
uli authored
43 doAnimateResizing = NO;
dc5be1c Initial check-in.
uli authored
44 }
45 return self;
46 }
47
48
49 - (id)initWithCoder:(NSCoder*)coder
50 {
51 self = [super initWithCoder: coder];
52 if( self )
53 {
54 // Initialization code here.
55 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(viewFrameDidChange:) name: NSViewFrameDidChangeNotification object: self];
56 interViewSpacing = -1;
57 forceToContentHeight = YES;
6b785b9 UKViewListView can animate.
uli authored
58 doAnimateResizing = NO;
dc5be1c Initial check-in.
uli authored
59 }
60 return self;
61 }
62
63
64
65 -(void) awakeFromNib
66 {
67 [self reLayoutViewListViews];
68 }
69
70
71 -(void) drawRect: (NSRect)rect
72 {
73 //NSDrawGrayBezel( [self bounds], [self bounds] ); // Debugging only.
74 }
75
76
77 -(void) didAddSubview: (NSView*)subview
78 {
79 [super didAddSubview: subview];
80
81 [self reLayoutViewListViews]; // Invalidates new box.
82 }
83
84
85 -(void) viewDidMoveToWindow
86 {
87 [self reLayoutViewListViews];
88 }
89
90
85eaed7 @uliwitness UKViewListView can now also resize the containing window to fit the v…
authored
91 -(void) setResizeWindowAndView: (BOOL)resizeBoth
92 {
93 resizeWindowAndView = resizeBoth;
94 }
95
96
dc5be1c Initial check-in.
uli authored
97 -(void) reLayoutViewListViewsAndAdjustFrame: (BOOL)adjustFrame
98 {
99 if( !isInReLayout )
100 {
101 isInReLayout = YES;
85eaed7 @uliwitness UKViewListView can now also resize the containing window to fit the v…
authored
102 [self setHidden: YES];
103
dc5be1c Initial check-in.
uli authored
104 if( forceToContentHeight && adjustFrame )
105 {
85eaed7 @uliwitness UKViewListView can now also resize the containing window to fit the v…
authored
106 BOOL isContentView = [[self window] contentView] == self;
107 if( isContentView || resizeWindowAndView )
6b785b9 UKViewListView can animate.
uli authored
108 {
109 NSWindow* wd = [self window];
110 NSRect newBox = [wd contentRectForFrameRect: [wd frame]];
111 NSSize newSize = [self bestSize];
112 newBox.size.width = newSize.width;
113 newBox.origin.y += newBox.size.height -newSize.height;
114 newBox.size.height = newSize.height;
115 newBox = [wd frameRectForContentRect: newBox];
116 [wd setFrame: newBox display: YES animate: doAnimateResizing];
117 }
85eaed7 @uliwitness UKViewListView can now also resize the containing window to fit the v…
authored
118
119 if( !isContentView || resizeWindowAndView )
dc5be1c Initial check-in.
uli authored
120 [self setFrameSizePinnedToTopLeft: [self bestSize]];
121 }
122
123 NSRect myBounds = [self bounds];
6b785b9 UKViewListView can animate.
uli authored
124 NSPoint viewPos = NSMakePoint( leftMargin, isFlipped ? topMargin : (NSMaxY( myBounds ) -topMargin) );
dc5be1c Initial check-in.
uli authored
125 NSArray* subs = [[[self subviews] copy] autorelease];
126 NSEnumerator* enny = [subs objectEnumerator];
127 NSView* currSubview = nil;
128
129 while( (currSubview = [enny nextObject]) )
130 {
131 if( ![currSubview isHidden] )
132 {
133 NSRect currViewBox = [currSubview bounds];
6b785b9 UKViewListView can animate.
uli authored
134 if( !isFlipped )
135 viewPos.y -= currViewBox.size.height;
dc5be1c Initial check-in.
uli authored
136 currViewBox.origin = viewPos;
137 currViewBox.size.width = myBounds.size.width -leftMargin -rightMargin;
138 [currSubview setFrame: currViewBox];
6b785b9 UKViewListView can animate.
uli authored
139 if( !isFlipped )
140 viewPos.y -= interViewSpacing;
141 else
142 viewPos.y += currViewBox.size.height +interViewSpacing;
dc5be1c Initial check-in.
uli authored
143 }
144 }
145
146 [self setNeedsDisplay: YES];
85eaed7 @uliwitness UKViewListView can now also resize the containing window to fit the v…
authored
147 [self setHidden: NO];
dc5be1c Initial check-in.
uli authored
148 isInReLayout = NO;
149 }
150 }
151
152
153 -(void) reLayoutViewListViews
154 {
155 [self reLayoutViewListViewsAndAdjustFrame: YES];
156 }
157
6b785b9 UKViewListView can animate.
uli authored
158 -(BOOL) isFlipped
159 {
160 return isFlipped;
161 }
162
163
164 -(void) setIsFlipped: (BOOL)state
165 {
166 isFlipped = state;
167 }
dc5be1c Initial check-in.
uli authored
168
169 -(NSSize) bestSize
170 {
171 NSSize bSiz = NSZeroSize;
172
173 bSiz.width = [self bounds].size.width;
174 bSiz.height = topMargin +bottomMargin;
175
176 NSEnumerator* enny = [[self subviews] objectEnumerator];
177 NSView* currSubview = nil;
178 BOOL isFirst = YES;
179
180 while( (currSubview = [enny nextObject]) )
181 {
182 if( ![currSubview isHidden] )
183 {
184 NSRect currViewBox = [currSubview bounds];
185
186 if( isFirst )
187 isFirst = NO;
188 else
189 bSiz.height += interViewSpacing;
190
191 bSiz.height += currViewBox.size.height;
192 }
193 }
194
195 return bSiz;
196 }
197
198
199 -(void) viewFrameDidChange: (NSNotification*)notif
200 {
201 [self reLayoutViewListViewsAndAdjustFrame: NO];
202 }
203
204
205 -(void) setForceToContentHeight: (BOOL)doForce
206 {
207 forceToContentHeight = doForce;
208 if( doForce )
209 [self reLayoutViewListViews];
210 }
211
212
213 -(BOOL) forceToContentHeight
214 {
215 return forceToContentHeight;
216 }
217
218
219 - (float)leftMargin
220 {
221 return leftMargin;
222 }
223
224 - (void)setLeftMargin:(float)value
225 {
226 if (leftMargin != value)
227 {
228 leftMargin = value;
229 }
230 }
231
232 - (float)rightMargin
233 {
234 return rightMargin;
235 }
236
237 - (void)setRightMargin:(float)value
238 {
239 if (rightMargin != value)
240 {
241 rightMargin = value;
242 }
243 }
244
245 - (float)topMargin
246 {
247 return topMargin;
248 }
249
250 - (void)setTopMargin:(float)value
251 {
252 if (topMargin != value)
253 {
254 topMargin = value;
255 }
256 }
257
258 - (float)bottomMargin
259 {
260 return bottomMargin;
261 }
262
263 - (void)setBottomMargin:(float)value
264 {
265 if (bottomMargin != value)
266 {
267 bottomMargin = value;
268 }
269 }
270
271 - (float)interViewSpacing
272 {
273 return interViewSpacing;
274 }
275
276 - (void)setInterViewSpacing:(float)value
277 {
278 if (interViewSpacing != value)
279 {
280 interViewSpacing = value;
281 }
282 }
283
6b785b9 UKViewListView can animate.
uli authored
284 -(void) setAnimateResizing: (BOOL)animateResizing
285 {
286 doAnimateResizing = animateResizing;
287 }
dc5be1c Initial check-in.
uli authored
288
289 @end
Something went wrong with that request. Please try again.