X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/2589c16f443dd6fe9df554eb533df464b5bb919b..f62f46dfa394f35899b21f2b2cf793e8c651d9bb:/ITTransientStatusWindow.m?ds=sidebyside diff --git a/ITTransientStatusWindow.m b/ITTransientStatusWindow.m old mode 100755 new mode 100644 index 004396a..24aa83b --- a/ITTransientStatusWindow.m +++ b/ITTransientStatusWindow.m @@ -1,23 +1,13 @@ #import "ITTransientStatusWindow.h" -#import +#import "ITWindowEffect.h" +#import #import "ITCoreGraphicsHacks.h" #import "ITTextField.h" -#import "ITGrayRoundedView.h" - +#import "ITTSWBackgroundView.h" #define EFFECT_FPS 30.0 -/*************************************************************************/ -#pragma mark - -#pragma mark EVIL HACKERY -/*************************************************************************/ - -@interface NSApplication (HACKHACKHACKHACK) -- (CGSConnectionID)contextID; -@end - - /*************************************************************************/ #pragma mark - #pragma mark PRIVATE METHOD DECLARATIONS @@ -28,14 +18,8 @@ exitMode:(ITTransientStatusWindowExitMode)exitMode backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType; - (void)rebuildWindow; -- (void)performEffect; -- (void)dissolveEffect; -- (void)slideVerticalEffect; -- (void)slideHorizontalEffect; -- (void)pivotEffect; -- (void)pivotStep; -- (void)pivotFinish; -- (void)setPivot:(float)angle; +- (void)startVanishTimer; +- (void)stopVanishTimer; @end @@ -90,20 +74,19 @@ static ITTransientStatusWindow *staticWindow = nil; backing:NSBackingStoreBuffered defer:NO] ) ) { - _visibilityState = ITTransientStatusWindowHiddenState; + _visibilityState = ITWindowHiddenState; _exitMode = exitMode; _exitDelay = DEFAULT_EXIT_DELAY; _backgroundType = backgroundType; - _verticalPosition = ITTransientStatusWindowPositionBottom; - _horizontalPosition = ITTransientStatusWindowPositionLeft; + _verticalPosition = ITWindowPositionBottom; + _horizontalPosition = ITWindowPositionLeft; _screenPadding = 32.0; - _entryEffect = ITTransientStatusWindowEffectNone; - _exitEffect = ITTransientStatusWindowEffectDissolve; - _effectTime = DEFAULT_EFFECT_TIME; - _effectProgress = 0.00; + //_screenNumber = 0; + _entryEffect = nil; + _exitEffect = nil; _reallyIgnoresEvents = YES; - _delayTimer = nil; - _effectTimer = nil; + _exitTimer = nil; + [self setScreen:[NSScreen mainScreen]]; // if ( _backgroundType == ITTransientStatusWindowRounded ) { // _contentSubView = contentView; @@ -119,73 +102,46 @@ static ITTransientStatusWindow *staticWindow = nil; return self; } +- (void)dealloc +{ + [_screen release]; + [super dealloc]; +} /*************************************************************************/ #pragma mark - #pragma mark INSTANCE METHODS /*************************************************************************/ -- (BOOL)ignoresMouseEvents +/*- (BOOL)ignoresMouseEvents { return _reallyIgnoresEvents; } - (void)setIgnoresMouseEvents:(BOOL)flag { - CGSValueObj key; - CGSValueObj ignore; + //CGSValueObj key; + //CGSValueObj ignore; + CGSWindowTag tags; key = CGSCreateCString("IgnoreForEvents"); ignore = CGSCreateBoolean( (flag ? kCGSTrue : kCGSFalse) ); CGSSetWindowProperty([NSApp contextID], (CGSWindowID)[self windowNumber], key, ignore); CGSReleaseObj(key); CGSReleaseObj(ignore); + + CGSGetWindowTags([NSApp contextID], (CGSWindowID)[self windowNumber], &tags, 32); - _reallyIgnoresEvents = flag; -} - -- (void)orderFront:(id)sender -{ - if ( _entryEffect == ITTransientStatusWindowEffectNone ) { - [super orderFront:sender]; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - [self performEffect]; - } - if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) { - // set the timer, and orderOut: when it lapses. - } -} - -- (void)makeKeyAndOrderFront:(id)sender -{ - if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) { - // set the timer, and orderOut: when it lapses. - } - - if ( _entryEffect == ITTransientStatusWindowEffectNone ) { - [super makeKeyAndOrderFront:sender]; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - [self performEffect]; - [self makeKeyWindow]; - } -} + if (flag) { + tags = tags | CGSTagTransparent; + } else { + tags = tags & CGSTagTransparent; + } +NSLog(@"ignore? %i", flag); + CGSSetWindowTags([NSApp contextID], (CGSWindowID)[self windowNumber], &tags, 32); -- (void)orderOut:(id)sender -{ - if ( _entryEffect == ITTransientStatusWindowEffectNone ) { - [super orderOut:sender]; - _visibilityState = ITTransientStatusWindowHiddenState; - } else { - [self performEffect]; - } -} - -- (NSTimeInterval)animationResizeTime:(NSRect)newFrame -{ - return _effectTime; -} + _reallyIgnoresEvents = flag; +}*/ /* @@ -213,11 +169,74 @@ static ITTransientStatusWindow *staticWindow = nil; */ -- (ITTransientStatusWindowVisibilityState)visibilityState +- (IBAction)appear:(id)sender +{ + if ( _visibilityState == ITWindowHiddenState ) { + // Window is hidden. Appear as normal, and start the timer. + [_entryEffect performAppear]; + } else if ( _visibilityState == ITWindowVisibleState ) { + // Window is completely visible. Simply reset the timer. + [self startVanishTimer]; + } else if ( _visibilityState == ITWindowAppearingState ) { + // Window is on its way in. Do nothing. + } else if ( _visibilityState == ITWindowVanishingState ) { + // Window is on its way out. Cancel the vanish. + [_exitEffect cancelVanish]; + } +} + +- (IBAction)vanish:(id)sender +{ + if ( _visibilityState == ITWindowVisibleState ) { + // Window is totally visible. Perform exit effect. + [_exitEffect performVanish]; + } else if ( _visibilityState == ITWindowHiddenState ) { + // Window is hidden. Do nothing. + } else if ( _visibilityState == ITWindowAppearingState ) { + // Window is on its way in. Cancel appear. + [_entryEffect cancelAppear]; + } else if ( _visibilityState == ITWindowVanishingState ) { + // Window is on its way out. Do nothing. + } +} + +- (void)setScreen:(NSScreen *)newScreen +{ + [_screen release]; + _screen = [newScreen retain]; +} + +- (NSScreen *)screen +{ + return _screen; +} + +- (void)setSizing:(ITTransientStatusWindowSizing)newSizing +{ + _sizing = newSizing; +} + +- (ITTransientStatusWindowSizing)sizing +{ + return _sizing; +} + +- (ITWindowVisibilityState)visibilityState { return _visibilityState; } +- (void)setVisibilityState:(ITWindowVisibilityState)newState +{ + _visibilityState = newState; + + if ( _visibilityState == ITWindowVisibleState ) { + [self startVanishTimer]; + } else if ( (_visibilityState == ITWindowVanishingState) || (_visibilityState == ITWindowHiddenState) ) { + [self stopVanishTimer]; + } +} + - (ITTransientStatusWindowExitMode)exitMode { return _exitMode; @@ -226,6 +245,14 @@ static ITTransientStatusWindow *staticWindow = nil; - (void)setExitMode:(ITTransientStatusWindowExitMode)newMode { _exitMode = newMode; + + if ( _visibilityState == ITWindowVisibleState ) { + if ( _exitMode == ITTransientStatusWindowExitOnCommand ) { + [self stopVanishTimer]; + } else if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) { + [self startVanishTimer]; + } + } } - (float)exitDelay @@ -251,26 +278,56 @@ static ITTransientStatusWindow *staticWindow = nil; _backgroundType = ITTransientStatusWindowRounded; } -- (ITTransientStatusWindowPosition)verticalPosition; +- (ITVerticalWindowPosition)verticalPosition; { return _verticalPosition; } -- (void)setVerticalPosition:(ITTransientStatusWindowPosition)newPosition; +- (void)setVerticalPosition:(ITVerticalWindowPosition)newPosition; { _verticalPosition = newPosition; } -- (ITTransientStatusWindowPosition)horizontalPosition; +- (ITHorizontalWindowPosition)horizontalPosition; { return _horizontalPosition; } -- (void)setHorizontalPosition:(ITTransientStatusWindowPosition)newPosition; +- (void)setHorizontalPosition:(ITHorizontalWindowPosition)newPosition; { _horizontalPosition = newPosition; } +- (float)effectProgress +{ + return _effectProgress; +} + +- (void)setEffectProgress:(float)newProgress +{ + _effectProgress = newProgress; +} + +- (float)screenPadding +{ + return _screenPadding; +} + +- (void)setScreenPadding:(float)newPadding +{ + _screenPadding = newPadding; +} + +/*- (int)screenNumber +{ + return _screenNumber; +} + +- (void)setScreenNumber:(int)newNumber +{ + _screenNumber = newNumber; +}*/ + - (ITWindowEffect *)entryEffect { return _entryEffect; @@ -278,7 +335,7 @@ static ITTransientStatusWindow *staticWindow = nil; - (void)setEntryEffect:(ITWindowEffect *)newEffect { - [_entryEffect autorelease]; + [_entryEffect releaseWhenIdle]; _entryEffect = [newEffect retain]; } @@ -289,7 +346,7 @@ static ITTransientStatusWindow *staticWindow = nil; - (void)setExitEffect:(ITWindowEffect *)newEffect { - [_exitEffect autorelease]; + [_exitEffect releaseWhenIdle]; _exitEffect = [newEffect retain]; } @@ -302,7 +359,7 @@ static ITTransientStatusWindow *staticWindow = nil; - (void)rebuildWindow; { if ( _backgroundType == ITTransientStatusWindowRounded ) { - ITGrayRoundedView *roundedView = [[[ITGrayRoundedView alloc] initWithFrame:[self frame]] autorelease]; + ITTSWBackgroundView *roundedView = [[[ITTSWBackgroundView alloc] initWithFrame:[self frame]] autorelease]; [self setBackgroundColor:[NSColor clearColor]]; [self setHasShadow:NO]; @@ -317,122 +374,30 @@ static ITTransientStatusWindow *staticWindow = nil; } } -- (void)performEffect +- (void)startVanishTimer { - if ( _visibilityState == ITTransientStatusWindowHiddenState ) { - _visibilityState = ITTransientStatusWindowEnteringState; - } else if ( _visibilityState == ITTransientStatusWindowVisibleState ) { - _visibilityState = ITTransientStatusWindowExitingState; - } else { - return; - } - - if ( _entryEffect == ITTransientStatusWindowEffectDissolve ) { - [self dissolveEffect]; - } else if ( _entryEffect == ITTransientStatusWindowEffectSlideVertically ) { - [self slideVerticalEffect]; - } else if ( _entryEffect == ITTransientStatusWindowEffectSlideHorizontally ) { - [self slideHorizontalEffect]; - } else if ( _entryEffect == ITTransientStatusWindowEffectPivot ) { - [self pivotEffect]; + if ( _exitMode == ITTransientStatusWindowExitAfterDelay) { + [self stopVanishTimer]; + _exitTimer = [NSTimer scheduledTimerWithTimeInterval:_exitDelay + target:self + selector:@selector(doDelayedExit) + userInfo:nil + repeats:NO]; } } -- (void)dissolveEffect +- (void)doDelayedExit { - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - [super orderFront:self]; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - [super orderOut:self]; - _visibilityState = ITTransientStatusWindowHiddenState; - } + [self vanish:self]; + _exitTimer = nil; } -- (void)slideVerticalEffect +- (void)stopVanishTimer { - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - [super orderFront:self]; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - [super orderOut:self]; - _visibilityState = ITTransientStatusWindowHiddenState; + if ( _exitTimer ) { + [_exitTimer invalidate]; + _exitTimer = nil; } } -- (void)slideHorizontalEffect -{ - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - [super orderFront:self]; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - [super orderOut:self]; - _visibilityState = ITTransientStatusWindowHiddenState; - } -} - -- (void)pivotEffect -{ - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - [self setPivot:315.0]; - _effectProgress = 0.0; - [self setAlphaValue:0.0]; - [super orderFront:self]; - _effectTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / EFFECT_FPS) - target:self - selector:@selector(pivotStep) - userInfo:nil - repeats:YES]; - } else { - [super orderOut:self]; - _visibilityState = ITTransientStatusWindowHiddenState; - } -} - -- (void)pivotStep -{ - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - float interPivot = 0.0; - _effectProgress += (1.0 / (EFFECT_FPS * _effectTime)); - _effectProgress = (_effectProgress < 1.0 ? _effectProgress : 1.0); - interPivot = (( sin((_effectProgress * pi) - (pi / 2)) + 1 ) / 2); - [self setPivot:((interPivot * 45) + 315)]; - [self setAlphaValue:interPivot]; - if ( _effectProgress >= 1.0 ) { - [self pivotFinish]; - } - } else { - //backwards - } -} - -- (void)pivotFinish -{ - if ( _visibilityState == ITTransientStatusWindowEnteringState ) { - [_effectTimer invalidate]; - _effectTimer = nil; - _effectProgress = 0.0; - _visibilityState = ITTransientStatusWindowVisibleState; - } else { - //backwards - } -} - - -- (void)setPivot:(float)angle -{ - float degAngle = (angle * (pi / 180)); - CGAffineTransform transform = CGAffineTransformMakeRotation(degAngle); - - // Set pivot point - transform.tx = -32.0; - transform.ty = [self frame].size.height + 32.0; - - CGSSetWindowTransform([NSApp contextID], - (CGSWindowID)[self windowNumber], - CGAffineTransformTranslate(transform, - (([self frame].origin.x - 32.0) * -1), - (([[self screen] frame].size.height - ([self frame].origin.y) + 32.0) * -1) )); -} - @end