Commit 819d233b authored by David Fuhrmann's avatar David Fuhrmann

macosx: implement simpler and generic drop view for all drag / drop operations

- Use the new VLCDragDropView for both CAS and main window drop zone.
  This implements a drop highlight border the same way as in playlist view.
- Remove Brushed Metal Image view and its own drop implementation.
  When having a image view inside a drop zone, you need to use
  VLCDropDisabledImageView which disables the own drop handling of NSImageView.
- Removed more unneeded drop implementations for subviews from CAS
parent b1946d46
...@@ -171,18 +171,3 @@ ...@@ -171,18 +171,3 @@
- (void)updateDropView; - (void)updateDropView;
@end @end
@interface VLCDropEnabledBox : NSBox
{
BOOL b_activeDragAndDrop;
}
@end
@interface VLCDropEnabledImageView : NSImageView
@end
@interface VLCDropEnabledButton : NSButton
@end
...@@ -261,6 +261,10 @@ static VLCConvertAndSave *_o_sharedInstance = nil; ...@@ -261,6 +261,10 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
[_ok_btn setEnabled: NO]; [_ok_btn setEnabled: NO];
// setup drop view
[_drop_box enablePlaylistItems];
[_drop_box setDropHandler: self];
[self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]]; [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]];
} }
...@@ -1057,130 +1061,3 @@ static VLCConvertAndSave *_o_sharedInstance = nil; ...@@ -1057,130 +1061,3 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
} }
@end @end
# pragma mark -
# pragma mark Drag and drop handling
@implementation VLCDropEnabledBox
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
b_activeDragAndDrop = YES;
[self setNeedsDisplay:YES];
[[NSCursor dragCopyCursor] set];
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
return NSDragOperationGeneric;
return NSDragOperationNone;
}
- (void)draggingEnded:(id < NSDraggingInfo >)sender
{
[[NSCursor arrowCursor] set];
b_activeDragAndDrop = NO;
[self setNeedsDisplay:YES];
}
- (void)draggingExited:(id < NSDraggingInfo >)sender
{
[[NSCursor arrowCursor] set];
b_activeDragAndDrop = NO;
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)dirtyRect
{
if (b_activeDragAndDrop) {
[[NSColor colorWithCalibratedRed:(.154/.255) green:(.154/.255) blue:(.154/.255) alpha:1.] setFill];
NSRect frameRect = [[self contentView] bounds];
frameRect.origin.x += 10;
frameRect.origin.y += 10;
frameRect.size.width -= 17;
frameRect.size.height -= 17;
NSFrameRectWithWidthUsingOperation(frameRect, 4., NSCompositeHighlight);
}
[super drawRect:dirtyRect];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
@end
@implementation VLCDropEnabledImageView
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
return [[[self superview] superview] draggingEntered:sender];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
@end
@implementation VLCDropEnabledButton
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
return [[[self superview] superview] draggingEntered:sender];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
return [[VLCConvertAndSave sharedInstance] performDragOperation: sender];
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
@end
...@@ -557,7 +557,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -557,7 +557,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
} }
#pragma mark - #pragma mark -
#pragma mark drag and drop support for VLCVoutView, VLBrushedMetalImageView and VLCThreePartDropView #pragma mark drag and drop support for VLCVoutView, VLCDragDropView and VLCThreePartDropView
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
NSPasteboard *o_paste = [sender draggingPasteboard]; NSPasteboard *o_paste = [sender draggingPasteboard];
......
...@@ -70,12 +70,32 @@ ...@@ -70,12 +70,32 @@
- (void)setNonFullscreenPresentationOptions; - (void)setNonFullscreenPresentationOptions;
@end @end
/*****************************************************************************
* VLCDragDropView
*
* Disables default drag / drop behaviour of an NSImageView.
* set it for all sub image views withing an VLCDragDropView.
*****************************************************************************/
@interface VLCDropDisabledImageView : NSImageView
@end
/***************************************************************************** /*****************************************************************************
* VLBrushedMetalImageView * VLCDragDropView
*****************************************************************************/ *****************************************************************************/
@interface VLBrushedMetalImageView : NSImageView @interface VLCDragDropView : NSView
{
bool b_activeDragAndDrop;
id _dropHandler;
}
@property (nonatomic, assign) id dropHandler;
- (void)enablePlaylistItems;
@end @end
......
...@@ -300,10 +300,30 @@ static bool b_old_spaces_style = YES; ...@@ -300,10 +300,30 @@ static bool b_old_spaces_style = YES;
@end @end
/***************************************************************************** /*****************************************************************************
* VLBrushedMetalImageView * VLCDragDropView
*****************************************************************************/ *****************************************************************************/
@implementation VLBrushedMetalImageView @implementation VLCDropDisabledImageView
- (void)awakeFromNib
{
[self unregisterDraggedTypes];
}
@end
/*****************************************************************************
* VLCDragDropView
*****************************************************************************/
@implementation VLCDragDropView
@synthesize dropHandler=_dropHandler;
- (void)enablePlaylistItems
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
}
- (BOOL)mouseDownCanMoveWindow - (BOOL)mouseDownCanMoveWindow
{ {
...@@ -319,19 +339,32 @@ static bool b_old_spaces_style = YES; ...@@ -319,19 +339,32 @@ static bool b_old_spaces_style = YES;
- (void)awakeFromNib - (void)awakeFromNib
{ {
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
[self setImageScaling: NSScaleToFit];
[self setImageFrameStyle: NSImageFrameNone];
[self setImageAlignment: NSImageAlignCenter];
} }
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{ {
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) {
return NSDragOperationGeneric; b_activeDragAndDrop = YES;
[self setNeedsDisplay:YES];
return NSDragOperationCopy;
}
return NSDragOperationNone; return NSDragOperationNone;
} }
- (void)draggingEnded:(id < NSDraggingInfo >)sender
{
b_activeDragAndDrop = NO;
[self setNeedsDisplay:YES];
}
- (void)draggingExited:(id < NSDraggingInfo >)sender
{
b_activeDragAndDrop = NO;
[self setNeedsDisplay:YES];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{ {
return YES; return YES;
...@@ -340,6 +373,10 @@ static bool b_old_spaces_style = YES; ...@@ -340,6 +373,10 @@ static bool b_old_spaces_style = YES;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
BOOL b_returned; BOOL b_returned;
if (_dropHandler && [_dropHandler respondsToSelector:@selector(performDragOperation:)])
b_returned = [_dropHandler performDragOperation: sender];
else // default
b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
...@@ -351,6 +388,19 @@ static bool b_old_spaces_style = YES; ...@@ -351,6 +388,19 @@ static bool b_old_spaces_style = YES;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
- (void)drawRect:(NSRect)dirtyRect
{
if (b_activeDragAndDrop) {
NSRect frameRect = [self bounds];
[[NSColor selectedControlColor] set];
NSFrameRectWithWidthUsingOperation(frameRect, 2., NSCompositeHighlight);
}
[super drawRect:dirtyRect];
}
@end @end
......
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