2009-02-22 22:28:09 +00:00
|
|
|
//
|
|
|
|
// MiniWindow.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 2/22/09.
|
|
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MiniWindow.h"
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
#import <Carbon/Carbon.h>
|
|
|
|
|
2022-01-25 05:30:36 +00:00
|
|
|
extern NSString *iTunesDropType;
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
@implementation MiniWindow
|
|
|
|
|
2018-06-28 10:59:59 +00:00
|
|
|
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
|
2009-02-22 22:28:09 +00:00
|
|
|
{
|
2021-01-08 09:10:18 +00:00
|
|
|
self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
[self setShowsResizeIndicator:NO];
|
|
|
|
[self setExcludedFromWindowsMenu:YES];
|
|
|
|
[[self standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
2021-02-27 12:29:01 +00:00
|
|
|
|
2021-01-08 09:10:18 +00:00
|
|
|
// Disallow height resize.
|
2021-03-03 19:47:31 +00:00
|
|
|
[self setContentMinSize:NSMakeSize(325, 1)];
|
2021-02-27 12:29:01 +00:00
|
|
|
[self setContentMaxSize:NSMakeSize(CGFLOAT_MAX, 1)];
|
2013-10-11 01:14:35 +00:00
|
|
|
[self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
|
2022-01-21 07:53:45 +00:00
|
|
|
|
|
|
|
hdcdLogo = [NSImage imageNamed:@"hdcdLogoTemplate"];
|
2021-01-08 09:10:18 +00:00
|
|
|
}
|
2009-02-22 22:28:09 +00:00
|
|
|
|
2021-01-08 09:10:18 +00:00
|
|
|
return self;
|
2009-02-22 22:28:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 07:53:45 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2022-01-25 05:30:36 +00:00
|
|
|
[super awakeFromNib];
|
|
|
|
|
2022-01-21 07:53:45 +00:00
|
|
|
[self showHDCDLogo:NO];
|
2022-01-25 05:30:36 +00:00
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
[self setLevel:kCGDraggingWindowLevel-1];
|
|
|
|
[self registerForDraggedTypes:@[fileType, iTunesDropType]];
|
2022-01-21 07:53:45 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 19:02:05 +00:00
|
|
|
- (void)toggleToolbarShown:(id)sender {
|
|
|
|
// Mini window IS the toolbar, no point in hiding it.
|
|
|
|
// Do nothing!
|
|
|
|
}
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
- (void)keyDown:(NSEvent *)event {
|
|
|
|
BOOL modifiersUsed =([event modifierFlags] & (NSEventModifierFlagShift |
|
|
|
|
NSEventModifierFlagControl |
|
|
|
|
NSEventModifierFlagOption |
|
|
|
|
NSEventModifierFlagCommand)) ? YES : NO;
|
|
|
|
if (modifiersUsed) {
|
|
|
|
[super keyDown:event];
|
2018-09-27 03:30:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
switch ([event keyCode]) {
|
|
|
|
case kVK_Space:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController playPauseResume:self];
|
|
|
|
break;
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
case kVK_Return:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController play:self];
|
|
|
|
break;
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
case kVK_LeftArrow:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController eventSeekBackward:self];
|
|
|
|
break;
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
case kVK_RightArrow:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController eventSeekForward:self];
|
|
|
|
break;
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
case kVK_UpArrow:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController volumeUp:self];
|
|
|
|
break;
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
case kVK_DownArrow:
|
2021-01-08 09:10:18 +00:00
|
|
|
[playbackController volumeDown:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-02-19 05:23:13 +00:00
|
|
|
[super keyDown:event];
|
2021-01-08 09:10:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-27 03:30:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 07:53:45 +00:00
|
|
|
- (void)showHDCDLogo:(BOOL)show
|
|
|
|
{
|
|
|
|
for (NSToolbarItem * toolbarItem in [miniToolbar items])
|
|
|
|
{
|
|
|
|
if ([[toolbarItem itemIdentifier] isEqualToString:@"hdcd"]) {
|
|
|
|
if (show)
|
|
|
|
[toolbarItem setImage:hdcdLogo];
|
|
|
|
else
|
|
|
|
[toolbarItem setImage:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-11 19:02:05 +00:00
|
|
|
|
2022-01-25 05:30:36 +00:00
|
|
|
- (NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard * pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:iTunesDropType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:fileType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) draggingUpdated:(id<NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard * pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:iTunesDropType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:fileType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation:(id<NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard * pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:iTunesDropType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:fileType])
|
|
|
|
{
|
|
|
|
if (sourceDragMask & NSDragOperationGeneric)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation:(id<NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard * pboard = [sender draggingPasteboard];
|
|
|
|
|
|
|
|
NSPasteboardType fileType;
|
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
fileType = NSPasteboardTypeFileURL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fileType = NSFilenamesPboardType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:iTunesDropType] ||
|
|
|
|
[[pboard types] containsObject:fileType]) {
|
|
|
|
NSUInteger row = [[playlistController arrangedObjects] count];
|
|
|
|
return [playlistController tableView:[playlistController tableView] acceptDrop:sender row:row dropOperation:NSTableViewDropOn];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
@end
|