#import "misc.h"
#import "intf.h" /* VLCApplication */
#import "MainWindow.h"
+#import "ControlsBar.h"
#import "controls.h"
#import "CoreInteraction.h"
#import <CoreAudio/CoreAudio.h>
+#import <vlc_keys.h>
+
/*****************************************************************************
* NSSound (VLCAdditions)
i_size = sizeof( i_device );
AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device );
- if (err != noErr)
- {
+ if (err != noErr) {
msg_Warn( VLCIntf, "couldn't get main audio output device" );
return .0;
}
AudioObjectPropertyAddress propertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, channel };
i_size = sizeof( f_volume );
err = AudioObjectGetPropertyData(i_device, &propertyAddress, 0, NULL, &i_size, &f_volume);
- if (err != noErr)
- {
+ if (err != noErr) {
msg_Warn( VLCIntf, "couldn't get volume value" );
return .0;
}
i_size = sizeof( i_device );
AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device );
- if (err != noErr)
- {
+ if (err != noErr) {
msg_Warn( VLCIntf, "couldn't get main audio output device" );
return NO;
}
{
NSUInteger count = [[NSScreen screens] count];
- for( NSUInteger i = 0; i < count; i++ )
- {
+ for ( NSUInteger i = 0; i < count; i++ ) {
NSScreen *screen = [[NSScreen screens] objectAtIndex: i];
- if([screen displayID] == displayID)
+ if ([screen displayID] == displayID)
return screen;
}
return nil;
}
-- (BOOL)isMainScreen
+- (BOOL)hasMenuBar
{
return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]);
}
+- (BOOL)hasDock
+{
+ NSRect screen_frame = [self frame];
+ NSRect screen_visible_frame = [self visibleFrame];
+ CGFloat f_menu_bar_thickness = [self hasMenuBar] ? [[NSStatusBar systemStatusBar] thickness] : 0.0;
+
+ BOOL b_found_dock = NO;
+ if (screen_visible_frame.size.width < screen_frame.size.width)
+ b_found_dock = YES;
+ else if (screen_visible_frame.size.height + f_menu_bar_thickness < screen_frame.size.height)
+ b_found_dock = YES;
+
+ return b_found_dock;
+}
+
- (BOOL)isScreen: (NSScreen*)screen
{
return ([self displayID] == [screen displayID]);
[blackoutWindows removeAllObjects];
NSUInteger screenCount = [[NSScreen screens] count];
- for(NSUInteger i = 0; i < screenCount; i++)
- {
+ for (NSUInteger i = 0; i < screenCount; i++) {
NSScreen *screen = [[NSScreen screens] objectAtIndex: i];
VLCWindow *blackoutWindow;
NSRect screen_rect;
- if([self isScreen: screen])
+ if ([self isScreen: screen])
continue;
screen_rect = [screen frame];
[blackoutWindows addObject: blackoutWindow];
[blackoutWindow release];
- if( [screen isMainScreen] )
- {
- if (OSX_LEOPARD)
- SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
- else
- [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
- }
+ NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
+ if ([screen hasMenuBar])
+ presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
+ if ([screen hasMenuBar] || [screen hasDock])
+ presentationOpts |= NSApplicationPresentationAutoHideDock;
+ [NSApp setPresentationOptions:presentationOpts];
}
}
{
NSUInteger blackoutWindowCount = [blackoutWindows count];
- for(NSUInteger i = 0; i < blackoutWindowCount; i++)
- {
+ for (NSUInteger i = 0; i < blackoutWindowCount; i++) {
VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex: i];
[blackoutWindow closeAndAnimate: YES];
}
- if (OSX_LEOPARD)
- SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
- else
- [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
-}
-
-@end
-
-/*****************************************************************************
- * VLCWindow
- *
- * Missing extension to NSWindow
- *****************************************************************************/
-
-@implementation VLCWindow
-- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
- backing:(NSBackingStoreType)backingType defer:(BOOL)flag
-{
- self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag];
- if( self )
- {
- b_isFullscreen = NO;
- b_isset_canBecomeKeyWindow = NO;
- /* we don't want this window to be restored on relaunch */
- if (OSX_LION)
- [self setRestorable:NO];
- }
- return self;
-}
-
-- (void)setCanBecomeKeyWindow: (BOOL)canBecomeKey
-{
- b_isset_canBecomeKeyWindow = YES;
- b_canBecomeKeyWindow = canBecomeKey;
-}
-
-- (BOOL)canBecomeKeyWindow
-{
- if(b_isset_canBecomeKeyWindow)
- return b_canBecomeKeyWindow;
-
- return [super canBecomeKeyWindow];
-}
-
-- (void)setCanBecomeMainWindow: (BOOL)canBecomeMain
-{
- b_isset_canBecomeMainWindow = YES;
- b_canBecomeMainWindow = canBecomeMain;
-}
-
-- (BOOL)canBecomeMainWindow
-{
- if(b_isset_canBecomeMainWindow)
- return b_canBecomeMainWindow;
-
- return [super canBecomeMainWindow];
-}
-
-- (void)closeAndAnimate: (BOOL)animate
-{
- NSInvocation *invoc;
-
- if (!animate)
- {
- [super close];
- return;
- }
-
- invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(close)]];
- [invoc setTarget: self];
-
- if (![self isVisible] || [self alphaValue] == 0.0)
- {
- [super close];
- return;
- }
-
- [self orderOut: self animate: YES callback: invoc];
-}
-
-- (void)orderOut: (id)sender animate: (BOOL)animate
-{
- NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(orderOut:)]];
- [invoc setTarget: self];
- [invoc setArgument: sender atIndex: 0];
- [self orderOut: sender animate: animate callback: invoc];
-}
-
-- (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback
-{
- NSViewAnimation *anim;
- NSViewAnimation *current_anim;
- NSMutableDictionary *dict;
-
- if (!animate)
- {
- [self orderOut: sender];
- return;
- }
-
- dict = [[NSMutableDictionary alloc] initWithCapacity:2];
-
- [dict setObject:self forKey:NSViewAnimationTargetKey];
-
- [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
- anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
- [dict release];
-
- [anim setAnimationBlockingMode:NSAnimationNonblocking];
- [anim setDuration:0.9];
- [anim setFrameRate:30];
- [anim setUserInfo: callback];
-
- @synchronized(self) {
- current_anim = self->animation;
-
- if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating])
- {
- [anim release];
- }
- else
- {
- if (current_anim)
- {
- [current_anim stopAnimation];
- [anim setCurrentProgress:1.0-[current_anim currentProgress]];
- [current_anim release];
- }
- else
- [anim setCurrentProgress:1.0 - [self alphaValue]];
- self->animation = anim;
- [self setDelegate: self];
- [anim startAnimation];
- }
- }
-}
-
-- (void)orderFront: (id)sender animate: (BOOL)animate
-{
- NSViewAnimation *anim;
- NSViewAnimation *current_anim;
- NSMutableDictionary *dict;
-
- if (!animate)
- {
- [super orderFront: sender];
- [self setAlphaValue: 1.0];
- return;
- }
-
- if (![self isVisible])
- {
- [self setAlphaValue: 0.0];
- [super orderFront: sender];
- }
- else if ([self alphaValue] == 1.0)
- {
- [super orderFront: self];
- return;
- }
-
- dict = [[NSMutableDictionary alloc] initWithCapacity:2];
-
- [dict setObject:self forKey:NSViewAnimationTargetKey];
-
- [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
- anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]];
- [dict release];
-
- [anim setAnimationBlockingMode:NSAnimationNonblocking];
- [anim setDuration:0.5];
- [anim setFrameRate:30];
-
- @synchronized(self) {
- current_anim = self->animation;
-
- if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating])
- {
- [anim release];
- }
- else
- {
- if (current_anim)
- {
- [current_anim stopAnimation];
- [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
- [current_anim release];
- }
- else
- [anim setCurrentProgress:[self alphaValue]];
- self->animation = anim;
- [self setDelegate: self];
- [self orderFront: sender];
- [anim startAnimation];
- }
- }
-}
-
-- (void)animationDidEnd:(NSAnimation*)anim
-{
- if ([self alphaValue] <= 0.0)
- {
- NSInvocation * invoc;
- [super orderOut: nil];
- [self setAlphaValue: 1.0];
- if ((invoc = [anim userInfo]))
- [invoc invoke];
- }
-}
-
-- (void)setFullscreen:(BOOL)b_var
-{
- b_isFullscreen = b_var;
-}
-
-- (BOOL)isFullscreen
-{
- return b_isFullscreen;
-}
-
-- (IBAction)fullscreen:(id)sender
-{
- [[VLCCoreInteraction sharedInstance] toggleFullscreen];
+ [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
}
@end
@end
+/*****************************************************************************
+ * ProgressView
+ *****************************************************************************/
+
+@implementation VLCProgressView : NSView
+
+- (void)scrollWheel:(NSEvent *)o_event
+{
+ intf_thread_t * p_intf = VLCIntf;
+ CGFloat f_deltaY = [o_event deltaY];
+ CGFloat f_deltaX = [o_event deltaX];
+
+ if (!OSX_SNOW_LEOPARD && [o_event isDirectionInvertedFromDevice])
+ f_deltaX = -f_deltaX; // optimisation, actually double invertion of f_deltaY here
+ else
+ f_deltaY = -f_deltaY;
+
+ // positive for left / down, negative otherwise
+ CGFloat f_delta = f_deltaX + f_deltaY;
+ CGFloat f_abs;
+ int i_vlckey;
+
+ if (f_delta > 0.0f) {
+ i_vlckey = ACTIONID_JUMP_BACKWARD_EXTRASHORT;
+ f_abs = f_delta;
+ }
+ else {
+ i_vlckey = ACTIONID_JUMP_FORWARD_EXTRASHORT;
+ f_abs = -f_delta;
+ }
+
+ for (NSUInteger i = 0; i < (int)(f_abs/4.+1.) && f_abs > 0.05 ; i++)
+ var_SetInteger( p_intf->p_libvlc, "key-action", i_vlckey );
+}
+
+- (BOOL)acceptsFirstResponder
+{
+ return YES;
+}
+
+@end
+
/*****************************************************************************
* TimeLineSlider
*****************************************************************************/
- (void)drawRect:(NSRect)rect
{
- [[[VLCMain sharedInstance] mainWindow] drawFancyGradientEffectForTimeSlider];
+ [[[[VLCMain sharedInstance] mainWindow] controlsBar] drawFancyGradientEffectForTimeSlider];
msleep( 10000 ); //wait for the gradient to draw completely
/* Draw default to make sure the slider behaves correctly */
@end
+/*****************************************************************************
+ * VLCVolumeSliderCommon
+ *****************************************************************************/
+
+@implementation VLCVolumeSliderCommon : NSSlider
+
+- (void)scrollWheel:(NSEvent *)o_event
+{
+ intf_thread_t * p_intf = VLCIntf;
+ CGFloat f_deltaY = [o_event deltaY];
+ CGFloat f_deltaX = [o_event deltaX];
+
+ if (!OSX_SNOW_LEOPARD && [o_event isDirectionInvertedFromDevice])
+ f_deltaX = -f_deltaX; // optimisation, actually double invertion of f_deltaY here
+ else
+ f_deltaY = -f_deltaY;
+
+ // positive for left / down, negative otherwise
+ CGFloat f_delta = f_deltaX + f_deltaY;
+ CGFloat f_abs;
+ int i_vlckey;
+
+ if (f_delta > 0.0f) {
+ i_vlckey = ACTIONID_VOL_DOWN;
+ f_abs = f_delta;
+ }
+ else {
+ i_vlckey = ACTIONID_VOL_UP;
+ f_abs = -f_delta;
+ }
+
+ for (NSUInteger i = 0; i < (int)(f_abs/4.+1.) && f_abs > 0.05 ; i++)
+ var_SetInteger(p_intf->p_libvlc, "key-action", i_vlckey);
+}
+
+@end
+
/*****************************************************************************
* ITSlider
*****************************************************************************/
- (void)setStringValue:(NSString *)string
{
- if (!o_string_shadow)
- {
+ if (!o_string_shadow) {
o_string_shadow = [[NSShadow alloc] init];
[o_string_shadow setShadowColor: [NSColor colorWithCalibratedWhite:1.0 alpha:0.5]];
- [o_string_shadow setShadowOffset:NSMakeSize(0.0, -1.5)];
+ [o_string_shadow setShadowOffset:NSMakeSize(0.0, -1.0)];
[o_string_shadow setShadowBlurRadius:0.0];
}
- (void)mouseDown: (NSEvent *)ourEvent
{
- if( [ourEvent clickCount] > 1 )
+ if ( [ourEvent clickCount] > 1 )
[[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
else
{
* VLCThreePartImageView interface
*****************************************************************************/
@implementation VLCThreePartImageView
+
- (void)dealloc
{
[o_left_img release];