Checking in improvements to the effect availability heuristic.
[ITKit.git] / ITWindowEffect.m
1 #import "ITWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3
4
5 @implementation ITWindowEffect
6
7 + (NSArray *)effectClasses
8 {
9     NSArray *classes = [NSArray arrayWithObjects:
10         NSClassFromString(@"ITCutWindowEffect"),
11         NSClassFromString(@"ITDissolveWindowEffect"),
12         NSClassFromString(@"ITSlideHorizontallyWindowEffect"),
13         NSClassFromString(@"ITSlideVerticallyWindowEffect"),
14         NSClassFromString(@"ITPivotWindowEffect"),
15         nil];
16         
17     return classes;
18 }
19
20 - (id)initWithWindow:(NSWindow *)window
21 {
22     if ( (self = [super init]) ) {
23         _window                 = [window retain];
24         _effectTime             = DEFAULT_EFFECT_TIME;
25         _effectTimer            = nil;
26         __shouldReleaseWhenIdle = NO;
27         __idle                  = YES;
28
29         if ( [window conformsToProtocol:@protocol(ITWindowPositioning)] ) {
30                                                            // Casts so the compiler won't gripe
31             _verticalPosition   = (ITVerticalWindowPosition)[(ITTransientStatusWindow *)window verticalPosition];
32             _horizontalPosition = (ITHorizontalWindowPosition)[(ITTransientStatusWindow *)window horizontalPosition];
33         } else {
34             NSLog(@"ITWindowEffect - initWithWindow: - window does not conform to ITWindowPositioning.");
35             _verticalPosition   = ITWindowPositionBottom;
36             _horizontalPosition = ITWindowPositionLeft;
37         }
38     }
39     return self;
40 }
41
42 - (NSWindow *)window
43 {
44     return _window;
45 }
46
47 - (void)setWindow:(NSWindow *)newWindow
48 {
49     [_window autorelease];
50     _window = [newWindow retain];
51 }
52
53 - (void)setWindowVisibility:(ITWindowVisibilityState)visibilityState
54 {
55     if ( [_window conformsToProtocol:@protocol(ITWindowMotility)] ) {
56        // Cast so the compiler won't gripe
57         [(ITTransientStatusWindow *)_window setVisibilityState:visibilityState];
58     } else {
59         NSLog(@"ITWindowEffect - setWindowVisibility: - window does not conform to ITWindowVisibility.");
60     }
61 }
62
63 - (float)effectTime
64 {
65     return _effectTime;
66 }
67
68 - (void)setEffectTime:(float)newTime
69 {
70     _effectTime = newTime;
71 }
72
73 + (NSString *)effectName
74 {
75     NSLog(@"ITWindowEffect does not implement +effectName.");
76     return nil;
77 }
78
79 + (NSDictionary *)supportedPositions
80 {
81     NSLog(@"ITWindowEffect does not implement +supportedPositions.");
82     
83 //  Below is an example dictionary.  Modify it appropriately when subclassing.
84     return [NSDictionary dictionaryWithObjectsAndKeys:
85         [NSDictionary dictionaryWithObjectsAndKeys:
86             [NSNumber numberWithBool:NO], @"Left",
87             [NSNumber numberWithBool:NO], @"Center",
88             [NSNumber numberWithBool:NO], @"Right", nil] , @"Top" ,
89         [NSDictionary dictionaryWithObjectsAndKeys:
90             [NSNumber numberWithBool:NO], @"Left",
91             [NSNumber numberWithBool:NO], @"Center",
92             [NSNumber numberWithBool:NO], @"Right", nil] , @"Middle" ,
93         [NSDictionary dictionaryWithObjectsAndKeys:
94             [NSNumber numberWithBool:NO], @"Left",
95             [NSNumber numberWithBool:NO], @"Center",
96             [NSNumber numberWithBool:NO], @"Right", nil] , @"Bottom" , nil];
97 }
98
99 + (unsigned int)listOrder
100 {
101     NSLog(@"ITWindowEffect does not implement +listOrder.");
102     return 0;
103 }
104
105 - (void)performAppear
106 {
107     NSLog(@"ITWindowEffect does not implement -performAppear.");
108 }
109
110 - (void)performVanish
111 {
112     NSLog(@"ITWindowEffect does not implement -performVanish.");
113 }
114
115 - (void)cancelAppear
116 {
117     NSLog(@"ITWindowEffect does not implement -cancelAppear.");
118 }
119
120 - (void)cancelVanish
121 {
122     NSLog(@"ITWindowEffect does not implement -cancelVanish.");
123 }
124
125 - (void)releaseWhenIdle;
126 {
127     if ( __idle ) {
128         [self release];
129     } else {
130         __shouldReleaseWhenIdle = YES;
131     }
132 }
133
134 - (void)dealloc
135 {
136         [_window release];
137         [super dealloc];
138 }
139
140
141 @end