Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 100 lines (87 sloc) 2.815 kB
76d2a5b @mstroeck
mstroeck authored
1 //
2 // ViewExtensions.m
3 // Vienna
4 //
5 // Created by Steve Palmer on 27/05/2007.
6 // Copyright (c) 2004-2007 Steve Palmer. All rights reserved.
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20
21 #import "ViewExtensions.h"
22
23 @interface NSAnimation (ViennaAnimationWithTags)
24 -(void)MA_setTag:(int)newTag;
25 -(int)MA_tag;
26 @end
27
28 @implementation NSAnimation (ViennaAnimationWithTags)
29
30 /* MA_tagDict
31 * A dictionary used to simulate instance variables for our category
32 */
33 - (NSMutableDictionary *)MA_tagDict
34 {
35 static NSMutableDictionary *MATagDict = nil;
36 if (MATagDict == nil)
37 {
38 MATagDict = [[NSMutableDictionary alloc] init];
39 }
40 return MATagDict;
41 }
42
43 /* MA_setTag
44 * Assigns the specified tag value to the animation object.
45 */
46 -(void)MA_setTag:(int)newTag
47 {
48 [[self MA_tagDict] setObject:[NSNumber numberWithInt:newTag]
49 forKey:[NSValue valueWithPointer:self]];
50 }
51
52 /* MA_tag
53 * Returns the associated tag.
54 */
55 -(int)MA_tag
56 {
57 NSMutableDictionary *tagDict = [self MA_tagDict];
58 NSValue *key = [NSValue valueWithPointer:self];
59 int tag = [[tagDict objectForKey:key] intValue];
60 [tagDict removeObjectForKey:key];
61 return tag;
62 }
63 @end
64
65 @implementation NSView (ViewExtensions)
66
67 /* resizeViewWithAnimation
68 * Resizes the specified view with animation.
69 */
70 -(void)resizeViewWithAnimation:(NSRect)newFrame withTag:(int)viewTag
71 {
72 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
73 [NSValue valueWithRect:newFrame], NSViewAnimationEndFrameKey,
74 self, NSViewAnimationTargetKey,
75 nil];
76
77 NSViewAnimation * animation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
78 [animation setAnimationBlockingMode:NSAnimationNonblocking];
79 [animation setDuration:0.1];
80 [animation setAnimationCurve:NSAnimationEaseInOut];
600434c @barijaona Fix some warnings, 64 bits.
barijaona authored
81 [animation setDelegate:(id<NSAnimationDelegate>)self];
76d2a5b @mstroeck
mstroeck authored
82 [animation MA_setTag:viewTag];
83 [animation startAnimation];
84 }
85
86 /* animationDidEnd
87 * Delegate function called when animation completes.
88 */
89 -(void)animationDidEnd:(NSAnimation *)animation
90 {
91 NSWindow * viewWindow = [self window];
92 int viewTag = [animation MA_tag];
93
94 [animation release];
95 if ([[viewWindow delegate] respondsToSelector:@selector(viewAnimationCompleted:withTag:)])
600434c @barijaona Fix some warnings, 64 bits.
barijaona authored
96 [(id)[viewWindow delegate] viewAnimationCompleted:self withTag:viewTag];
76d2a5b @mstroeck
mstroeck authored
97 }
98
99 @end
Something went wrong with that request. Please try again.