]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainWindow.m
macosx: adapt module_list_get calls for latest changes in core
[vlc] / modules / gui / macosx / MainWindow.m
index 9d985958b31767d577b78d077674a4c5b17f078b..98fc6ff2175eeadee0f043293ab2675476171f75 100644 (file)
@@ -43,6 +43,7 @@
 #import <vlc_aout_intf.h>
 
 #import "ControlsBar.h"
+#import "VideoView.h"
 
 
 @interface VLCMainWindow ()
@@ -142,6 +143,11 @@ static VLCMainWindow *_o_sharedInstance = nil;
         o_extra_video_window = nil;
     }
 
+    if (o_detached_video_window) {
+        [o_detached_video_window release];
+        o_detached_video_window = nil;
+    }
+
     [super dealloc];
 }
 
@@ -156,7 +162,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
         b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
 #endif
     t_hide_mouse_timer = nil;
-    [o_detached_video_window setDelegate: self];
     [self useOptimizedDrawing: YES];
     
     [[o_search_fld cell] setPlaceholderString: _NS("Search")];
@@ -190,10 +195,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     // Set that here as IB seems to be buggy
     if (b_dark_interface) {
         [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
-        [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
     } else {
         [self setContentMinSize:NSMakeSize(604., 288.)];
-        [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height)];
     }
 
     [self setTitle: _NS("VLC media player")];
@@ -511,10 +514,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark overwritten default functionality
-- (BOOL)canBecomeKeyWindow
-{
-    return YES;
-}
 
 - (void)windowResizedOrMoved:(NSNotification *)notification
 {
@@ -632,7 +631,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 {
     [o_controls_bar updateTimeSlider];
     [[self controlsBar] updatePosAndTimeInFSPanel:o_fspanel];
-    [[o_detached_video_window controlsBar] updateTimeSlider];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] updateTimeSlider];
 }
 
 - (void)updateName
@@ -652,10 +652,12 @@ static VLCMainWindow *_o_sharedInstance = nil;
         NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
         if ([o_url isFileURL]) {
             [self setRepresentedURL: o_url];
-            [o_detached_video_window setRepresentedURL: o_url];
+            if (o_detached_video_window)
+                [o_detached_video_window setRepresentedURL: o_url];
         } else {
             [self setRepresentedURL: nil];
-            [o_detached_video_window setRepresentedURL: nil];
+            if (o_detached_video_window)
+                [o_detached_video_window setRepresentedURL: nil];
         }
         free(uri);
 
@@ -667,7 +669,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
         }
 
         [self setTitle: aString];
-        if (b_nonembedded && [[VLCMain sharedInstance] activeVideoPlayback])
+        if (b_nonembedded && o_detached_video_window && [[VLCMain sharedInstance] activeVideoPlayback])
             [o_detached_video_window setTitle: aString];
 
         [o_fspanel setStreamTitle: aString];
@@ -681,7 +683,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)updateWindow
 {
     [o_controls_bar updateControls];
-    [[o_detached_video_window controlsBar] updateControls];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] updateControls];
 
     bool b_seekable = false;
 
@@ -709,14 +712,16 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)setPause
 {
     [o_controls_bar setPause];
-    [[o_detached_video_window controlsBar] setPause];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] setPause];
     [o_fspanel setPause];
 }
 
 - (void)setPlay
 {
     [o_controls_bar setPlay];
-    [[o_detached_video_window controlsBar] setPlay];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] setPlay];
     [o_fspanel setPlay];
 }
 
@@ -728,15 +733,13 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark Video Output handling
-- (id)videoView
-{
-    return o_video_view;
-}
 
-- (void)setupVideoView
+- (VLCVoutView *)setupVout:(vout_window_t *)p_wnd
 {
     BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
     BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
+    VLCVoutView *o_vout_view;
+    VLCVideoWindowCommon *o_new_video_window;
 
     // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
     if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
@@ -770,70 +773,74 @@ static VLCMainWindow *_o_sharedInstance = nil;
         [o_extra_video_window setBackgroundColor: [NSColor blackColor]];
         [o_extra_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
         [o_extra_video_window setCanBecomeMainWindow: !b_video_wallpaper];
-        [o_extra_video_window setAcceptsMouseMovedEvents:!b_video_wallpaper];
+        [o_extra_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
         [o_extra_video_window setMovableByWindowBackground: !b_video_wallpaper];
         [o_extra_video_window useOptimizedDrawing: YES];
 
-        [o_video_view retain];
-        if ([o_video_view superview] != NULL)
-            [o_video_view removeFromSuperviewWithoutNeedingDisplay];
-        window_rect.origin.x = window_rect.origin.y = 0;
-        [o_video_view setFrame: window_rect];
-        [[o_extra_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
-        [o_video_view release];
+        o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_extra_video_window contentView] bounds]];
+        [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+        [[o_extra_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
+        [o_extra_video_window setVideoView:o_vout_view];
+
+        o_new_video_window = o_extra_video_window;
 
         if (b_video_wallpaper)
             [o_extra_video_window orderBack:nil];
         else {
             [o_extra_video_window center];
             [o_extra_video_window setFrameAutosaveName:@"extra-videowindow"];
-            [o_detached_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
+            [o_extra_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
         }
 
         b_nonembedded = YES;
     } else {
         if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
-            if ([o_video_view window] != self) {
-                [o_video_view removeFromSuperviewWithoutNeedingDisplay];
-                [o_video_view setFrame: [o_split_view frame]];
-                [[self contentView] addSubview:o_video_view positioned:NSWindowAbove relativeTo:nil];
-            }
+            o_vout_view = [o_video_view retain];
+            o_new_video_window = self;
             b_nonembedded = NO;
         } else {
-            if ([o_video_view superview] != NULL)
-                [o_video_view removeFromSuperviewWithoutNeedingDisplay];
-
-            NSRect videoFrame;
-            videoFrame.size = [[o_detached_video_window contentView] frame].size;
-            videoFrame.size.height -= [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height;
-            if (b_dark_interface)
-                videoFrame.size.height -= [o_titlebar_view frame].size.height;
+            if (!o_detached_video_window) {
+                NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
+                [o_controller loadWindow];
+                o_detached_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
+                [o_controller release];
+
+                // event occurs before window is created, so call again
+                [[VLCMain sharedInstance] playbackStatusUpdated];
+            }
 
-            videoFrame.origin.x = .0;
-            videoFrame.origin.y = [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height;
+            [o_detached_video_window setDelegate: self];
+            if (b_dark_interface) {
+                [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
+            } else {
+                [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height)];
+            }
 
-            [o_video_view setFrame: videoFrame];
-            [[o_detached_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
             [o_detached_video_window setLevel:NSNormalWindowLevel];
             [o_detached_video_window useOptimizedDrawing: YES];
+
+            o_vout_view = [[o_detached_video_window videoView] retain];
+            o_new_video_window = o_detached_video_window;
             b_nonembedded = YES;
         }
     }
 
     if (!b_video_wallpaper) {
-        [[o_video_view window] makeKeyAndOrderFront: self];
+        [o_new_video_window makeKeyAndOrderFront: self];
 
         vout_thread_t *p_vout = getVout();
         if (p_vout) {
             if (var_GetBool(p_vout, "video-on-top"))
-                [[o_video_view window] setLevel: NSStatusWindowLevel];
+                [o_new_video_window setLevel: NSStatusWindowLevel];
             else
-                [[o_video_view window] setLevel: NSNormalWindowLevel];
+                [o_new_video_window setLevel: NSNormalWindowLevel];
             vlc_object_release(p_vout);
         }
     }
 
-    [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
+    [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
+
+    return [o_vout_view autorelease];
 }
 
 - (void)setVideoplayEnabled
@@ -850,13 +857,14 @@ static VLCMainWindow *_o_sharedInstance = nil;
             [[self animator] setFrame:frameBeforePlayback display:YES];
 
         [self makeFirstResponder: nil];
-        [o_detached_video_window orderOut: nil];
+        if (o_detached_video_window)
+            [o_detached_video_window orderOut: nil];
         if (o_extra_video_window)
             [o_extra_video_window orderOut: nil];
 
         if ([self level] != NSNormalWindowLevel)
             [self setLevel: NSNormalWindowLevel];
-        if ([o_detached_video_window level] != NSNormalWindowLevel)
+        if (o_detached_video_window && [o_detached_video_window level] != NSNormalWindowLevel)
             [o_detached_video_window setLevel: NSNormalWindowLevel];
 
         // restore alpha value to 1 for the case that macosx-opaqueness is set to < 1
@@ -1011,7 +1019,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     screen_rect = [screen frame];
 
     [o_controls_bar setFullscreenState:YES];
-    [[o_detached_video_window controlsBar] setFullscreenState:YES];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] setFullscreenState:YES];
 
     [self recreateHideMouseTimer];
 
@@ -1168,7 +1177,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [self lockFullscreenAnimation];
 
     [o_controls_bar setFullscreenState:NO];
-    [[o_detached_video_window controlsBar] setFullscreenState:NO];
+    if (o_detached_video_window)
+        [[o_detached_video_window controlsBar] setFullscreenState:NO];
 
     /* We always try to do so */
     [NSScreen unblackoutScreens];
@@ -1850,8 +1860,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
 {
     [self setAcceptsMouseMovedEvents: YES];
 
+    [self setBackgroundColor: [NSColor blackColor]];
     if (b_dark_interface) {
-        [self setBackgroundColor: [NSColor clearColor]];
         [self setOpaque: NO];
         [self display];
         [self setHasShadow:NO];
@@ -1866,18 +1876,15 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
         // native fs not supported with detached view yet
         [o_titlebar_view setFullscreenButtonHidden: YES];
-
     }
-}
 
-- (IBAction)fullscreen:(id)sender
-{
-    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
-}
-
-- (BOOL)canBecomeKeyWindow
-{
-    return YES;
+    NSRect videoViewRect = [[self contentView] bounds];
+    if (b_dark_interface)
+        videoViewRect.size.height -= [o_titlebar_view frame].size.height;
+    CGFloat f_bottomBarHeight = [[[self controlsBar] bottomBarView] frame].size.height;
+    videoViewRect.size.height -= f_bottomBarHeight;
+    videoViewRect.origin.y = f_bottomBarHeight;
+    [o_video_view setFrame: videoViewRect];
 }
 
 @end