]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
macosx: Set nib deplyment target to 10.4, and don't use toolbar from nib as this...
[vlc] / modules / gui / macosx / intf.m
index c6f631b97ba7924a7f2795f58b7502d5c0a6faf0..51292a47ab0607b9be20c0ea5c73894ec3b65d31 100644 (file)
@@ -392,6 +392,15 @@ static VLCMain *_o_sharedMainInstance = nil;
     [o_msgs_panel setExcludedFromWindowsMenu: YES];
     [o_msgs_panel setDelegate: self];
 
+    /* In code and not in Nib for 10.4 compat */
+    NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease];
+    [toolbar setDelegate:self];
+    [toolbar setShowsBaselineSeparator:NO];
+    [toolbar setAllowsUserCustomization:NO];
+    [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
+    [toolbar setAutosavesConfiguration:YES];
+    [o_window setToolbar:toolbar];
+
     i_key = config_GetInt( p_intf, "key-quit" );
     [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
     [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
@@ -455,7 +464,11 @@ static VLCMain *_o_sharedMainInstance = nil;
     [o_window setDelegate: self];
  
     b_restore_size = false;
-    if( [o_window frame].size.height <= 200 )
+
+    // Set that here as IB seems to be buggy
+    [o_window setContentMinSize:NSMakeSize(338., 30.)];
+
+    if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
     {
         b_small_window = YES;
         [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
@@ -466,14 +479,16 @@ static VLCMain *_o_sharedMainInstance = nil;
     else
     {
         b_small_window = NO;
-        [o_playlist_view setFrame: NSMakeRect( 0, 0, [o_window frame].size.width, [o_window frame].size.height - 95 )];
+        NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
+        [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
         [o_playlist_view setNeedsDisplay:YES];
         [o_playlist_view setAutoresizesSubviews: YES];
         [[o_window contentView] addSubview: o_playlist_view];
     }
+
     [self updateTogglePlaylistState];
 
-    o_size_with_playlist = [o_window frame].size;
+    o_size_with_playlist = [o_window contentRectForFrameRect:[o_window frame]].size;
 
     p_playlist = pl_Yield( p_intf );
 
@@ -615,7 +630,7 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
 
 - (void)initStrings
 {
-    [o_window setTitle: _NS("VLC")];
+    [o_window setTitle: _NS("VLC media player")];
     [self setScrollField:_NS("VLC media player") stopAfter:-1];
 
     /* button controls */
@@ -848,14 +863,14 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
         nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
 
     if([o_update shouldCheckForUpdate])
-        [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
+        [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:nil];
 #endif
 
     /* Handle sleep notification */
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
            name:NSWorkspaceWillSleepNotification object:nil];
 
-    [self performSelectorInBackground:@selector(lookForCrashLog) withObject:NULL];
+    [NSThread detachNewThreadSelector:@selector(lookForCrashLog) toTarget:self withObject:nil];
 }
 
 /* Listen to the remote in exclusive mode, only when VLC is the active
@@ -1215,6 +1230,7 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
     pl_Release( p_intf );
 
     vlc_object_lock( p_intf );
+
     while( vlc_object_alive( p_intf ) )
     {
         vlc_mutex_lock( &p_intf->change_lock );
@@ -1239,6 +1255,10 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
             vlc_object_release( p_input );
             p_input = NULL;
         }
+        else if( cachedInputState != input_GetState( p_input ) )
+        {
+            p_intf->p_sys->b_intf_update = true;
+        }
 
         /* Manage volume status */
         [self manageVolumeSlider];
@@ -1298,10 +1318,10 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
         if( ( b_input = ( p_input != NULL ) ) )
         {
             /* seekable streams */
-            int state = input_GetState( p_input );
-            if ( state == INIT_S ||
-                 state == OPENING_S ||
-                 state == BUFFERING_S )
+            cachedInputState = input_GetState( p_input );
+            if ( cachedInputState == INIT_S ||
+                 cachedInputState == OPENING_S ||
+                 cachedInputState == BUFFERING_S )
             {
                 b_buffering = YES;
             }
@@ -2178,8 +2198,8 @@ end:
 
 - (void)notifyCrashLogToUser:(NSString *)crashLogPath
 {
-    int ret = NSRunInformationalAlertPanel(_NS("VLC has previously crashed"),
-                _NS("VLC has previously crashed, do you want to send an email with the crash to VLC's team?"),
+    int ret = NSRunInformationalAlertPanel(_NS("VLC crashed previously"),
+                _NS("VLC crashed previously. Do you want to send an email with details on the crash to VLC's development team?"),
                 _NS("Send"), _NS("Don't Send"), nil, nil);
     if( ret == NSAlertDefaultReturn )
     {
@@ -2242,35 +2262,35 @@ end:
     }
 }
 
+#pragma mark Playlist toggling
+
 - (IBAction)togglePlaylist:(id)sender
 {
-    NSRect o_rect = [o_window frame];
+    NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
+    NSRect o_rect = [o_window contentRectForFrameRect:[o_window frame]];
     /*First, check if the playlist is visible*/
-    if( o_rect.size.height <= 200 )
+    if( contentRect.size.height <= 169. )
     {
-        o_restore_rect = o_rect;
+        o_restore_rect = contentRect;
         b_restore_size = true;
         b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
+
         /* make large */
-        if( o_size_with_playlist.height > 200 )
-        {
+        if( o_size_with_playlist.height > 169. )
             o_rect.size.height = o_size_with_playlist.height;
-        } else {
-            o_rect.size.height = 500;
-        }
+        else
+            o_rect.size.height = 500.;
  
-        if( o_size_with_playlist.width > [o_window minSize].width )
-        {
+        if( o_size_with_playlist.width >= [o_window contentMinSize].width )
             o_rect.size.width = o_size_with_playlist.width;
-        } else {
-            o_rect.size.width = 500;
-        }
-        o_rect.size.height = (o_size_with_playlist.height > 200) ?
-            o_size_with_playlist.height : 500;
-        o_rect.origin.x = [o_window frame].origin.x;
-        o_rect.origin.y = [o_window frame].origin.y - o_rect.size.height +
-                                                [o_window minSize].height;
+        else
+            o_rect.size.width = [o_window contentMinSize].width;
+
+        o_rect.origin.x = contentRect.origin.x;
+        o_rect.origin.y = contentRect.origin.y - o_rect.size.height +
+            [o_window contentMinSize].height;
+
+        o_rect = [o_window frameRectForContentRect:o_rect];
 
         NSRect screenRect = [[o_window screen] visibleFrame];
         if( !NSContainsRect( screenRect, o_rect ) ) {
@@ -2285,21 +2305,31 @@ end:
     else
     {
         NSSize curSize = o_rect.size;
-        /* make small */
-        o_rect.size.height = [o_window minSize].height;
-        o_rect.size.width = [o_window minSize].width;
-        o_rect.origin.x = [o_window frame].origin.x;
-        /* Calculate the position of the lower right corner after resize */
-        o_rect.origin.y = [o_window frame].origin.y +
-            [o_window frame].size.height - [o_window minSize].height;
-
         if( b_restore_size )
+        {
             o_rect = o_restore_rect;
+            if( o_rect.size.height < [o_window contentMinSize].height )
+                o_rect.size.height = [o_window contentMinSize].height;
+            if( o_rect.size.width < [o_window contentMinSize].width )
+                o_rect.size.width = [o_window contentMinSize].width;
+        }
+        else
+        {
+            NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
+            /* make small */
+            o_rect.size.height = [o_window contentMinSize].height;
+            o_rect.size.width = [o_window contentMinSize].width;
+            o_rect.origin.x = contentRect.origin.x;
+            /* Calculate the position of the lower right corner after resize */
+            o_rect.origin.y = contentRect.origin.y +
+                contentRect.size.height - [o_window contentMinSize].height;
+        }
 
         [o_playlist_view setAutoresizesSubviews: NO];
         [o_playlist_view removeFromSuperview];
         [o_btn_playlist setState: NO];
         b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
+        o_rect = [o_window frameRectForContentRect:o_rect];
     }
 
     [o_window setFrame: o_rect display:YES animate: YES];
@@ -2307,7 +2337,7 @@ end:
 
 - (void)updateTogglePlaylistState
 {
-    if( [o_window frame].size.height <= 200 )
+    if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
     {
         [o_btn_playlist setState: NO];
     }
@@ -2319,13 +2349,16 @@ end:
 
 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
 {
+
     /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
 
    /*Stores the size the controller one resize, to be able to restore it when
      toggling the playlist*/
     o_size_with_playlist = proposedFrameSize;
 
-    if( proposedFrameSize.height <= 200 )
+    NSRect rect;
+    rect.size = proposedFrameSize;
+    if( [o_window contentRectForFrameRect:rect].size.height <= 169. )
     {
         if( b_small_window == NO )
         {
@@ -2346,11 +2379,12 @@ end:
 
 - (void)windowDidResize:(NSNotification *)notif
 {
-    if( [o_window frame].size.height > 200 && b_small_window )
+    if( [o_window contentRectForFrameRect:[o_window frame]].size.height > 169. && b_small_window )
     {
         /* If large and coming from small then show */
         [o_playlist_view setAutoresizesSubviews: YES];
-        [o_playlist_view setFrame: NSMakeRect( 0, 0, [o_window frame].size.width, [o_window frame].size.height - [o_window minSize].height )];
+        NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
+        [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
         [o_playlist_view setNeedsDisplay:YES];
         [[o_window contentView] addSubview: o_playlist_view];
         b_small_window = NO;
@@ -2358,6 +2392,8 @@ end:
     [self updateTogglePlaylistState];
 }
 
+#pragma mark -
+
 @end
 
 @implementation VLCMain (NSMenuValidation)