]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/fspanel.m
Useless #includes
[vlc] / modules / gui / macosx / fspanel.m
index 99376f02e5165a509ff2f1d75568515f2c4e4095..d941fc33ee97545eb57ad684a2518d464ad95638 100644 (file)
@@ -31,7 +31,6 @@
 #import "misc.h"
 #import "fspanel.h"
 #import "CompatibilityFixes.h"
-#import <vlc_aout_intf.h>
 
 @interface VLCFSPanel ()
 - (void)hideMouse;
@@ -51,7 +50,7 @@
     [win setOpaque:NO];
     [win setHasShadow: NO];
     [win setBackgroundColor:[NSColor clearColor]];
-    if (OSX_LION)
+    if (!OSX_SNOW_LEOPARD)
         [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
 
     /* let the window sit on top of everything else and start out completely transparent */
 {
     [[NSNotificationCenter defaultCenter] removeObserver: self];
 
-    if( hideAgainTimer )
-    {
+    if (hideAgainTimer) {
         [hideAgainTimer invalidate];
         [hideAgainTimer release];
     }
+
+    if (o_vout_window)
+        [o_vout_window release];
+
     [self setFadeTimer:nil];
     [super dealloc];
 }
     screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
 
     if (!screen)
-    {
         /* invalid preferences or none specified, using main screen */
         screen = [NSScreen mainScreen];
-    }
 
     theScreensFrame = [screen frame];
     theWindowsFrame = [self frame];
 - (void)focus:(NSTimer *)timer
 {
     /* we need to push ourselves to front if the vout window was closed since our last display */
-    if( b_voutWasUpdated )
-    {
+    if (b_voutWasUpdated) {
         [self orderFront: self];
         b_voutWasUpdated = NO;
     }
 
-    if( [self alphaValue] < 1.0 )
+    if ([self alphaValue] < 1.0)
         [self setAlphaValue:[self alphaValue]+0.1];
-    if( [self alphaValue] >= 1.0 )
-    {
+    if ([self alphaValue] >= 1.0) {
         b_displayed = YES;
         [self setAlphaValue: 1.0];
         [self setFadeTimer:nil];
-        if( b_fadeQueued )
-        {
+        if (b_fadeQueued) {
             b_fadeQueued=NO;
             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
         }
 /* This routine is called repeatedly to hide the window */
 - (void)unfocus:(NSTimer *)timer
 {
-    if( b_keptVisible )
-    {
+    if (b_keptVisible) {
         b_keptVisible = NO;
         b_fadeQueued = NO;
         [self setFadeTimer: NULL];
         [self fadeIn];
         return;
     }
-    if( [self alphaValue] > 0.0 )
+    if ([self alphaValue] > 0.0)
         [self setAlphaValue:[self alphaValue]-0.05];
-    if( [self alphaValue] <= 0.05 )
-    {
+    if ([self alphaValue] <= 0.05) {
         b_displayed = NO;
         [self setAlphaValue:0.0];
         [self setFadeTimer:nil];
-        if( b_fadeQueued )
-        {
+        if (b_fadeQueued) {
             b_fadeQueued=NO;
             [self setFadeTimer:
                 [NSTimer scheduledTimerWithTimeInterval:0.1
 - (void)mouseExited:(NSEvent *)theEvent
 {
     /* give up our focus, so the vout may show us again without letting the user clicking it */
-    vout_thread_t *p_vout = getVout();
-    if (p_vout)
-    {
-        if (var_GetBool( p_vout, "fullscreen" ))
-            [[[[VLCMainWindow sharedInstance] videoView] window] makeKeyWindow];
-        vlc_object_release( p_vout );
-    }
+    if (o_vout_window && var_GetBool(pl_Get(VLCIntf), "fullscreen"))
+        [o_vout_window makeKeyWindow];
 }
 
 - (void)hideMouse
 {
     /* in case that the user don't want us to appear, make sure we hide the mouse */
 
-    if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
-    {
-        float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
+    if (!config_GetInt(VLCIntf, "macosx-fspanel")) {
+        float time = (float)var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 1000.;
         [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
         return;
     }
 
-    if( b_nonActive )
+    if (b_nonActive)
         return;
 
     [self orderFront: nil];
 
-    if( [self alphaValue] < 1.0 || b_displayed != YES )
-    {
+    if ([self alphaValue] < 1.0 || b_displayed != YES) {
         if (![self fadeTimer])
             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
         else if ([[[self fadeTimer] userInfo] shortValue]==0)
 
 - (void)fadeOut
 {
-    ifNSPointInRect([NSEvent mouseLocation],[self frame]))
+    if (NSPointInRect([NSEvent mouseLocation],[self frame]))
         return;
 
-    if( ( [self alphaValue] > 0.0 ) )
-    {
+    if (([self alphaValue] > 0.0)) {
         if (![self fadeTimer])
             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
         else if ([[[self fadeTimer] userInfo] shortValue]==1)
     b_keptVisible = YES;
 
     /* get us a valid timer */
-    if(! b_alreadyCounting )
-    {
-        i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
-        if( hideAgainTimer )
-        {
+    if (! b_alreadyCounting) {
+        i_timeToKeepVisibleInSec = var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 500;
+        if (hideAgainTimer) {
             [hideAgainTimer invalidate];
             [hideAgainTimer autorelease];
         }
 - (void)keepVisible:(NSTimer *)timer
 {
     /* if the user triggered an action, start over again */
-    if( b_keptVisible )
+    if (b_keptVisible)
         b_keptVisible = NO;
 
     /* count down until we hide ourselfes again and do so if necessary */
-    if( --i_timeToKeepVisibleInSec < 1 )
-    {
+    if (--i_timeToKeepVisibleInSec < 1) {
         [self hideMouse];
         [self fadeOut];
         [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
     [self setFrameOrigin:point];
 }
 
-- (BOOL)isDisplayed
-{
-    return b_displayed;
-}
-
-- (void)setVoutWasUpdated: (int)i_newdevice;
+- (void)setVoutWasUpdated: (VLCWindow *)o_window
 {
     b_voutWasUpdated = YES;
-    if( i_newdevice != i_device )
-    {
+    if (o_vout_window)
+        [o_vout_window release];
+    o_vout_window = [o_window retain];
+    int i_newdevice = (int)[[o_vout_window screen] displayID];
+    if (i_newdevice != i_device) {
         i_device = i_newdevice;
         [self center];
     }
  *****************************************************************************/
 @implementation VLCFSPanelView
 
-#define addButton( o_button, imageOff, imageOn, _x, _y, action )                                \
+#define addButton(o_button, imageOff, imageOn, _x, _y, action, AXDesc, ToolTip)               \
     s_rc.origin.x = _x;                                                                         \
     s_rc.origin.y = _y;                                                                         \
     o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \
     [o_button sizeToFit];                                                                       \
     [o_button setTarget: self];                                                                 \
     [o_button setAction: @selector(action:)];                                                   \
+    [[o_button cell] accessibilitySetOverrideValue:AXDesc forAttribute:NSAccessibilityDescriptionAttribute]; \
+    [[o_button cell] accessibilitySetOverrideValue:ToolTip forAttribute:NSAccessibilityTitleAttribute]; \
+    [o_button setToolTip: ToolTip]; \
     [self addSubview:o_button];
 
-#define addTextfield( class, o_text, align, font, color )                                    \
+#define addTextfield(class, o_text, align, font, color)                                    \
     o_text = [[class alloc] initWithFrame: s_rc];                            \
     [o_text setDrawsBackground: NO];                                                        \
     [o_text setBordered: NO];                                                               \
     id view = [super initWithFrame:frameRect];
     fillColor = [[NSColor clearColor] retain];
     NSRect s_rc = [self frame];
-    addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
-    addButton( o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward );
-    addButton( o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play );
-    addButton( o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward );
-    addButton( o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next );
-    addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, toggleFullscreen );
+    addButton(o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev, _NS("Click to go to the previous playlist item."), _NS("Previous"));
+    addButton(o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward, _NS("Click and hold to skip backward through the current media."), _NS("Backward"));
+    addButton(o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play, _NS("Click to play or pause the current media."), _NS("Play/Pause"));
+    addButton(o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward, _NS("Click and hold to skip forward through the current media."), _NS("Forward"));
+    addButton(o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next, _NS("Click to go to the next playlist item."), _NS("Next"));
+    addButton(o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, toggleFullscreen, _NS("Click to exit fullscreen playback."), _NS("Toggle Fullscreen mode"));
 /*
-    addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
+    addButton(o_button, @"image (off state)", @"image (on state)", 38, 51, something, accessibility help string, usual tool tip);
  */
+    [o_fwd setContinuous:YES];
+    [o_bwd setContinuous:YES];
 
     /* time slider */
-    s_rc = [self frame];
+    // (surrounding progress view for swipe behaviour)
     s_rc.origin.x = 15;
-    s_rc.origin.y = 55;
+    s_rc.origin.y = 45;
     s_rc.size.width = 518;
-    s_rc.size.height = 9;
+    s_rc.size.height = 13;
+    o_progress_view = [[VLCProgressView alloc] initWithFrame: s_rc];
+    s_rc.origin.x = 0;
+    s_rc.origin.y = 0;
     o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
     [o_fs_timeSlider setMinValue:0];
     [o_fs_timeSlider setMaxValue:10000];
     [o_fs_timeSlider setContinuous: YES];
     [o_fs_timeSlider setTarget: self];
     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
-    [self addSubview: o_fs_timeSlider];
+    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Position") forAttribute:NSAccessibilityTitleAttribute];
+    [[o_fs_timeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change current playback position.") forAttribute:NSAccessibilityDescriptionAttribute];
+    [self addSubview: o_progress_view];
+    [o_progress_view addSubview: o_fs_timeSlider];
 
     /* volume slider */
     s_rc = [self frame];
     [o_fs_volumeSlider setContinuous: YES];
     [o_fs_volumeSlider setTarget: self];
     [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
+    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Volume") forAttribute:NSAccessibilityTitleAttribute];
+    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change the volume.") forAttribute:NSAccessibilityDescriptionAttribute];
     [self addSubview: o_fs_volumeSlider];
 
     /* time counter and stream title output fields */
     s_rc.origin.y = 64;
     s_rc.size.width = 352;
     s_rc.size.height = 14;
-    addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor );
+    addTextfield(NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor);
     s_rc.origin.x = 471;
     s_rc.origin.y = 64;
     s_rc.size.width = 65;
-    addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor );
+    addTextfield(VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor);
+
+    o_background_img = [[NSImage imageNamed:@"fs_background"] retain];
+    o_vol_sld_img = [[NSImage imageNamed:@"fs_volume_slider_bar"] retain];
+    o_vol_mute_img = [[NSImage imageNamed:@"fs_volume_mute"] retain];
+    o_vol_max_img = [[NSImage imageNamed:@"fs_volume_max"] retain];
+    o_time_sld_img = [[NSImage imageNamed:@"fs_time_slider"] retain];
 
     return view;
 }
 
 - (void)dealloc
 {
+    [o_background_img release];
+    [o_vol_sld_img release];
+    [o_vol_mute_img release];
+    [o_vol_max_img release];
+    [o_time_sld_img release];
     [o_fs_timeSlider release];
     [o_fs_volumeSlider release];
     [o_prev release];
 
 - (IBAction)forward:(id)sender
 {
-    [[VLCCoreInteraction sharedInstance] forward];
+    if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
+        // we just skipped 4 "continous" events, otherwise we are too fast
+        [[VLCCoreInteraction sharedInstance] forwardExtraShort];
+        last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
+    }
 }
 
 - (IBAction)backward:(id)sender
 {
-    [[VLCCoreInteraction sharedInstance] backward];
+    if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) > 0.16) {
+        // we just skipped 4 "continous" events, otherwise we are too fast
+        [[VLCCoreInteraction sharedInstance] backwardExtraShort];
+        last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
+    }
 }
 
 - (IBAction)prev:(id)sender
 - (IBAction)fsTimeSliderUpdate:(id)sender
 {
     input_thread_t * p_input;
-    p_input = pl_CurrentInput( VLCIntf );
-    if( p_input != NULL )
-    {
+    p_input = pl_CurrentInput(VLCIntf);
+    if (p_input != NULL) {
         vlc_value_t pos;
 
         pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
-        var_Set( p_input, "position", pos );
-        vlc_object_release( p_input );
+        var_Set(p_input, "position", pos);
+        vlc_object_release(p_input);
     }
     [[VLCMain sharedInstance] updatePlaybackPosition];
 }
     [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
 }
 
-#define addImage(image, _x, _y, mode, _width)                                               \
-    img = [NSImage imageNamed:image];                                              \
-    image_rect.size = [img size];                                                           \
+#define addImage(image, _x, _y, mode)                                                       \
+    image_size = [image size];                                                              \
+    image_rect.size = image_size;                                                           \
     image_rect.origin.x = 0;                                                                \
     image_rect.origin.y = 0;                                                                \
     frame.origin.x = _x;                                                                    \
     frame.origin.y = _y;                                                                    \
-    frame.size = [img size];                                                                \
-    if( _width ) frame.size.width = _width;                                                 \
-    [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
+    frame.size = image_size;                                                                \
+    [image drawInRect:frame fromRect:image_rect operation:mode fraction:1];
 
 - (void)drawRect:(NSRect)rect
 {
     NSRect frame = [self frame];
     NSRect image_rect;
+    NSSize image_size;
     NSImage *img;
-    addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
-    addImage( @"fs_volume_slider_bar", 26, 23, NSCompositeSourceOver, 0 );
-    addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
-    addImage( @"fs_volume_max", 124, 18, NSCompositeSourceOver, 0 );
-    addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
+    addImage(o_background_img, 0, 0, NSCompositeCopy);
+    addImage(o_vol_sld_img, 26, 23, NSCompositeSourceOver);
+    addImage(o_vol_mute_img, 16, 18, NSCompositeSourceOver);
+    addImage(o_vol_max_img, 124, 18, NSCompositeSourceOver);
+    addImage(o_time_sld_img, 15, 45, NSCompositeSourceOver);
 }
 
 @end
     [[NSGraphicsContext currentContext] restoreGraphicsState];
 
     NSRect knobRect = [[self cell] knobRectFlipped:NO];
-    knobRect.origin.y+=7.5;
+    knobRect.origin.y+=4;
     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
     [self drawKnobInRect: knobRect];
 }