Commit 3f87c4d3 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: re-implement drag & drop support for VLCVoutView (close #6604)

additionally, clean up misc.m and move code shared by VLCVoutView, VLBrushedMetalImageView and VLCThreePartDropView to VLCCoreInteraction
(cherry picked from commit c55ac4febf308e50ccc72ff96becf1aeb76faac5)
parent b7f6772e
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
- (int)volume; - (int)volume;
- (void)setVolume:(int)i_value; - (void)setVolume:(int)i_value;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (void)setAspectRatioLocked:(BOOL)b_value; - (void)setAspectRatioLocked:(BOOL)b_value;
- (BOOL)aspectRatioIsLocked; - (BOOL)aspectRatioIsLocked;
- (void)toggleFullscreen; - (void)toggleFullscreen;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#import "CoreInteraction.h" #import "CoreInteraction.h"
#import "intf.h" #import "intf.h"
#import "open.h" #import "open.h"
#import "playlist.h"
#import <vlc_playlist.h> #import <vlc_playlist.h>
#import <vlc_input.h> #import <vlc_input.h>
#import <vlc_keys.h> #import <vlc_keys.h>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#import <vlc_aout_intf.h> #import <vlc_aout_intf.h>
#import <vlc/vlc.h> #import <vlc/vlc.h>
#import <vlc_strings.h> #import <vlc_strings.h>
#import <vlc_url.h>
@implementation VLCCoreInteraction @implementation VLCCoreInteraction
static VLCCoreInteraction *_o_sharedInstance = nil; static VLCCoreInteraction *_o_sharedInstance = nil;
...@@ -549,6 +551,60 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -549,6 +551,60 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
aout_VolumeSet( pl_Get( p_intf ), i_value ); aout_VolumeSet( pl_Get( p_intf ), i_value );
} }
#pragma mark -
#pragma mark drag and drop support for VLCVoutView, VLBrushedMetalImageView and VLCThreePartDropView
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *o_paste = [sender draggingPasteboard];
NSArray *o_types = [NSArray arrayWithObject: NSFilenamesPboardType];
NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
NSData *o_carried_data = [o_paste dataForType:o_desired_type];
BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
if( o_carried_data )
{
if ([o_desired_type isEqualToString:NSFilenamesPboardType])
{
NSArray *o_array = [NSArray array];
NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
BOOL b_returned = NO;
if (count == 1 && p_input)
{
b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
vlc_object_release( p_input );
if(!b_returned)
return YES;
}
else if( p_input )
vlc_object_release( p_input );
for( NSUInteger i = 0; i < count; i++)
{
NSDictionary *o_dic;
char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
if( !psz_uri )
continue;
o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
free( psz_uri );
o_array = [o_array arrayByAddingObject: o_dic];
}
if( b_autoplay )
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
return YES;
}
}
return NO;
}
#pragma mark - #pragma mark -
#pragma mark video output stuff #pragma mark video output stuff
......
...@@ -74,6 +74,50 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -74,6 +74,50 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
* VLCVoutView implementation * VLCVoutView implementation
*****************************************************************************/ *****************************************************************************/
@implementation VLCVoutView @implementation VLCVoutView
#pragma mark -
#pragma mark drag & drop support
- (void)dealloc
{
[self unregisterDraggedTypes];
[super dealloc];
}
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
return NSDragOperationGeneric;
return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BOOL b_returned;
b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
[self setNeedsDisplay:YES];
return b_returned;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
#pragma mark -
#pragma mark vout actions
- (void)closeVout - (void)closeVout
{ {
vout_thread_t * p_vout = getVout(); vout_thread_t * p_vout = getVout();
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
*****************************************************************************/ *****************************************************************************/
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <ApplicationServices/ApplicationServices.h>
#import "CompatibilityFixes.h" #import "CompatibilityFixes.h"
/***************************************************************************** /*****************************************************************************
......
...@@ -22,17 +22,11 @@ ...@@ -22,17 +22,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#import <Cocoa/Cocoa.h> #import "misc.h"
#import <Carbon/Carbon.h>
#import "CompatibilityFixes.h"
#import "intf.h" /* VLCApplication */ #import "intf.h" /* VLCApplication */
#import "MainWindow.h" #import "MainWindow.h"
#import "misc.h"
#import "playlist.h"
#import "controls.h" #import "controls.h"
#import "CoreInteraction.h" #import "CoreInteraction.h"
#import <vlc_url.h>
/***************************************************************************** /*****************************************************************************
* NSAnimation (VLCAdditions) * NSAnimation (VLCAdditions)
...@@ -396,8 +390,7 @@ static NSMutableArray *blackoutWindows = NULL; ...@@ -396,8 +390,7 @@ static NSMutableArray *blackoutWindows = NULL;
- (void)awakeFromNib - (void)awakeFromNib
{ {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
NSFilenamesPboardType, nil]];
[self setImageScaling: NSScaleToFit]; [self setImageScaling: NSScaleToFit];
[self setImageFrameStyle: NSImageFrameNone]; [self setImageFrameStyle: NSImageFrameNone];
[self setImageAlignment: NSImageAlignCenter]; [self setImageAlignment: NSImageAlignCenter];
...@@ -405,15 +398,10 @@ static NSMutableArray *blackoutWindows = NULL; ...@@ -405,15 +398,10 @@ static NSMutableArray *blackoutWindows = NULL;
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{ {
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
== NSDragOperationGeneric)
{
return NSDragOperationGeneric; return NSDragOperationGeneric;
}
else
{
return NSDragOperationNone; return NSDragOperationNone;
}
} }
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
...@@ -423,54 +411,11 @@ static NSMutableArray *blackoutWindows = NULL; ...@@ -423,54 +411,11 @@ static NSMutableArray *blackoutWindows = NULL;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
NSPasteboard *o_paste = [sender draggingPasteboard]; BOOL b_returned;
NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil]; b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
NSData *o_carried_data = [o_paste dataForType:o_desired_type];
BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
if( o_carried_data )
{
if ([o_desired_type isEqualToString:NSFilenamesPboardType])
{
NSArray *o_array = [NSArray array];
NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
BOOL b_returned = NO;
if (count == 1 && p_input)
{
b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
vlc_object_release( p_input );
if(!b_returned)
return YES;
}
else if( p_input )
vlc_object_release( p_input );
for( NSUInteger i = 0; i < count; i++)
{
NSDictionary *o_dic;
char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
if( !psz_uri )
continue;
o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
free( psz_uri );
o_array = [o_array arrayByAddingObject: o_dic];
}
if( b_autoplay )
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
return YES;
}
}
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
return YES; return b_returned;
} }
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
...@@ -810,21 +755,15 @@ void _drawFrameInRect(NSRect frameRect) ...@@ -810,21 +755,15 @@ void _drawFrameInRect(NSRect frameRect)
- (void)awakeFromNib - (void)awakeFromNib
{ {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
NSFilenamesPboardType, nil]];
} }
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{ {
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
== NSDragOperationGeneric)
{
return NSDragOperationGeneric; return NSDragOperationGeneric;
}
else
{
return NSDragOperationNone; return NSDragOperationNone;
}
} }
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
...@@ -834,52 +773,9 @@ void _drawFrameInRect(NSRect frameRect) ...@@ -834,52 +773,9 @@ void _drawFrameInRect(NSRect frameRect)
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
NSPasteboard *o_paste = [sender draggingPasteboard]; BOOL b_returned;
NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil]; b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
NSData *o_carried_data = [o_paste dataForType:o_desired_type];
BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
if( o_carried_data )
{
if ([o_desired_type isEqualToString:NSFilenamesPboardType])
{
NSArray *o_array = [NSArray array];
NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSUInteger count = [o_values count];
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
BOOL b_returned = NO;
if (count == 1 && p_input)
{
b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
vlc_object_release( p_input );
if(!b_returned)
return YES;
}
else if( p_input )
vlc_object_release( p_input );
for( NSUInteger i = 0; i < count; i++)
{
NSDictionary *o_dic;
char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
if( !psz_uri )
continue;
o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
free( psz_uri );
o_array = [o_array arrayByAddingObject: o_dic];
}
if( b_autoplay )
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
return YES;
}
}
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
return YES; return YES;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment