source: releases/Pester/1.1b1/Source/PSMovieAlertController.m@ 585

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

PSScriptAlert.m: Removed reference to NDAppleScriptObject.

PSMovieAlertController.[hm]: Added minimum sizing.

NJRCenteringMovieView.[hm]: Support for centering movie inside its
frame if the frame is too large for the movie; sizes movie
proportionally if necessary (not used in Pester).

NSImage-NJRExtensions.[hm]: Fixed copyright.

Read Me.rtfd: Updated with bug fixes.

PSMovieAlert.m: Note bug in NSMovieView, currently doesn't affect us.

NJRQTMediaPopUpButton.m: Work around background processor use bug when
NSMovieView has movie set but not playing.

NJRVoicePopUpButton.m: Removed obsolete comment.

PSApplication.m: Only show alarm set window on rapp if alerts aren't
expiring.

PSAlarms.[hm]: Added -alarmsExpiring for support of conditional
rapp window open feature in PSApplication.

PSAlarmSetController.m: Stop window update timer and movie playback on
hide, restart timer on activate - fixes background processor usage.

File size: 4.6 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@implementation PSMovieAlertController
16
17+ (PSMovieAlertController *)controllerWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
18{
19 return [[self alloc] initWithAlarm: anAlarm movieAlert: anAlert];
20}
21
22- (void)play;
23{
24 NSTimeInterval delay;
25 if (repetitions == 0) return;
26 if (IsMovieDone((Movie)theMovie) || repetitionsRemaining == repetitions) {
27 if (repetitionsRemaining == 0) {
28 [self close];
29 return;
30 }
31 repetitionsRemaining--;
32 [movieView gotoBeginning: self];
33 [movieView start: self];
34 }
35 delay = (GetMovieDuration((Movie)theMovie) - GetMovieTime((Movie)theMovie, NULL)) / (double)GetMovieTimeScale((Movie)theMovie);
36 // XXX should use a timebase callback for this instead (see NJRQTMediaPopUpButton); also, use QuickTimeÕs built-in loop functionality instead of rolling our own?
37 [self performSelector: @selector(play) withObject: nil afterDelay: delay inModes: [NSArray arrayWithObject: NSDefaultRunLoopMode]];
38}
39
40- (id)initWithAlarm:(PSAlarm *)anAlarm movieAlert:(PSMovieAlert *)anAlert;
41{
42 if ([self initWithWindowNibName: @"Movie alert"]) {
43 NSMovie *movie = [anAlert movie];
44 NSWindow *window = [self window]; // connect outlets
45 alarm = anAlarm;
46 alert = anAlert;
47 [movieView setMovie: movie];
48 theMovie = [movie QTMovie];
49 if ([alert hasVideo]) {
50 NSRect screenRect = [[window screen] visibleFrame];
51 float magnification = 1.0;
52 NSSize movieSize;
53 NSSize minSize = [window minSize];
54 float windowFrameHeight = [window frame].size.height - [[window contentView] frame].size.height;
55 NSRect frame;
56 screenRect.size.height -= windowFrameHeight;
57 minSize.height -= windowFrameHeight;
58 while (1) {
59 movieSize = [movieView sizeForMagnification: magnification];
60 movieSize.height -= 16; // controller is hidden, but its size is included (documented, ergh)
61 if (movieSize.width > screenRect.size.width || movieSize.height > screenRect.size.height)
62 magnification /= 2;
63 else
64 break;
65 }
66 if (movieSize.width < minSize.width) movieSize.width = minSize.width;
67 if (movieSize.height < minSize.height) movieSize.width = minSize.height;
68 [window setContentSize: movieSize];
69 [window center];
70 frame = [window frame];
71 frame.origin.y -= 400; // appear below notifier window - XXX this is very inaccurate, fix
72 if (frame.origin.y < screenRect.origin.y) frame.origin.y = screenRect.origin.y;
73 [window setFrame: frame display: NO];
74 [window setTitle: [alarm message]];
75 { // XXX workaround for (IMO) ugly appearance of Cocoa utility windows
76 NSView *miniButton = [window standardWindowButton: NSWindowMiniaturizeButton],
77 *zoomButton = [window standardWindowButton: NSWindowZoomButton];
78 // NOTE: this will not work if the window is resizable: when the frame is reset, the standard buttons reappear
79 [miniButton setFrameOrigin: NSMakePoint(-100, -100)];
80 [zoomButton setFrameOrigin: NSMakePoint(-100, -100)];
81 [[miniButton superview] setNeedsDisplay: YES];
82 [[zoomButton superview] setNeedsDisplay: YES];
83 }
84 [[self window] orderFrontRegardless];
85 }
86 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(close) name: PSAlarmAlertStopNotification object: nil];
87 repetitions = [alert repetitions];
88 repetitionsRemaining = repetitions;
89 if (![movie isStatic]) [self play]; // if it's an image, don't close the window automatically
90 }
91 return self;
92}
93
94- (void)dealloc;
95{
96 [[NSNotificationCenter defaultCenter] removeObserver: self];
97 [super dealloc];
98}
99
100@end
101
102@implementation PSMovieAlertController (NSWindowNotifications)
103
104- (void)windowWillClose:(NSNotification *)notification;
105{
106 repetitions = 0;
107 [movieView stop: self];
108 [alert completedForAlarm: alarm];
109 [self autorelease];
110 // 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.
111}
112
113@end
Note: See TracBrowser for help on using the repository browser.