Commit c55ac4fe 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
parent abbeb91f
......@@ -70,6 +70,8 @@
- (int)volume;
- (void)setVolume:(int)i_value;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (void)setAspectRatioLocked:(BOOL)b_value;
- (BOOL)aspectRatioIsLocked;
- (void)toggleFullscreen;
......
......@@ -24,6 +24,7 @@
#import "CoreInteraction.h"
#import "intf.h"
#import "open.h"
#import "playlist.h"
#import <vlc_playlist.h>
#import <vlc_input.h>
#import <vlc_keys.h>
......@@ -31,6 +32,7 @@
#import <vlc_aout_intf.h>
#import <vlc/vlc.h>
#import <vlc_strings.h>
#import <vlc_url.h>
@implementation VLCCoreInteraction
static VLCCoreInteraction *_o_sharedInstance = nil;
......@@ -549,6 +551,60 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
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 video output stuff
......
......@@ -74,6 +74,50 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
* VLCVoutView implementation
*****************************************************************************/
@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
{
vout_thread_t * p_vout = getVout();
......
......@@ -23,7 +23,6 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import <ApplicationServices/ApplicationServices.h>
#import "CompatibilityFixes.h"
/*****************************************************************************
......
......@@ -22,17 +22,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import "CompatibilityFixes.h"
#import "misc.h"
#import "intf.h" /* VLCApplication */
#import "MainWindow.h"
#import "misc.h"
#import "playlist.h"
#import "controls.h"
#import "CoreInteraction.h"
#import <vlc_url.h>
/*****************************************************************************
* NSAnimation (VLCAdditions)
......@@ -396,8 +390,7 @@ static NSMutableArray *blackoutWindows = NULL;
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
NSFilenamesPboardType, nil]];
[self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
[self setImageScaling: NSScaleToFit];
[self setImageFrameStyle: NSImageFrameNone];
[self setImageAlignment: NSImageAlignCenter];
......@@ -405,15 +398,10 @@ static NSMutableArray *blackoutWindows = NULL;
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
== NSDragOperationGeneric)
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
return NSDragOperationGeneric;
}
else
{
return NSDragOperationNone;
}
return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
......@@ -423,54 +411,11 @@ static NSMutableArray *blackoutWindows = NULL;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *o_paste = [sender draggingPasteboard];
NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
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 );
BOOL b_returned;
b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
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];
return YES;
return b_returned;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
......@@ -810,21 +755,15 @@ void _drawFrameInRect(NSRect frameRect)
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
NSFilenamesPboardType, nil]];
[self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
== NSDragOperationGeneric)
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
return NSDragOperationGeneric;
}
else
{
return NSDragOperationNone;
}
return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
......@@ -834,52 +773,9 @@ void _drawFrameInRect(NSRect frameRect)
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *o_paste = [sender draggingPasteboard];
NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
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];
BOOL b_returned;
b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
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];
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