Changeset 583 for trunk/Cocoa/Pester


Ignore:
Timestamp:
09/20/09 04:54:14 (15 years ago)
Author:
Nicholas Riley
Message:

PSVolumeController.m: Restore volume slider functionality for 10.6; beeps on cancellation now, though.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSVolumeController.m

    r136 r583  
    2222    if ( (self = [self initWithWindowNibName: @"Volume"]) != nil) {
    2323        [self window]; // connect outlets
    24         NSWindow *window = [[NJRNonCenteringWindow alloc] initWithContentRect: [contentView bounds] styleMask: NSBorderlessWindowMask | NSTexturedBackgroundWindowMask backing: NSBackingStoreBuffered defer: NO];
     24        NSWindow *window = [[NJRNonCenteringWindow alloc] initWithContentRect: [contentView bounds] styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: NO];
    2525
    2626        if ([NJRSoundManager volumeIsNotMutedOrInvalid: volume])
     
    3030
    3131        [window setContentView: contentView];
     32        [window setInitialFirstResponder: volumeSlider];
     33        [window makeFirstResponder: volumeSlider];
    3234        [window setOpaque: NO];
    3335        [window setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.81f alpha: 0.9f]];
     
    5153        // -[NSApplication beginModalSessionForWindow:] shows and centers the window; we use NJRNonCenteringWindow to prevent the repositioning from succeeding
    5254        NSModalSession session = [NSApp beginModalSessionForWindow: window];
    53         [volumeSlider mouseDown: [NSApp currentEvent]];
    54         [NSApp runModalSession: session];
     55        // In 10.6, we can no longer force the modal session to work by "seeding" the slider with a mouse-down event.
     56        // Instead, we stop the modal session on a volume change.
     57        while ([NSApp runModalSession: session] == NSRunContinuesResponse) {
     58            // Any mouse click events that do not change the slider value should abort.
     59            NSEvent *event = [NSApp currentEvent];
     60            unsigned int eventTypeMask = NSEventMaskFromType([event type]);
     61            if (eventTypeMask & (NSLeftMouseDownMask | NSRightMouseDownMask | NSOtherMouseDownMask)) {
     62                [NSApp preventWindowOrdering];
     63                [NSApp discardEventsMatchingMask: NSAnyEventMask beforeEvent: event];
     64                break;
     65            }
     66            if (eventTypeMask & (NSKeyDownMask | NSKeyUpMask)) {
     67                unsigned short keyCode = [event keyCode];
     68                if (keyCode == 53 || keyCode == 36 || keyCode == 76) { // escape, return, enter
     69                    [NSApp discardEventsMatchingMask: NSAnyEventMask beforeEvent: event];
     70                    break;
     71                }
     72            }
     73        }
    5574        [NSApp endModalSession: session];
    5675        [window close];
     
    7089{
    7190    [delegate volumeController: self didSetVolume: [sender floatValue]];
     91    [NSApp stopModal];
    7292}
    7393
Note: See TracChangeset for help on using the changeset viewer.