Removing ITKit dependencies on F-Script framework. Currently working on ITBridging...
[ITKit.git] / ITTransientStatusWindow.m
old mode 100755 (executable)
new mode 100644 (file)
index e44f703..24aa83b
@@ -1,20 +1,11 @@
 #import "ITTransientStatusWindow.h"
 #import "ITTransientStatusWindow.h"
-#import <CoreGraphics/CoreGraphics.h>
+#import "ITWindowEffect.h"
+#import <ApplicationServices/ApplicationServices.h>
 #import "ITCoreGraphicsHacks.h"
 #import "ITTextField.h"
 #import "ITCoreGraphicsHacks.h"
 #import "ITTextField.h"
-#import "ITGrayRoundedView.h"
+#import "ITTSWBackgroundView.h"
 
 
-@class ITTextField;
-@class ITGrayRoundedView;
-
-/*************************************************************************/
-#pragma mark -
-#pragma mark EVIL HACKERY
-/*************************************************************************/
-
-@interface NSApplication (HACKHACKHACKHACK)
-- (CGSConnectionID)contextID;
-@end
+#define EFFECT_FPS 30.0
 
 
 /*************************************************************************/
 
 
 /*************************************************************************/
                  exitMode:(ITTransientStatusWindowExitMode)exitMode
            backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType;
 - (void)rebuildWindow;
                  exitMode:(ITTransientStatusWindowExitMode)exitMode
            backgroundType:(ITTransientStatusWindowBackgroundType)backgroundType;
 - (void)rebuildWindow;
-- (void)performEffect;
-- (void)dissolveEffect:(BOOL)entering;
-- (void)slideVerticalEffect:(BOOL)entering;
-- (void)slideHorizontalEffect:(BOOL)entering;
+- (void)startVanishTimer;
+- (void)stopVanishTimer;
 @end
 
 
 @end
 
 
@@ -71,7 +60,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 {
     NSRect contentRect;
     
 {
     NSRect contentRect;
     
-    // If no Content View was provided, use a generic NSView with the app icon.
+    // If no Content View was provided, use a generic view.
     if ( ! (contentView) ) {
         contentView = [[[NSView alloc] initWithFrame:
             NSMakeRect(100.0, 100.0, 200.0, 200.0)] autorelease];
     if ( ! (contentView) ) {
         contentView = [[[NSView alloc] initWithFrame:
             NSMakeRect(100.0, 100.0, 200.0, 200.0)] autorelease];
@@ -85,24 +74,25 @@ static ITTransientStatusWindow *staticWindow = nil;
                                      backing:NSBackingStoreBuffered
                                        defer:NO] ) ) {
                                     
                                      backing:NSBackingStoreBuffered
                                        defer:NO] ) ) {
                                     
-        _visibilityState     = ITTransientStatusWindowHiddenState;
+        _visibilityState     = ITWindowHiddenState;
         _exitMode            = exitMode;
         _exitDelay           = DEFAULT_EXIT_DELAY;
         _backgroundType      = backgroundType;
         _exitMode            = exitMode;
         _exitDelay           = DEFAULT_EXIT_DELAY;
         _backgroundType      = backgroundType;
-        _verticalPosition    = ITTransientStatusWindowPositionBottom;
-        _horizontalPosition  = ITTransientStatusWindowPositionLeft;
-        _entryEffect         = ITTransientStatusWindowEffectNone;
-        _exitEffect          = ITTransientStatusWindowEffectDissolve;
-        _effectTime          = DEFAULT_EFFECT_TIME;
+        _verticalPosition    = ITWindowPositionBottom;
+        _horizontalPosition  = ITWindowPositionLeft;
+        _screenPadding       = 32.0;
+        //_screenNumber        = 0;
+        _entryEffect         = nil;
+        _exitEffect          = nil;
         _reallyIgnoresEvents = YES;
         _reallyIgnoresEvents = YES;
-        _delayTimer = nil;
-        _fadeTimer  = nil;
+        _exitTimer           = nil;
+               [self setScreen:[NSScreen mainScreen]];
 
 
-//        if ( _backgroundType == ITTransientStatusWindowRounded ) {
-//            _contentSubView = contentView;
-//        } else {
-//            [self setContentView:contentView];
-//        }
+//      if ( _backgroundType == ITTransientStatusWindowRounded ) {
+//          _contentSubView = contentView;
+//      } else {
+//          [self setContentView:contentView];
+//      }
 
         [self setIgnoresMouseEvents:YES];
         [self setLevel:NSScreenSaverWindowLevel];
 
         [self setIgnoresMouseEvents:YES];
         [self setLevel:NSScreenSaverWindowLevel];
@@ -112,84 +102,46 @@ static ITTransientStatusWindow *staticWindow = nil;
     return self;
 }
 
     return self;
 }
 
+- (void)dealloc
+{
+       [_screen release];
+       [super dealloc];
+}
 
 /*************************************************************************/
 #pragma mark -
 #pragma mark INSTANCE METHODS
 /*************************************************************************/
 
 
 /*************************************************************************/
 #pragma mark -
 #pragma mark INSTANCE METHODS
 /*************************************************************************/
 
-- (void)setRotation:(float)angle
-{
-    CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
-    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) ));
-    NSLog(@"%f %f", ([self frame].origin.x * -1), ([self frame].origin.y * -1));
-}
-
-- (BOOL)ignoresMouseEvents
+/*- (BOOL)ignoresMouseEvents
 {
     return _reallyIgnoresEvents;
 }
 
 - (void)setIgnoresMouseEvents:(BOOL)flag
 {
 {
     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);
 
     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 ( _exitMode == ITTransientStatusWindowExitAfterDelay ) {
-        // set the timer, and orderOut: when it lapses.
-    }
-
-    if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
-        [super orderFront:sender];
-    } else {
-        [self performEffect];
-    }
-}
-
-- (void)makeKeyAndOrderFront:(id)sender
-{
-    if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) {
-        // set the timer, and orderOut: when it lapses.
-    }
-
-    if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
-        [super makeKeyAndOrderFront:sender];
-    } else {
-        [self performEffect];
-        [self makeKeyWindow];
-    }
-}
-
-- (void)orderOut:(id)sender
-{
-    if ( _entryEffect == ITTransientStatusWindowEffectNone ) {
-        [super orderOut:sender];
-    } else {
-        [self performEffect];
-    }
-}
+       if (flag) {
+               tags = tags | CGSTagTransparent;
+       } else {
+               tags = tags & CGSTagTransparent;
+       }
+NSLog(@"ignore? %i", flag);
+       CGSSetWindowTags([NSApp contextID], (CGSWindowID)[self windowNumber], &tags, 32);
 
 
-- (NSTimeInterval)animationResizeTime:(NSRect)newFrame
-{
-    return _effectTime;
-}
+    _reallyIgnoresEvents = flag;
+}*/
 
 /*
 
 
 /*
 
@@ -217,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;
 }
 
 {
     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;
 - (ITTransientStatusWindowExitMode)exitMode
 {
     return _exitMode;
@@ -230,6 +245,14 @@ static ITTransientStatusWindow *staticWindow = nil;
 - (void)setExitMode:(ITTransientStatusWindowExitMode)newMode
 {
     _exitMode = newMode;
 - (void)setExitMode:(ITTransientStatusWindowExitMode)newMode
 {
     _exitMode = newMode;
+    
+    if ( _visibilityState == ITWindowVisibleState ) {
+        if ( _exitMode == ITTransientStatusWindowExitOnCommand ) {
+            [self stopVanishTimer];
+        } else if ( _exitMode == ITTransientStatusWindowExitAfterDelay ) {
+            [self startVanishTimer];
+        }
+    }
 }
 
 - (float)exitDelay
 }
 
 - (float)exitDelay
@@ -255,44 +278,76 @@ static ITTransientStatusWindow *staticWindow = nil;
     _backgroundType = ITTransientStatusWindowRounded;
 }
 
     _backgroundType = ITTransientStatusWindowRounded;
 }
 
-- (ITTransientStatusWindowPosition)verticalPosition;
+- (ITVerticalWindowPosition)verticalPosition;
 {
     return _verticalPosition;
 }
 
 {
     return _verticalPosition;
 }
 
-- (void)setVerticalPosition:(ITTransientStatusWindowPosition)newPosition;
+- (void)setVerticalPosition:(ITVerticalWindowPosition)newPosition;
 {
     _verticalPosition = newPosition;
 }
 
 {
     _verticalPosition = newPosition;
 }
 
-- (ITTransientStatusWindowPosition)horizontalPosition;
+- (ITHorizontalWindowPosition)horizontalPosition;
 {
     return _horizontalPosition;
 }
 
 {
     return _horizontalPosition;
 }
 
-- (void)setHorizontalPosition:(ITTransientStatusWindowPosition)newPosition;
+- (void)setHorizontalPosition:(ITHorizontalWindowPosition)newPosition;
 {
     _horizontalPosition = newPosition;
 }
 
 {
     _horizontalPosition = newPosition;
 }
 
-- (ITTransientStatusWindowEffect)entryEffect
+- (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;
 }
 
 {
     return _entryEffect;
 }
 
-- (void)setEntryEffect:(ITTransientStatusWindowEffect)newEffect;
+- (void)setEntryEffect:(ITWindowEffect *)newEffect
 {
 {
-    _entryEffect = newEffect;
+    [_entryEffect releaseWhenIdle];
+    _entryEffect = [newEffect retain];
 }
 
 }
 
-- (ITTransientStatusWindowEffect)exitEffect;
+- (ITWindowEffect *)exitEffect
 {
     return _exitEffect;
 }
 
 {
     return _exitEffect;
 }
 
-- (void)setExitEffect:(ITTransientStatusWindowEffect)newEffect;
+- (void)setExitEffect:(ITWindowEffect *)newEffect
 {
 {
-    _exitEffect = newEffect;
+    [_exitEffect releaseWhenIdle];
+    _exitEffect = [newEffect retain];
 }
 
 
 }
 
 
@@ -304,7 +359,7 @@ static ITTransientStatusWindow *staticWindow = nil;
 - (void)rebuildWindow;
 {
     if ( _backgroundType == ITTransientStatusWindowRounded ) {
 - (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];
 
         [self setBackgroundColor:[NSColor clearColor]];
         [self setHasShadow:NO];
@@ -319,53 +374,30 @@ static ITTransientStatusWindow *staticWindow = nil;
     }
 }
 
     }
 }
 
-- (void)performEffect
+- (void)startVanishTimer
 {
 {
-    if ( _visibilityState == ITTransientStatusWindowHiddenState ) {
-        if ( _entryEffect == ITTransientStatusWindowEffectDissolve ) {
-            [self dissolveEffect:YES];
-        } else if ( _entryEffect == ITTransientStatusWindowEffectSlideVertically ) {
-            [self slideVerticalEffect:YES];
-        } else if ( _entryEffect == ITTransientStatusWindowEffectSlideHorizontally ) {
-            [self slideHorizontalEffect:YES];
-        }
-    } else if ( _visibilityState == ITTransientStatusWindowVisibleState ) {
-        if ( _exitEffect == ITTransientStatusWindowEffectDissolve ) {
-            [self dissolveEffect:NO];
-        } else if ( _exitEffect == ITTransientStatusWindowEffectSlideVertically ) {
-            [self slideVerticalEffect:NO];
-        } else if ( _exitEffect == ITTransientStatusWindowEffectSlideHorizontally ) {
-            [self slideHorizontalEffect:NO];
-        }
+    if ( _exitMode == ITTransientStatusWindowExitAfterDelay) {
+        [self stopVanishTimer];
+        _exitTimer = [NSTimer scheduledTimerWithTimeInterval:_exitDelay
+                                                      target:self
+                                                    selector:@selector(doDelayedExit)
+                                                    userInfo:nil
+                                                     repeats:NO];
     }
 }
 
     }
 }
 
-- (void)dissolveEffect:(BOOL)entering
+- (void)doDelayedExit
 {
 {
-    if ( entering ) {
-        [super orderFront:self];
-    } else {
-        [super orderOut:self];
-    }
+    [self vanish:self];
+    _exitTimer = nil;
 }
 
 }
 
-- (void)slideVerticalEffect:(BOOL)entering
+- (void)stopVanishTimer
 {
 {
-    if ( entering ) {
-        [super orderFront:self];
-    } else {
-        [super orderOut:self];
+    if ( _exitTimer ) {
+        [_exitTimer invalidate];
+        _exitTimer = nil;
     }
 }
 
     }
 }
 
-- (void)slideHorizontalEffect:(BOOL)entering
-{
-    if ( entering ) {
-        [super orderFront:self];
-    } else {
-        [super orderOut:self];
-    }
-}
-
-
 @end
 @end