source: releases/Pester/1.1a5/Source/PSMovieAlertController.m@ 312

Last change on this file since 312 was 53, checked in by Nicholas Riley, 22 years ago

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

File size: 4.3 KB
Line 
1//
2// PSMovieAlertController.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlarmAlertController.h"
10#import "PSMovieAlertController.h"
11#import "PSMovieAlert.h"
12#import "NSMovie-NJRExtensions.h"
13#import <QuickTime/Movies.h>
14
15// XXX if you specify a truly tiny movie, obey the minimum window size to compensate
16
17@implementation PSMovieAlertController
18
19+ (PSMovieAlertController *)controllerWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
20{
21 return [[self alloc] initWithAlarm: anAlarm movieAlert: anAlert];
22}
23
24- (void)play;
25{
26 NSTimeInterval delay;
27 if (repetitions == 0) return;
28 if (IsMovieDone((Movie)theMovie) || repetitionsRemaining == repetitions) {
29 if (repetitionsRemaining == 0) {
30 [self close];
31 return;
32 }
33 repetitionsRemaining--;
34 [movieView gotoBeginning: self];
35 [movieView start: self];
36 }
37 delay = (GetMovieDuration((Movie)theMovie) - GetMovieTime((Movie)theMovie, NULL)) / (double)GetMovieTimeScale((Movie)theMovie);
38 [self performSelector: @selector(play) withObject: nil afterDelay: delay inModes: [NSArray arrayWithObject: NSDefaultRunLoopMode]];
39}
40
41- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
42{
43 if ([self initWithWindowNibName: @"Movie alert"]) {
44 NSMovie *movie = [anAlert movie];
45 NSWindow *window = [self window]; // connect outlets
46 alarm = anAlarm;
47 alert = anAlert;
48 [movieView setMovie: movie];
49 theMovie = [movie QTMovie];
50 if ([alert hasVideo]) {
51 NSRect screenRect = [[window screen] visibleFrame];
52 float magnification = 1.0;
53 NSSize movieSize;
54 NSRect frame;
55 screenRect.size.height -= [window frame].size.height - [[window contentView] frame].size.height; // account for height of window frame
56 while (1) {
57 movieSize = [movieView sizeForMagnification: magnification];
58 movieSize.height -= 16; // controller is hidden, but its size is included (documented, ergh)
59 if (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height)
60 magnification /= 2;
61 else
62 break;
63 }
64 [window setContentSize: movieSize];
65 [window center];
66 frame = [window frame];
67 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
68 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
69 [window setFrame: frame display: NO];
70 [window setTitle: [alarm message]];
71 { // XXX workaround for (IMO) ugly appearance of Cocoa utility windows
72 NSView *miniButton = [window standardWindowButton: NSWindowMiniaturizeButton],
73 *zoomButton = [window standardWindowButton: NSWindowZoomButton];
74 // NOTE: this will not work if the window is resizable: when the frame is reset, the standard buttons reappear
75 [miniButton setFrameOrigin: NSMakePoint(-100, -100)];
76 [zoomButton setFrameOrigin: NSMakePoint(-100, -100)];
77 [[miniButton superview] setNeedsDisplay: YES];
78 [[zoomButton superview] setNeedsDisplay: YES];
79 }
80 [[self window] orderFrontRegardless];
81 }
82 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
83 repetitions = [alert repetitions];
84 repetitionsRemaining = repetitions;
85 if (![movie isStatic]) [self play]; // if it's an image, don't close the window automatically
86 }
87 return self;
88}
89
90- (void)dealloc;
91{
92 [[NSNotificationCenter defaultCenter] removeObserver: self];
93 [super dealloc];
94}
95
96@end
97
98@implementation PSMovieAlertController (NSWindowNotifications)
99
100- (void)windowWillClose:(NSNotification *)notification;
101{
102 repetitions = 0;
103 [movieView stop: self];
104 [alert completedForAlarm: alarm];
105 [self autorelease];
106 // note: there may still be a retained copy of this object until the runloop timer has let go of us at the end of the current movie playback cycle; donÕt worry about it.
107}
108
109@end
Note: See TracBrowser for help on using the repository browser.