1 #import "ITTransientStatusWindow.h"
2 #import "ITWindowEffect.h"
3 #import <CoreGraphics/CoreGraphics.h>
4 #import "ITCoreGraphicsHacks.h"
5 #import "ITTextField.h"
6 #import "ITGrayRoundedView.h"
8 #define EFFECT_FPS 30.0
11 /*************************************************************************/
13 #pragma mark PRIVATE METHOD DECLARATIONS
14 /*************************************************************************/
16 @interface ITTransientStatusWindow (Private)
17 - (id)initWithContentView:(NSView *)contentView
18 exitMode:(ITTransientStatusWindowExitMode)exitMode
19 backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType;
20 - (void)rebuildWindow;
21 - (void)startVanishTimer;
25 /*************************************************************************/
27 #pragma mark IMPLEMENTATION
28 /*************************************************************************/
30 @implementation ITTransientStatusWindow
33 /*************************************************************************/
35 #pragma mark SHARED STATIC OBJECTS
36 /*************************************************************************/
38 static ITTransientStatusWindow *staticWindow = nil;
41 /*************************************************************************/
43 #pragma mark INITIALIZATION METHODS
44 /*************************************************************************/
46 + (ITTransientStatusWindow *)sharedWindow
48 if ( ! (staticWindow) ) {
49 staticWindow = [[self alloc] initWithContentView:nil
50 exitMode:ITTransientStatusWindowExitAfterDelay
51 backgroundType:ITTransientStatusWindowRounded];
56 - (id)initWithContentView:(NSView *)contentView
57 exitMode:(ITTransientStatusWindowExitMode)exitMode
58 backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType
62 // If no Content View was provided, use a generic view.
63 if ( ! (contentView) ) {
64 contentView = [[[NSView alloc] initWithFrame:
65 NSMakeRect(100.0, 100.0, 200.0, 200.0)] autorelease];
68 // Set the content rect to the frame of the content view, now guaranteed to exist.
69 contentRect = [contentView frame];
71 if ( ( self = [super initWithContentRect:contentRect
72 styleMask:NSBorderlessWindowMask
73 backing:NSBackingStoreBuffered
76 _visibilityState = ITTransientStatusWindowHiddenState;
78 _exitDelay = DEFAULT_EXIT_DELAY;
79 _backgroundType = backgroundType;
80 _verticalPosition = ITWindowPositionBottom;
81 _horizontalPosition = ITWindowPositionLeft;
82 _screenPadding = 32.0;
86 _reallyIgnoresEvents = YES;
89 // if ( _backgroundType == ITTransientStatusWindowRounded ) {
90 // _contentSubView = contentView;
92 // [self setContentView:contentView];
95 [self setIgnoresMouseEvents:YES];
96 [self setLevel:NSScreenSaverWindowLevel];
97 [self setContentView:contentView];
104 /*************************************************************************/
106 #pragma mark INSTANCE METHODS
107 /*************************************************************************/
109 - (BOOL)ignoresMouseEvents
111 return _reallyIgnoresEvents;
114 - (void)setIgnoresMouseEvents:(BOOL)flag
119 key = CGSCreateCString("IgnoreForEvents");
120 ignore = CGSCreateBoolean( (flag ? kCGSTrue : kCGSFalse) );
121 CGSSetWindowProperty([NSApp contextID], (CGSWindowID)[self windowNumber], key, ignore);
123 CGSReleaseObj(ignore);
125 _reallyIgnoresEvents = flag;
133 if ( _backgroundType == ITTransientStatusWindowRounded ) {
134 return _contentSubView;
136 return [super contentView];
140 - (void)setContentView:(NSView *)aView
142 if ( _backgroundType == ITTransientStatusWindowRounded ) {
143 [_contentSubView removeFromSuperview];
144 _contentSubView = aView;
145 [_contentSubView setFrame:[[super contentView] frame]];
146 [[super contentView] addSubview:_contentSubView];
147 [_contentSubView setNextResponder:self];
149 [super setContentView:aView];
155 - (IBAction)appear:(id)sender
157 NSLog(@"%i", _visibilityState);
158 if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
159 // Window is hidden. Appear as normal, and start the timer.
160 if ( _entryEffect == nil ) {
161 [self orderFront:self];
162 _visibilityState = ITTransientStatusWindowVisibleState;
164 _visibilityState = ITTransientStatusWindowAppearingState;
165 [_entryEffect performAppear];
166 _visibilityState = ITTransientStatusWindowVisibleState;
168 [self startVanishTimer];
169 } else if ( _visibilityState == ITTransientStatusWindowVisibleState ) {
170 // Window is completely visible. Simply reset the timer.
171 [self startVanishTimer];
172 } else if ( _visibilityState == ITTransientStatusWindowAppearingState ) {
173 // Window is appearing. Do nothing.
174 } else if ( _visibilityState == ITTransientStatusWindowVanishingState ) {
175 NSLog(@"%i", _visibilityState);
176 if ( _exitEffect == nil ) {
177 [self orderFront:self];
178 _visibilityState = ITTransientStatusWindowVisibleState;
180 _visibilityState = ITTransientStatusWindowAppearingState;
181 [_exitEffect cancelVanish];
182 _visibilityState = ITTransientStatusWindowVisibleState;
184 [self startVanishTimer];
188 - (IBAction)vanish:(id)sender
190 if ( _visibilityState == ITTransientStatusWindowVisibleState ) {
191 // Window is totally visible. Perform exit effect.
192 if ( _exitEffect == nil ) {
193 [self orderOut:self];
194 _visibilityState = ITTransientStatusWindowHiddenState;
196 _visibilityState = ITTransientStatusWindowVanishingState;
197 NSLog(@"%i", _visibilityState);
198 [_exitEffect performVanish];
199 NSLog(@"%i", _visibilityState);
200 _visibilityState = ITTransientStatusWindowHiddenState;
201 NSLog(@"%i", _visibilityState);
203 [self startVanishTimer];
204 } else if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
205 // Window is hidden. Do nothing.
206 } else if ( _visibilityState == ITTransientStatusWindowAppearingState ) {
207 // Window is on its way in. Cancel appear.
208 [_entryEffect cancelAppear];
209 _visibilityState = ITTransientStatusWindowHiddenState;
210 } else if ( _visibilityState == ITTransientStatusWindowVanishingState ) {
211 // Window is on its way out. Do nothing.
215 - (ITWindowVisibilityState)visibilityState
217 return _visibilityState;
220 - (void)setVisibilityState:(ITWindowVisibilityState)newState
222 _visibilityState = newState;
225 - (ITTransientStatusWindowExitMode)exitMode
230 - (void)setExitMode:(ITTransientStatusWindowExitMode)newMode
240 - (void)setExitDelay:(float)seconds
242 _exitDelay = seconds;
245 - (ITTransientStatusWindowBackgroundType)backgroundType
247 // return _backgroundType;
248 return ITTransientStatusWindowRounded;
251 - (void)setBackgroundType:(ITTransientStatusWindowBackgroundType)newType
253 // setBackgroundType: is currently ignored. Defaults to ITTransientStatusWindowRounded.
254 // _backgroundType = newType;
255 _backgroundType = ITTransientStatusWindowRounded;
258 - (ITVerticalWindowPosition)verticalPosition;
260 return _verticalPosition;
263 - (void)setVerticalPosition:(ITVerticalWindowPosition)newPosition;
265 _verticalPosition = newPosition;
268 - (ITHorizontalWindowPosition)horizontalPosition;
270 return _horizontalPosition;
273 - (void)setHorizontalPosition:(ITHorizontalWindowPosition)newPosition;
275 _horizontalPosition = newPosition;
278 - (float)screenPadding
280 return _screenPadding;
283 - (void)setScreenPadding:(float)newPadding
285 _screenPadding = newPadding;
290 return _screenNumber;
293 - (void)setScreenNumber:(int)newNumber
295 _screenNumber = newNumber;
298 - (ITWindowEffect *)entryEffect
303 - (void)setEntryEffect:(ITWindowEffect *)newEffect
305 [_entryEffect autorelease];
306 _entryEffect = [newEffect retain];
309 - (ITWindowEffect *)exitEffect
314 - (void)setExitEffect:(ITWindowEffect *)newEffect
316 [_exitEffect autorelease];
317 _exitEffect = [newEffect retain];
321 /*************************************************************************/
323 #pragma mark PRIVATE METHODS
324 /*************************************************************************/
326 - (void)rebuildWindow;
328 if ( _backgroundType == ITTransientStatusWindowRounded ) {
329 ITGrayRoundedView *roundedView = [[[ITGrayRoundedView alloc] initWithFrame:[self frame]] autorelease];
331 [self setBackgroundColor:[NSColor clearColor]];
332 [self setHasShadow:NO];
335 [self setContentView:roundedView];
336 // [super setContentView:roundedView];
337 // [_contentSubView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
338 // [self setContentView:_contentSubView];
344 - (void)startVanishTimer