source: trunk/Cocoa/Pester/Source/PSVolumeController.m@ 346

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

PSVolumeController.m: Use NJRNonCenteringWindow to prevent the
repositioning from succeeding. Fixes bug 27.

NJRNonCenteringWindow.[hm]: Stub implementation of -[NSWindow center].
Should be removed when bug in Mac OS X is fixed (filed in Radar).

File size: 2.6 KB
Line 
1//
2// PSVolumeController.m
3// Pester
4//
5// Created by Nicholas Riley on Tue Apr 08 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "PSVolumeController.h"
10#import "NJRSoundManager.h"
11#import "NJRNonCenteringWindow.h"
12
13@implementation PSVolumeController
14
15+ (PSVolumeController *)controllerWithVolume:(float)volume delegate:(id)aDelegate;
16{
17 return [[self alloc] initWithVolume: volume delegate: aDelegate];
18}
19
20- (id)initWithVolume:(float)volume delegate:(id)aDelegate;
21{
22 if ( (self = [self initWithWindowNibName: @"Volume"]) != nil) {
23 [self window]; // connect outlets
24 NSWindow *window = [[NJRNonCenteringWindow alloc] initWithContentRect: [contentView bounds] styleMask: NSBorderlessWindowMask | NSTexturedBackgroundWindowMask backing: NSBackingStoreBuffered defer: NO];
25
26 if ([NJRSoundManager volumeIsNotMutedOrInvalid: volume])
27 [volumeSlider setFloatValue: volume];
28
29 delegate = [aDelegate retain];
30
31 [window setContentView: contentView];
32 [window setOpaque: NO];
33 [window setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.81f alpha: 0.9f]];
34 [window setHasShadow: YES];
35 [window setOneShot: YES];
36 [window setDelegate: self];
37 NSView *view = [aDelegate volumeControllerLaunchingView: self];
38 if (view != nil) {
39 NSRect rect = [view convertRect: [view bounds] toView: nil];
40 NSWindow *parentWindow = [view window];
41 rect.origin = [parentWindow convertBaseToScreen: rect.origin];
42 rect.origin.x -= [window frame].size.width - rect.size.width + 1;
43 [window setFrameTopLeftPoint: rect.origin];
44 NSRect visibleFrame = [[parentWindow screen] visibleFrame];
45 if (!NSContainsRect(visibleFrame, [window frame])) {
46 NSPoint viewTopLeft = { rect.origin.x, rect.origin.y + rect.size.height };
47 [window setFrameOrigin: viewTopLeft];
48 }
49 }
50
51 // -[NSApplication beginModalSessionForWindow:] shows and centers the window; we use NJRNonCenteringWindow to prevent the repositioning from succeeding
52 NSModalSession session = [NSApp beginModalSessionForWindow: window];
53 [volumeSlider mouseDown: [NSApp currentEvent]];
54 [NSApp runModalSession: session];
55 [NSApp endModalSession: session];
56 [window close];
57 [self autorelease];
58 // XXX make sure window and self are released
59 }
60 return self;
61}
62
63- (void)dealloc;
64{
65 [delegate release];
66 [super dealloc];
67}
68
69- (IBAction)volumeSet:(NSSlider *)sender;
70{
71 [delegate volumeController: self didSetVolume: [sender floatValue]];
72}
73
74@end
Note: See TracBrowser for help on using the repository browser.