/*****************************************************************************
* controls.m: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2002-2011 the VideoLAN team
+ * Copyright (C) 2002-2012 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
#import "open.h"
#import "controls.h"
#import "playlist.h"
+#import "MainMenu.h"
#import "CoreInteraction.h"
#import <vlc_keys.h>
[o_specificTime_ok_btn setTitle: _NS("OK")];
[o_specificTime_sec_lbl setStringValue: _NS("sec.")];
[o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
+
+ i_lastScrollWheelDirection = 0;
}
if( p_vout != NULL )
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
- vlc_object_release( (vlc_object_t *)p_vout );
+ vlc_object_release( p_vout );
}
vlc_object_release( p_input );
}
- (IBAction)lockVideosAspectRatio:(id)sender
{
- [[VLCCoreInteraction sharedInstance] setAspectRatioLocked: [sender state]];
+ [[VLCCoreInteraction sharedInstance] setAspectRatioLocked: ![sender state]];
[sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
}
if( !p_input ) return;
input_item_t *p_item = input_GetItem( p_input );
- if( !p_item ) return;
+ if( !p_item )
+ {
+ vlc_object_release( p_input );
+ return;
+ }
char *path = input_item_GetURI( p_item );
if( !path ) path = strdup( "" );
[[[[openPanel URLs] objectAtIndex: i] path] UTF8String] );
}
}
+ vlc_object_release( p_input );
+}
+
+- (void)resetScrollWheelDirection
+{
+ /* release the scroll direction 0.8 secs after the last event */
+ if (([NSDate timeIntervalSinceReferenceDate] - t_lastScrollEvent) >= 0.80)
+ i_lastScrollWheelDirection = 0;
}
- (void)scrollWheel:(NSEvent *)theEvent
{
intf_thread_t * p_intf = VLCIntf;
BOOL b_invertedEventFromDevice = NO;
+ CGFloat f_deltaY, f_deltaX = .0;
+
if (OSX_LION)
{
if ([theEvent isDirectionInvertedFromDevice])
b_invertedEventFromDevice = YES;
}
- float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
- float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
- int i, i_yvlckey, i_xvlckey;
+ f_deltaY = [theEvent deltaY];
+ f_deltaX = [theEvent deltaX];
+
+ CGFloat f_yabsvalue = f_deltaY > 0.0f ? f_deltaY : -f_deltaY;
+ CGFloat f_xabsvalue = f_deltaX > 0.0f ? f_deltaX : -f_deltaX;
+
+ int i_yvlckey, i_xvlckey = 0;
if (b_invertedEventFromDevice)
{
- if ([theEvent deltaY] > 0.0f)
+ if (f_deltaY > 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
- if ([theEvent deltaX] > 0.0f)
+ if (f_deltaX > 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
}
else
{
- if ([theEvent deltaY] < 0.0f)
+ if (f_deltaY < 0.0f)
i_yvlckey = KEY_MOUSEWHEELDOWN;
else
i_yvlckey = KEY_MOUSEWHEELUP;
- if ([theEvent deltaX] < 0.0f)
+ if (f_deltaX < 0.0f)
i_xvlckey = KEY_MOUSEWHEELRIGHT;
else
i_xvlckey = KEY_MOUSEWHEELLEFT;
}
- /* Send multiple key event, depending on the intensity of the event */
- for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
- var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
-
- /* Prioritize Y event (sound volume) over X event */
- if (f_yabsvalue < 0.05)
+ /* in the following, we're forwarding either a x or a y event */
+ /* Multiple key events are send depending on the intensity of the event */
+ /* the opposite direction is being blocked for 0.8 secs */
+ if (f_yabsvalue > 0.05)
{
- for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
- var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
+ if (i_lastScrollWheelDirection < 0) // last was a X
+ return;
+
+ i_lastScrollWheelDirection = 1; // Y
+ for (NSUInteger i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
+ var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
+
+ t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
+ [self performSelector:@selector(resetScrollWheelDirection)
+ withObject: NULL
+ afterDelay:1.00];
+ return;
+ }
+ if (f_xabsvalue > 0.05)
+ {
+ if (i_lastScrollWheelDirection > 0) // last was a Y
+ return;
+
+ i_lastScrollWheelDirection = -1; // X
+ for (NSUInteger i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
+ var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
+
+ t_lastScrollEvent = [NSDate timeIntervalSinceReferenceDate];
+ [self performSelector:@selector(resetScrollWheelDirection)
+ withObject: NULL
+ afterDelay:1.00];
}
}
/* Escape */
if( key == (unichar) 0x1b )
{
- vout_thread_t *p_vout = getVout();
- if (p_vout)
+ if (var_GetBool( p_vout, "fullscreen" ))
{
- if (var_GetBool( p_vout, "fullscreen" ))
- {
- [[VLCCoreInteraction sharedInstance] toggleFullscreen];
- eventHandled = YES;
- }
+ [[VLCCoreInteraction sharedInstance] toggleFullscreen];
+ eventHandled = YES;
}
}
else if( key == ' ' )
[self play:self];
eventHandled = YES;
}
- vlc_object_release( (vlc_object_t *)p_vout );
+ vlc_object_release( p_vout );
}
vlc_object_release( p_input );
}
}
@end
+
+@implementation VLCControls (NSMenuValidation)
+
+- (BOOL)validateMenuItem:(NSMenuItem *)o_mi
+{
+ return [[VLCMainMenu sharedInstance] validateMenuItem:o_mi];
+}
+
+@end