]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/extended.m
macosx: vlc_keys seems to need vlc_common.
[vlc] / modules / gui / macosx / extended.m
index c16044a9cbd6b16d84bfcdcf336c9e57dedcb6b7..34ebe19f21e1e529015d615e182237674f2d338a 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2005-2008 the VideoLAN team
  * $Id$
  *
- * Authors: Felix Paul Kühne <fkuehne@videolan.org>
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
 #import <vlc_aout.h>
 #import <vlc_vout.h>
 #import <vlc_interface.h>
+#import <vlc_playlist.h>
 
 /*****************************************************************************
  * VLCExtended implementation
@@ -65,11 +66,6 @@ static VLCExtended *_o_sharedInstance = nil;
     /* localise GUI-strings */
     /* method is called from intf.m (in method showExtended) */
     [o_extended_window setTitle: _NS("Extended controls")];
-    [o_lbl_video setStringValue: _NS("Video")];
-    [o_lbl_audio setStringValue: _NS("Audio")];
-    [o_lbl_audioFlts setStringValue: _NS("Audio filters")];
-    [o_lbl_videoFlts setStringValue: _NS("Video filters")];
-    [o_lbl_adjustImage setStringValue: _NS("Image adjustment")];
     [o_btn_vidFlts_mrInfo setToolTip: _NS("Shows more information about the available video filters.")];
     [o_ckb_wave setTitle: _NS("Wave")];
     [o_ckb_ripple setTitle: _NS("Ripple")];
@@ -113,15 +109,16 @@ static VLCExtended *_o_sharedInstance = nil;
     /* set the adjust-filter-sliders to the values from the prefs and enable
      * them, if wanted */
     char * psz_vfilters;
-    intf_thread_t * p_intf = VLCIntf;
+    intf_thread_t *p_intf = VLCIntf;
     psz_vfilters = config_GetPsz( p_intf, "vout-filter" );
     /* set the video-filter-checkboxes to the correct values */
     if( psz_vfilters )
     {
-        [o_ckb_blur setState: (int)strstr( psz_vfilters, "motionblur")];
-        [o_ckb_imgClone setState: (int)strstr( psz_vfilters, "clone")];
-        [o_ckb_imgCrop setState: (int)strstr( psz_vfilters, "crop")];
-        [o_ckb_trnsform setState: (int)strstr( psz_vfilters, "transform")];
+        [o_ckb_blur setState: (NSInteger)strstr( psz_vfilters, "motionblur")];
+        [o_ckb_imgClone setState: (NSInteger)strstr( psz_vfilters, "clone")];
+        [o_ckb_imgCrop setState: (NSInteger)strstr( psz_vfilters, "crop")];
+        [o_ckb_trnsform setState: (NSInteger)strstr( psz_vfilters, "transform")];
+        [o_ckb_intZoom setState: (NSInteger)strstr( psz_vfilters, "magnify")];
 
         free( psz_vfilters );
     }
@@ -151,11 +148,11 @@ static VLCExtended *_o_sharedInstance = nil;
     }
     if( psz_vifilters )
     {
-        [o_ckb_wave setState: (int)strstr( psz_vifilters, "wave")];
-        [o_ckb_psycho setState: (int)strstr( psz_vifilters, "psychedelic")];
-        [o_ckb_ripple setState: (int)strstr( psz_vifilters, "ripple")];
-        [o_ckb_gradient setState: (int)strstr( psz_vifilters, "gradient")];
-        [o_ckb_imgInvers setState: (int)strstr( psz_vifilters, "invert")];
+        [o_ckb_wave setState: (NSInteger)strstr( psz_vifilters, "wave")];
+        [o_ckb_psycho setState: (NSInteger)strstr( psz_vifilters, "psychedelic")];
+        [o_ckb_ripple setState: (NSInteger)strstr( psz_vifilters, "ripple")];
+        [o_ckb_gradient setState: (NSInteger)strstr( psz_vifilters, "gradient")];
+        [o_ckb_imgInvers setState: (NSInteger)strstr( psz_vifilters, "invert")];
 
         free( psz_vifilters );
     }
@@ -165,27 +162,26 @@ static VLCExtended *_o_sharedInstance = nil;
     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
     if( psz_afilters )
     {
-        [o_ckb_hdphnVirt setState: (int)strstr( psz_afilters, "headphone" ) ];
-        [o_ckb_vlme_norm setState: (int)strstr( psz_afilters, "normvol" ) ];
+        [o_ckb_hdphnVirt setState: (NSInteger)strstr( psz_afilters, "headphone" ) ];
+        [o_ckb_vlme_norm setState: (NSInteger)strstr( psz_afilters, "normvol" ) ];
  
         free( psz_afilters );
     }
-}
 
-- (void)collapsAll
-{
-    /* collaps all views so Cocoa saves the window position correctly */
-    if( o_adjImg_expanded )
-        [self expandAdjustImage: nil];
+    /* fill the popup button according to our available views */
+    [o_selector_pop removeAllItems];
+    [o_selector_pop addItemWithTitle: _NS("Adjust Image")];
+    [o_selector_pop addItemWithTitle: _NS("Video Filter")];
+    [o_selector_pop addItemWithTitle: _NS("Audio Filter")];
+    [o_selector_pop selectItemAtIndex: 0];
 
-    if( o_audFlts_expanded )
-        [self expandAudioFilters: nil];
+    /* make sure we draw a view on launch */
+    [self viewSelectorAction: self];
 
-    if( o_vidFlts_expanded )
-        [self expandVideoFilters: nil];
+    [self initStrings];
 }
 
-- (BOOL)getConfigChanged
+- (BOOL)configChanged
 {
     return o_config_changed;
 }
@@ -232,6 +228,53 @@ static VLCExtended *_o_sharedInstance = nil;
     [o_extended_window makeKeyAndOrderFront:nil];
 }
 
+- (IBAction)viewSelectorAction:(id)sender
+{
+    NSView *o_toBeShown_view;
+    /* check which view to show */
+    if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Adjust Image")] )
+        o_toBeShown_view = o_adjustImg_view;
+    else if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Audio Filter")] )
+        o_toBeShown_view = o_audioFlts_view;
+    else if( [[[o_selector_pop selectedItem] title] isEqualToString: _NS("Video Filter")] )
+        o_toBeShown_view = o_videoFilters_view;
+    else
+        msg_Err( VLCIntf, "invalid ui view requested" );
+    
+    NSRect o_win_rect, o_view_rect, o_old_view_rect;
+    o_win_rect = [o_extended_window frame];
+    o_view_rect = [o_toBeShown_view frame];
+    
+    if( o_currentlyshown_view != nil )
+    {
+        /* restore our window's height, if we've shown another category previously */
+        o_old_view_rect = [o_currentlyshown_view frame];
+        o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
+        o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
+        
+        /* remove our previous category view */
+        [o_currentlyshown_view removeFromSuperviewWithoutNeedingDisplay];
+    }
+    
+    o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
+    
+    //[o_extended_window displayIfNeeded];
+    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
+    
+    [o_toBeShown_view setFrame: NSMakeRect( 0, 
+                                              0, //[o_top_controls_box frame].size.height, 
+                                              o_view_rect.size.width, 
+                                              o_view_rect.size.height )];
+    [o_toBeShown_view setNeedsDisplay: YES];
+    [o_toBeShown_view setAutoresizesSubviews: YES];
+    [[o_extended_window contentView] addSubview: o_toBeShown_view];
+
+    /* keep our current category for further reference */
+    [o_currentlyshown_view release];
+    o_currentlyshown_view = o_toBeShown_view;
+    [o_currentlyshown_view retain];
+}
+
 - (IBAction)enableAdjustImage:(id)sender
 {
     /* en-/disable the sliders */
@@ -280,7 +323,7 @@ static VLCExtended *_o_sharedInstance = nil;
 {
     /* read-out the sliders' values and apply them */
     intf_thread_t * p_intf = VLCIntf;
-    vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE);
+    vout_thread_t *p_vout = getVout();
     vlc_object_t *p_filter;
 
     if( p_vout == NULL )
@@ -314,7 +357,7 @@ static VLCExtended *_o_sharedInstance = nil;
     else
     {
         msg_Dbg( p_intf, "we found a vout to adjust, let's look for the filter" );
-        p_filter = (vlc_object_t *)vlc_object_find_name( p_intf, "adjust", FIND_ANYWHERE );
+        p_filter = vlc_object_find_name( p_intf, "adjust", FIND_ANYWHERE );
 
         if(! p_filter )
         {
@@ -366,21 +409,21 @@ static VLCExtended *_o_sharedInstance = nil;
     id o_window = [NSApp keyWindow];
     NSArray *o_windows = [NSApp orderedWindows];
     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
-    playlist_t * p_playlist = pl_Yield( VLCIntf );
-    vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Hold( VLCIntf );
+    vout_thread_t *p_vout = getVout();
     vout_thread_t *p_real_vout;
 
     val.f_float = [o_sld_opaque floatValue] / 100;
 
     if( p_vout != NULL )
     {
-        p_real_vout = [VLCVoutView getRealVout: p_vout];
+        p_real_vout = [VLCVoutView realVout: p_vout];
         var_Set( p_real_vout, "macosx-opaqueness", val );
 
         while ((o_window = [o_enumerator nextObject]))
         {
             if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
-                [[[VLCMain sharedInstance] getEmbeddedList]
+                [[[VLCMain sharedInstance] embeddedList]
                                     windowContainsEmbedded: o_window])
             {
                 [o_window setAlphaValue: val.f_float];
@@ -393,7 +436,7 @@ static VLCExtended *_o_sharedInstance = nil;
     /* store to prefs */
     config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
 
-    vlc_object_release( p_playlist );
+    pl_Release( VLCIntf );
 
     o_config_changed = YES;
 }
@@ -411,7 +454,7 @@ static VLCExtended *_o_sharedInstance = nil;
 {
     /* read-out the slider's value and apply it */
     intf_thread_t * p_intf = VLCIntf;
-    aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE);
+    aout_instance_t * p_aout= getAout();
 
     if( p_aout != NULL )
     {
@@ -433,155 +476,11 @@ static VLCExtended *_o_sharedInstance = nil;
         [self changeAFiltersString: "normvol" onOrOff: NO ];
 }
 
-- (IBAction)expandAdjustImage:(id)sender
-{
-    /* expand or collapse adjImg */
-    NSRect o_win_rect = [o_extended_window frame];
-    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
-    NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
-    NSRect o_box_adjImg_rect = [o_box_adjImg frame];
-    if( o_adjImg_expanded )
-    {
-        /* move the window contents upwards (partially done through settings
-         * inside the nib) and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height - 193;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y + 193;
-        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 193;
-        o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y + 193;
-        /* remove the inserted view */
-        [o_adjustImg_view removeFromSuperviewWithoutNeedingDisplay];
-    }
-    else
-    {
-        /* move the window contents downwards and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height + 193;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y - 193;
-        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 193;
-        o_box_vidFlts_rect.origin.y = o_box_vidFlts_rect.origin.y - 193;
-    }
-    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
-    [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
-    [o_extended_window displayIfNeeded];
-    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
-    if( o_adjImg_expanded )
-    {
-        o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height - 193;
-        o_adjImg_expanded = NO;
-    } 
-    else
-    {
-        /* insert view */
-        o_box_adjImg_rect.size.height = [o_box_adjImg frame].size.height + 193;
-        [o_adjustImg_view setFrame: NSMakeRect( 20, -10, 370, 203)];
-        [o_adjustImg_view setNeedsDisplay:YES];
-        [o_adjustImg_view setAutoresizesSubviews: YES];
-        [[o_box_adjImg contentView] addSubview: o_adjustImg_view];
-        o_adjImg_expanded = YES;
-    }
-    [o_box_adjImg setFrameFromContentFrame: o_box_adjImg_rect];
-}
-
-- (IBAction)expandAudioFilters:(id)sender
-{
-    /* expand or collapse audFlts */
-    NSRect o_win_rect = [o_extended_window frame];
-    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
-    if( o_audFlts_expanded )
-    {
-        /* move the window contents upwards (partially done through settings
-         * inside the nib) and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height - 66;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y + 66;
-        /* remove the inserted view */
-        [o_audioFlts_view removeFromSuperviewWithoutNeedingDisplay];
-    }
-    else
-    {
-        /* move the window contents downwards and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height + 66;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y - 66;
-    }
-    [o_extended_window displayIfNeeded];
-    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
-    if( o_audFlts_expanded )
-    {
-        o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height - 66;
-        o_audFlts_expanded = NO;
-    } 
-    else
-    {
-        /* insert view */
-        o_box_audFlts_rect.size.height = [o_box_audFlts frame].size.height + 66;
-        [o_audioFlts_view setFrame: NSMakeRect( 20, -20, 370, 76)];
-        [o_audioFlts_view setNeedsDisplay:YES];
-        [o_audioFlts_view setAutoresizesSubviews: YES];
-        [[o_box_audFlts contentView] addSubview: o_audioFlts_view];
-        o_audFlts_expanded = YES;
-    }
-    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
-}
-
-- (IBAction)expandVideoFilters:(id)sender
-{
-    /* expand or collapse vidFlts */
-    NSRect o_win_rect = [o_extended_window frame];
-    NSRect o_box_audFlts_rect = [o_box_audFlts frame];
-    NSRect o_box_vidFlts_rect = [o_box_vidFlts frame];
-    if( o_vidFlts_expanded )
-    {
-        /* move the window contents upwards (partially done through settings
-         * inside the nib) and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height - 172;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y + 172;
-        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y + 172;
-        /* remove the inserted view */
-        [o_videoFilters_view removeFromSuperviewWithoutNeedingDisplay];
-    }
-    else
-    {
-        /* move the window contents downwards and resize the window */
-        o_win_rect.size.height = o_win_rect.size.height + 172;
-        o_win_rect.origin.y = [o_extended_window frame].origin.y - 172;
-        o_box_audFlts_rect.origin.y = o_box_audFlts_rect.origin.y - 172;
-    }
-    [o_box_audFlts setFrameFromContentFrame: o_box_audFlts_rect];
-    [o_extended_window displayIfNeeded];
-    [o_extended_window setFrame: o_win_rect display:YES animate: YES];
-    if( o_vidFlts_expanded )
-    {
-        o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height - 172;
-        o_vidFlts_expanded = NO;
-    } 
-    else
-    {
-        /* insert view */
-        o_box_vidFlts_rect.size.height = [o_box_vidFlts frame].size.height + 172;
-        [o_videoFilters_view setFrame: NSMakeRect( 20, -10, 370, 172)];
-        [o_videoFilters_view setNeedsDisplay:YES];
-        [o_videoFilters_view setAutoresizesSubviews: YES];
-        [[o_box_vidFlts contentView] addSubview: o_videoFilters_view];
-        o_vidFlts_expanded = YES;
-    }
-    [o_box_vidFlts setFrameFromContentFrame: o_box_vidFlts_rect];
-}
-
 - (IBAction)videoFilterAction:(id)sender
 {
     /* en-/disable video filters */
     if (sender == o_ckb_blur)
-        [self changeVoutFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
+        [self changeVideoFiltersString: "motionblur" onOrOff: [o_ckb_blur state]];
 
     else if (sender == o_ckb_imgClone)
         [self changeVoutFiltersString: "clone" onOrOff: [o_ckb_imgClone state]];
@@ -694,8 +593,7 @@ static VLCExtended *_o_sharedInstance = nil;
     config_PutPsz( p_intf, "vout-filter", psz_string );
 
     /* Try to set on the fly */
-    p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
-                                              FIND_ANYWHERE );
+    p_vout = getVout();
     if( p_vout )
     {
         var_SetString( p_vout, "vout-filter", psz_string );
@@ -761,8 +659,7 @@ static VLCExtended *_o_sharedInstance = nil;
     config_PutPsz( p_intf, "video-filter", psz_string );
 
     /* Try to set on the fly */
-    p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
-                                              FIND_ANYWHERE );
+    p_vout = getVout();
     if( p_vout )
     {
         var_SetString( p_vout, "video-filter", psz_string );
@@ -781,8 +678,7 @@ static VLCExtended *_o_sharedInstance = nil;
 
     char *psz_parser, *psz_string;
     intf_thread_t * p_intf = VLCIntf;
-    aout_instance_t * p_aout= (aout_instance_t *)vlc_object_find(p_intf,
-                                 VLC_OBJECT_AOUT, FIND_ANYWHERE);
+    aout_instance_t * p_aout = getAout();
 
     if( p_aout )
     {
@@ -808,6 +704,7 @@ static VLCExtended *_o_sharedInstance = nil;
         }
         else
         {
+            if( p_aout ) vlc_object_release( p_aout );
             return;
         }
     }
@@ -827,6 +724,7 @@ static VLCExtended *_o_sharedInstance = nil;
          else
          {
              free( psz_string );
+             if( p_aout ) vlc_object_release( p_aout );
              return;
          }
     }
@@ -837,14 +735,7 @@ static VLCExtended *_o_sharedInstance = nil;
     }
     else
     {
-        var_SetString( p_aout, "audio-filter", psz_string );
-        int i = 0;
-        while( i < p_aout->i_nb_inputs )
-        {
-            p_aout->pp_inputs[i]->b_restart = true;
-            i = (i + 1);
-        }
-        vlc_object_release( p_aout );
+        aout_EnableFilter( p_aout, psz_string, false );
     }
     free( psz_string );
 
@@ -855,7 +746,7 @@ static VLCExtended *_o_sharedInstance = nil;
 {
     /* save the preferences to make sure that our module-changes will up on
      * next launch again */
-    playlist_t * p_playlist = pl_Yield( VLCIntf );
+    playlist_t * p_playlist = pl_Hold( VLCIntf );
     int returnedValue;
     NSArray * theModules;
     theModules = [[NSArray alloc] initWithObjects: @"main", 
@@ -884,7 +775,7 @@ static VLCExtended *_o_sharedInstance = nil;
             "extended control attribute '%s' (%i)",
             [[theModules objectAtIndex: x] UTF8String] , returnedValue);
             [theModules release];
-            vlc_object_release( p_playlist );
+            pl_Release( VLCIntf );
  
             return;
         }
@@ -895,6 +786,6 @@ static VLCExtended *_o_sharedInstance = nil;
     msg_Dbg( VLCIntf, "VLCExtended: saved certain preferences successfully" );
  
     [theModules release];
-    vlc_object_release( p_playlist );
+    pl_Release( VLCIntf );
 }
 @end