Positioning Fixes. The window might still do some weirdness if you change its positi...
[ITKit.git] / ITTransientStatusWindow.m
index f2ed917..4f03f53 100755 (executable)
@@ -1,9 +1,9 @@
 #import "ITTransientStatusWindow.h"
 #import "ITWindowEffect.h"
-#import <CoreGraphics/CoreGraphics.h>
+#import <ApplicationServices/ApplicationServices.h>
 #import "ITCoreGraphicsHacks.h"
 #import "ITTextField.h"
-#import "ITGrayRoundedView.h"
+#import "ITTSWBackgroundView.h"
 
 #define EFFECT_FPS 30.0
 
@@ -19,6 +19,7 @@
            backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType;
 - (void)rebuildWindow;
 - (void)startVanishTimer;
+- (void)stopVanishTimer;
 @end
 
 
@@ -73,18 +74,18 @@ static ITTransientStatusWindow *staticWindow = nil;
                                      backing:NSBackingStoreBuffered
                                        defer:NO] ) ) {
                                     
-        _visibilityState     = ITTransientStatusWindowHiddenState;
+        _visibilityState     = ITWindowHiddenState;
         _exitMode            = exitMode;
         _exitDelay           = DEFAULT_EXIT_DELAY;
         _backgroundType      = backgroundType;
         _verticalPosition    = ITWindowPositionBottom;
         _horizontalPosition  = ITWindowPositionLeft;
         _screenPadding       = 32.0;
-        _screenNumber        = 0;
+        //_screenNumber        = 0;
         _entryEffect         = nil;
         _exitEffect          = nil;
         _reallyIgnoresEvents = YES;
-        _delayTimer          = nil;
+        _exitTimer           = nil;
 
 //      if ( _backgroundType == ITTransientStatusWindowRounded ) {
 //          _contentSubView = contentView;
@@ -125,7 +126,6 @@ static ITTransientStatusWindow *staticWindow = nil;
     _reallyIgnoresEvents = flag;
 }
 
-
 /*
 
 - (id)contentView
@@ -152,62 +152,33 @@ static ITTransientStatusWindow *staticWindow = nil;
 
 */
 
- - (IBAction)appear:(id)sender
- {
-    NSLog(@"%i", _visibilityState);
-    if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
+- (IBAction)appear:(id)sender
+{
+    if ( _visibilityState == ITWindowHiddenState ) {
          // Window is hidden.  Appear as normal, and start the timer.
-        if ( _entryEffect == nil ) {
-            [self orderFront:self];
-            _visibilityState = ITTransientStatusWindowVisibleState;
-        } else {
-            _visibilityState = ITTransientStatusWindowAppearingState;
-            [_entryEffect performAppear];
-            _visibilityState = ITTransientStatusWindowVisibleState;
-        }
-        [self startVanishTimer];
-    } else if ( _visibilityState == ITTransientStatusWindowVisibleState ) {
+        [_entryEffect performAppear];
+    } else if ( _visibilityState == ITWindowVisibleState ) {
          // Window is completely visible.  Simply reset the timer.
         [self startVanishTimer];
-    } else if ( _visibilityState == ITTransientStatusWindowAppearingState ) {
-         // Window is appearing.  Do nothing.
-    } else if ( _visibilityState == ITTransientStatusWindowVanishingState ) {
-        NSLog(@"%i", _visibilityState);
-        if ( _exitEffect == nil ) {
-            [self orderFront:self];
-            _visibilityState = ITTransientStatusWindowVisibleState;
-        } else {
-            _visibilityState = ITTransientStatusWindowAppearingState;
-            [_exitEffect cancelVanish];
-            _visibilityState = ITTransientStatusWindowVisibleState;
-        }
-        [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 == ITTransientStatusWindowVisibleState ) {
+    if ( _visibilityState == ITWindowVisibleState ) {
         // Window is totally visible.  Perform exit effect.
-        if ( _exitEffect == nil ) {
-            [self orderOut:self];
-            _visibilityState = ITTransientStatusWindowHiddenState;
-        } else {
-            _visibilityState = ITTransientStatusWindowVanishingState;
-            NSLog(@"%i", _visibilityState);
-            [_exitEffect performVanish];
-            NSLog(@"%i", _visibilityState);
-            _visibilityState = ITTransientStatusWindowHiddenState;
-            NSLog(@"%i", _visibilityState);
-        }
-        [self startVanishTimer];
-    } else if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
+        [_exitEffect performVanish];
+    } else if ( _visibilityState == ITWindowHiddenState ) {
         // Window is hidden.  Do nothing.
-    } else if ( _visibilityState == ITTransientStatusWindowAppearingState ) {
+    } else if ( _visibilityState == ITWindowAppearingState ) {
         // Window is on its way in.  Cancel appear.
         [_entryEffect cancelAppear];
-        _visibilityState = ITTransientStatusWindowHiddenState;
-    } else if ( _visibilityState == ITTransientStatusWindowVanishingState ) {
+    } else if ( _visibilityState == ITWindowVanishingState ) {
         // Window is on its way out.  Do nothing.
     }
 }
@@ -220,6 +191,12 @@ static ITTransientStatusWindow *staticWindow = nil;
 - (void)setVisibilityState:(ITWindowVisibilityState)newState
 {
     _visibilityState = newState;
+    
+    if ( _visibilityState == ITWindowVisibleState ) {
+        [self startVanishTimer];
+    } else if ( (_visibilityState == ITWindowVanishingState) || (_visibilityState == ITWindowHiddenState) ) {
+        [self stopVanishTimer];
+    }
 }
 
 - (ITTransientStatusWindowExitMode)exitMode
@@ -230,6 +207,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
@@ -275,6 +260,16 @@ static ITTransientStatusWindow *staticWindow = nil;
     _horizontalPosition = newPosition;
 }
 
+- (float)effectProgress
+{
+    return _effectProgress;
+}
+
+- (void)setEffectProgress:(float)newProgress
+{
+    _effectProgress = newProgress;
+}
+
 - (float)screenPadding
 {
     return _screenPadding;
@@ -285,7 +280,7 @@ static ITTransientStatusWindow *staticWindow = nil;
     _screenPadding = newPadding;
 }
 
-- (int)screenNumber
+/*- (int)screenNumber
 {
     return _screenNumber;
 }
@@ -293,7 +288,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 - (void)setScreenNumber:(int)newNumber
 {
     _screenNumber = newNumber;
-}
+}*/
 
 - (ITWindowEffect *)entryEffect
 {
@@ -302,7 +297,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 
 - (void)setEntryEffect:(ITWindowEffect *)newEffect
 {
-    [_entryEffect autorelease];
+    [_entryEffect releaseWhenIdle];
     _entryEffect = [newEffect retain];
 }
 
@@ -313,7 +308,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 
 - (void)setExitEffect:(ITWindowEffect *)newEffect
 {
-    [_exitEffect autorelease];
+    [_exitEffect releaseWhenIdle];
     _exitEffect = [newEffect retain];
 }
 
@@ -326,7 +321,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];
@@ -343,7 +338,28 @@ static ITTransientStatusWindow *staticWindow = nil;
 
 - (void)startVanishTimer
 {
+    if ( _exitMode == ITTransientStatusWindowExitAfterDelay) {
+        [self stopVanishTimer];
+        _exitTimer = [NSTimer scheduledTimerWithTimeInterval:_exitDelay
+                                                      target:self
+                                                    selector:@selector(doDelayedExit)
+                                                    userInfo:nil
+                                                     repeats:NO];
+    }
+}
 
+- (void)doDelayedExit
+{
+    [self vanish:self];
+    _exitTimer = nil;
+}
+
+- (void)stopVanishTimer
+{
+    if ( _exitTimer ) {
+        [_exitTimer invalidate];
+        _exitTimer = nil;
+    }
 }
 
 @end