Removing the use of private CoreGraphics APIs to draw shadows, and replacing with...
[ITKit.git] / ITWindowEffect.m
1 #import "ITWindowEffect.h"
2 #import "ITTransientStatusWindow.h"
3 #import <OpenGL/gl.h>
4 #import <OpenGL/glu.h>
5 #import <OpenGL/glext.h>
6
7 @implementation ITWindowEffect
8
9 + (NSArray *)effectClasses
10 {
11     NSMutableArray *classes = [[NSArray arrayWithObjects:
12         NSClassFromString(@"ITCutWindowEffect"),
13         NSClassFromString(@"ITDissolveWindowEffect"),
14         NSClassFromString(@"ITSlideHorizontallyWindowEffect"),
15         NSClassFromString(@"ITSlideVerticallyWindowEffect"),
16         NSClassFromString(@"ITPivotWindowEffect"),
17         NSClassFromString(@"ITZoomWindowEffect"),
18         NSClassFromString(@"ITSpinWindowEffect"),
19         NSClassFromString(@"ITSpinAndZoomWindowEffect"),
20         nil] mutableCopy];
21         
22         long version;
23         if ((Gestalt(gestaltSystemVersion, &version) == noErr) && (version >= 4160) && (version < 4166)) {
24                 NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 1, 1) pixelFormat:[NSOpenGLView defaultPixelFormat]];
25                 if ([view openGLContext]) {
26                         NSString *string = [NSString stringWithCString:glGetString(GL_EXTENSIONS)];
27                         NSRange result = [string rangeOfString:@"ARB_fragment_program"];
28                         if (result.location != NSNotFound) {
29                                 [classes addObject:NSClassFromString(@"ITCoreImageWindowEffect")];
30                         }
31                 }
32                 [view release];
33         }
34         
35     return [classes autorelease];
36 }
37
38 - (id)initWithWindow:(NSWindow *)window
39 {
40     if ( (self = [super init]) ) {
41         _window                 = [window retain];
42         _effectTime             = DEFAULT_EFFECT_TIME;
43         _effectTimer            = nil;
44         __shouldReleaseWhenIdle = NO;
45         __idle                  = YES;
46
47         if ( [window conformsToProtocol:@protocol(ITWindowPositioning)] ) {
48             _verticalPosition   = (ITVerticalWindowPosition)[(ITTransientStatusWindow *)window verticalPosition];
49             _horizontalPosition = (ITHorizontalWindowPosition)[(ITTransientStatusWindow *)window horizontalPosition];
50         } else {
51             NSLog(@"ITWindowEffect - initWithWindow: - window does not conform to ITWindowPositioning.");
52             _verticalPosition   = ITWindowPositionBottom;
53             _horizontalPosition = ITWindowPositionLeft;
54         }
55     }
56     return self;
57 }
58
59 - (NSWindow *)window
60 {
61     return _window;
62 }
63
64 - (void)setWindow:(NSWindow *)newWindow
65 {
66     [_window autorelease];
67     _window = [newWindow retain];
68 }
69
70 - (void)setWindowVisibility:(ITWindowVisibilityState)visibilityState
71 {
72     if ( [_window conformsToProtocol:@protocol(ITWindowMotility)] ) {
73        // Cast so the compiler won't gripe
74         [(ITTransientStatusWindow *)_window setVisibilityState:visibilityState];
75     } else {
76         NSLog(@"ITWindowEffect - setWindowVisibility: - window does not conform to ITWindowVisibility.");
77     }
78 }
79
80 - (float)effectTime
81 {
82     return _effectTime;
83 }
84
85 - (void)setEffectTime:(float)newTime
86 {
87     _effectTime = newTime;
88 }
89
90 + (NSString *)effectName
91 {
92     NSLog(@"ITWindowEffect does not implement +effectName.");
93     return nil;
94 }
95
96 + (NSDictionary *)supportedPositions
97 {
98     NSLog(@"ITWindowEffect does not implement +supportedPositions.");
99     
100 //  Below is an example dictionary.  Modify it appropriately when subclassing.
101     return [NSDictionary dictionaryWithObjectsAndKeys:
102         [NSDictionary dictionaryWithObjectsAndKeys:
103             [NSNumber numberWithBool:NO], @"Left",
104             [NSNumber numberWithBool:NO], @"Center",
105             [NSNumber numberWithBool:NO], @"Right", nil] , @"Top" ,
106         [NSDictionary dictionaryWithObjectsAndKeys:
107             [NSNumber numberWithBool:NO], @"Left",
108             [NSNumber numberWithBool:NO], @"Center",
109             [NSNumber numberWithBool:NO], @"Right", nil] , @"Middle" ,
110         [NSDictionary dictionaryWithObjectsAndKeys:
111             [NSNumber numberWithBool:NO], @"Left",
112             [NSNumber numberWithBool:NO], @"Center",
113             [NSNumber numberWithBool:NO], @"Right", nil] , @"Bottom" , nil];
114 }
115
116 + (unsigned int)listOrder
117 {
118     NSLog(@"ITWindowEffect does not implement +listOrder.");
119     return 0;
120 }
121
122 - (void)performAppear
123 {
124     NSLog(@"ITWindowEffect does not implement -performAppear.");
125 }
126
127 - (void)performVanish
128 {
129     NSLog(@"ITWindowEffect does not implement -performVanish.");
130 }
131
132 - (void)cancelAppear
133 {
134     NSLog(@"ITWindowEffect does not implement -cancelAppear.");
135 }
136
137 - (void)cancelVanish
138 {
139     NSLog(@"ITWindowEffect does not implement -cancelVanish.");
140 }
141
142 - (void)releaseWhenIdle;
143 {
144     if ( __idle ) {
145         [self release];
146     } else {
147         __shouldReleaseWhenIdle = YES;
148     }
149 }
150
151 - (void)dealloc
152 {
153         [_window release];
154         [super dealloc];
155 }
156
157
158 @end