]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/Windows.m
macosx: add custom numberformatter to goto time field to only allow digits and :
[vlc] / modules / gui / macosx / Windows.m
index d7e1066bb877fdebc24511519bd1334366b76ced..dc15ad9391e2e379b8d6b65c2b9921130b169c70 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * Windows.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2012 VLC authors and VideoLAN
+ * Copyright (C) 2012-2013 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
     [dict setObject:self forKey:NSViewAnimationTargetKey];
 
     [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
-    anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
+    anim = [[NSViewAnimation alloc] initWithViewAnimations:@[dict]];
     [dict release];
 
     [anim setAnimationBlockingMode:NSAnimationNonblocking];
     @synchronized(self) {
         current_anim = self->o_current_animation;
 
-        if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating]) {
+        if ([[current_anim viewAnimations][0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating]) {
             [anim release];
         } else {
             if (current_anim) {
     [dict setObject:self forKey:NSViewAnimationTargetKey];
 
     [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
-    anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
+    anim = [[NSViewAnimation alloc] initWithViewAnimations:@[dict]];
     [dict release];
 
     [anim setAnimationBlockingMode:NSAnimationNonblocking];
     @synchronized(self) {
         current_anim = self->o_current_animation;
 
-        if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating]) {
+        if ([[current_anim viewAnimations][0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating]) {
             [anim release];
         } else {
             if (current_anim) {
 
 @synthesize videoView=o_video_view;
 @synthesize controlsBar=o_controls_bar;
+@synthesize enteringFullscreenTransition=b_entering_fullscreen_transition;
 
 #pragma mark -
 #pragma mark Init
         return proposedFrameSize;
 
     // needed when entering lion fullscreen mode
-    if ([self fullscreen])
+    if (b_entering_fullscreen_transition || [self fullscreen])
         return proposedFrameSize;
 
     if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
 }
 
 
+#pragma mark -
+#pragma mark Mouse cursor handling
+
+//  NSTimer selectors require this function signature as per Apple's docs
+- (void)hideMouseCursor:(NSTimer *)timer
+{
+    [NSCursor setHiddenUntilMouseMoves: YES];
+}
+
+- (void)recreateHideMouseTimer
+{
+    if (t_hide_mouse_timer != nil) {
+        [t_hide_mouse_timer invalidate];
+        [t_hide_mouse_timer release];
+    }
+
+    t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
+                                                          target:self
+                                                        selector:@selector(hideMouseCursor:)
+                                                        userInfo:nil
+                                                         repeats:NO];
+    [t_hide_mouse_timer retain];
+}
+
+//  Called automatically if window's acceptsMouseMovedEvents property is true
+- (void)mouseMoved:(NSEvent *)theEvent
+{
+    if (b_fullscreen)
+        [self recreateHideMouseTimer];
+
+    [super mouseMoved: theEvent];
+}
+
 #pragma mark -
 #pragma mark Lion native fullscreen handling
 
         [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
 }
 
+- (void)resignKeyWindow
+{
+    [super resignKeyWindow];
+
+    [[[VLCMainWindow sharedInstance] fsPanel] setNonActive:nil];
+}
+
 - (void)windowWillEnterFullScreen:(NSNotification *)notification
 {
     // workaround, see #6668
     [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
 
-    [self setFullscreen: YES];
+    b_entering_fullscreen_transition = YES;
 
     var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
 
         }
     }
 
-    [o_video_view setFrame: [[self contentView] frame]];
+    if ([self hasActiveVideo])
+        [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
 
-    [[VLCMainWindow sharedInstance] recreateHideMouseTimer];
     i_originalLevel = [self level];
     [[[VLCMain sharedInstance] voutController] updateWindowLevelForHelperWindows: NSNormalWindowLevel];
     [self setLevel:NSNormalWindowLevel];
         [self setFrame: winrect display:NO animate:NO];
     }
 
-    // TODO fix bottom bar status when vout just not visible, but there
-    if (![o_video_view isHidden])
+    [o_video_view setFrame: [[self contentView] frame]];
+    if (![o_video_view isHidden]) {
         [[o_controls_bar bottomBarView] setHidden: YES];
+    }
+    
 
     [self setMovableByWindowBackground: NO];
 }
     // But this creates some problems when leaving fs over remote intfs, so activate app here.
     [NSApp activateIgnoringOtherApps:YES];
 
+    [self setFullscreen: YES];
+    b_entering_fullscreen_transition = NO;
+
     if ([self hasActiveVideo]) {
         [[[VLCMainWindow sharedInstance] fsPanel] setVoutWasUpdated: self];
-        [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
+        if (![o_video_view isHidden])
+            [[[VLCMainWindow sharedInstance] fsPanel] setActive: nil];
     }
 
     NSArray *subviews = [[self videoView] subviews];
     NSUInteger count = [subviews count];
 
     for (NSUInteger x = 0; x < count; x++) {
-        if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
-            [[subviews objectAtIndex:x] reshape];
+        if ([subviews[x] respondsToSelector:@selector(reshape)])
+            [subviews[x] reshape];
     }
 
 }
     if (b_dark_interface) {
         NSRect winrect;
         CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
-        winrect = [self frame];
 
+        winrect = [o_video_view frame];
+        winrect.size.height -= f_titleBarHeight;
+        [o_video_view setFrame: winrect];
+
+        winrect = [self frame];
         [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
                                               winrect.size.width, f_titleBarHeight)];
         [[self contentView] addSubview: o_titlebar_view];
 
         winrect.size.height = winrect.size.height + f_titleBarHeight;
         [self setFrame: winrect display:NO animate:NO];
-        winrect = [o_video_view frame];
-        winrect.size.height -= f_titleBarHeight;
-        [o_video_view setFrame: winrect];
     }
 
     NSRect videoViewFrame = [o_video_view frame];
-    videoViewFrame.origin.y = [[o_controls_bar bottomBarView] frame].size.height;
-    videoViewFrame.size.height -= [[o_controls_bar bottomBarView] frame].size.height;
+    videoViewFrame.origin.y += [o_controls_bar height];
+    videoViewFrame.size.height -= [o_controls_bar height];
     [o_video_view setFrame: videoViewFrame];
-    [[o_controls_bar bottomBarView] setHidden: NO];
+
+    if (![o_video_view isHidden]) {
+        [[o_controls_bar bottomBarView] setHidden: NO];
+    }
     
     [self setMovableByWindowBackground: YES];
 }
                 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
             }
 
-            NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
-            if ([screen hasMenuBar])
-                presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
-            if ([screen hasMenuBar] || [screen hasDock])
-                presentationOpts |= NSApplicationPresentationAutoHideDock;
-            [NSApp setPresentationOptions:presentationOpts];
+            [screen setFullscreenPresentationOptions];
 
             [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
             [o_temp_view setFrame:[o_video_view frame]];
         [o_fullscreen_anim2 release];
     }
 
-    NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
-    if ([screen hasMenuBar])
-        presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
-    if ([screen hasMenuBar] || [screen hasDock])
-        presentationOpts |= NSApplicationPresentationAutoHideDock;
-    [NSApp setPresentationOptions:presentationOpts];
+    [screen setFullscreenPresentationOptions];
 
     dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
     dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
      - Keep at most 2 animation at a time
      - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
      */
-    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
-    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
+    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict1]];
+    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict2]];
 
     [dict1 release];
     [dict2 release];
 - (void)hasBecomeFullscreen
 {
     if ([[o_video_view subviews] count] > 0)
-        [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
+        [o_fullscreen_window makeFirstResponder: [o_video_view subviews][0]];
 
     [o_fullscreen_window makeKeyWindow];
     [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
         }
 
         [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
-        [NSApp setPresentationOptions: NSApplicationPresentationDefault];
+        [[o_fullscreen_window screen] setNonFullscreenPresentationOptions];
 
         /* Will release the lock */
         [self hasEndedFullscreen];
     [[o_video_view window] orderFront: self];
 
     [[[VLCMainWindow sharedInstance] fsPanel] setNonActive: nil];
-    [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
+    [[o_fullscreen_window screen] setNonFullscreenPresentationOptions];
 
     if (o_fullscreen_anim1) {
         [o_fullscreen_anim1 stopAnimation];
     [dict2 setObject:self forKey:NSViewAnimationTargetKey];
     [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
 
-    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
+    o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict2]];
     [dict2 release];
 
     [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
     [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
     [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
 
-    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
+    o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:@[dict1]];
     [dict1 release];
 
     [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
     [o_video_view release];
     [o_video_view setFrame:[o_temp_view frame]];
     if ([[o_video_view subviews] count] > 0)
-        [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
+        [self makeFirstResponder: [o_video_view subviews][0]];
 
     [super makeKeyAndOrderFront:self]; /* our version (in main window) contains a workaround */
 
     /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
     viewAnimations = [o_fullscreen_anim2 viewAnimations];
     if ([viewAnimations count] >=1 &&
-        [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
+        [[viewAnimations[0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
         /* Fullscreen ended */
         [self hasEndedFullscreen];
     } else
     static NSMutableArray *attributes = nil;
     if (attributes == nil) {
         attributes = [[super accessibilityAttributeNames] mutableCopy];
-        NSArray *appendAttributes = [NSArray arrayWithObjects: NSAccessibilitySubroleAttribute,
-                                     NSAccessibilityCloseButtonAttribute,
-                                     NSAccessibilityMinimizeButtonAttribute,
-                                     NSAccessibilityZoomButtonAttribute,
-                                     nil];
+        NSArray *appendAttributes = @[NSAccessibilitySubroleAttribute,
+                                      NSAccessibilityCloseButtonAttribute,
+                                      NSAccessibilityMinimizeButtonAttribute,
+                                      NSAccessibilityZoomButtonAttribute];
 
         for(NSString *attribute in appendAttributes) {
             if (![attributes containsObject:attribute])