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;
|
|
|
|
|
2022-06-22 02:01:06 +00:00
|
|
|
extern void showCrashlyticsConsent(NSWindow *window);
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
@implementation MiniWindow
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation {
|
|
|
|
self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
|
|
|
|
if(self) {
|
|
|
|
[self setShowsResizeIndicator:NO];
|
|
|
|
[self setExcludedFromWindowsMenu:YES];
|
|
|
|
[[self standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
|
|
|
|
|
|
|
// Disallow height resize.
|
|
|
|
[self setContentMinSize:NSMakeSize(325, 1)];
|
|
|
|
[self setContentMaxSize:NSMakeSize(CGFLOAT_MAX, 1)];
|
|
|
|
[self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
|
|
|
|
|
|
|
|
hdcdLogo = [NSImage imageNamed:@"hdcdLogoTemplate"];
|
|
|
|
|
|
|
|
[self setFrameUsingName:@"Mini Window"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2009-02-22 22:28:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)awakeFromNib {
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
[self showHDCDLogo:NO];
|
|
|
|
|
2022-06-23 05:54:32 +00:00
|
|
|
[self registerForDraggedTypes:@[NSPasteboardTypeFileURL, iTunesDropType]];
|
2022-06-22 02:01:06 +00:00
|
|
|
|
|
|
|
if([[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"]) {
|
|
|
|
showCrashlyticsConsent(self);
|
|
|
|
}
|
2022-01-21 07:53:45 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 19:02:05 +00:00
|
|
|
- (void)toggleToolbarShown:(id)sender {
|
2022-02-07 05:49:27 +00:00
|
|
|
// Mini window IS the toolbar, no point in hiding it.
|
|
|
|
// Do nothing!
|
2013-10-11 19:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 05:23:13 +00:00
|
|
|
- (void)keyDown:(NSEvent *)event {
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL modifiersUsed = ([event modifierFlags] & (NSEventModifierFlagShift |
|
|
|
|
NSEventModifierFlagControl |
|
|
|
|
NSEventModifierFlagOption |
|
|
|
|
NSEventModifierFlagCommand)) ?
|
|
|
|
YES :
|
|
|
|
NO;
|
|
|
|
if(modifiersUsed) {
|
|
|
|
[super keyDown:event];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch([event keyCode]) {
|
|
|
|
case kVK_Space:
|
|
|
|
[playbackController playPauseResume:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_Return:
|
|
|
|
[playbackController play:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_LeftArrow:
|
|
|
|
[playbackController eventSeekBackward:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_RightArrow:
|
|
|
|
[playbackController eventSeekForward:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_UpArrow:
|
|
|
|
[playbackController volumeUp:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kVK_DownArrow:
|
|
|
|
[playbackController volumeDown:self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
[super keyDown:event];
|
|
|
|
break;
|
|
|
|
}
|
2018-09-27 03:30:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)showHDCDLogo:(BOOL)show {
|
|
|
|
for(NSToolbarItem *toolbarItem in [miniToolbar items]) {
|
2022-06-11 20:37:51 +00:00
|
|
|
if([[toolbarItem itemIdentifier] isEqualToString:@"hdcdMini"]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(show)
|
|
|
|
[toolbarItem setImage:hdcdLogo];
|
|
|
|
else
|
|
|
|
[toolbarItem setImage:nil];
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 07:53:45 +00:00
|
|
|
}
|
2013-10-11 19:02:05 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
|
|
|
NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
if([[pboard types] containsObject:iTunesDropType]) {
|
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:54:32 +00:00
|
|
|
if([[pboard types] containsObject:NSPasteboardTypeFileURL]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
2022-01-25 05:30:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
|
|
|
|
NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
if([[pboard types] containsObject:iTunesDropType]) {
|
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:54:32 +00:00
|
|
|
if([[pboard types] containsObject:NSPasteboardTypeFileURL]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSDragOperationNone;
|
2022-01-25 05:30:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
|
|
|
|
NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
|
|
|
|
|
|
|
|
if([[pboard types] containsObject:iTunesDropType]) {
|
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:54:32 +00:00
|
|
|
if([[pboard types] containsObject:NSPasteboardTypeFileURL]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
if(sourceDragMask & NSDragOperationGeneric) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
2022-01-25 05:30:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
|
|
|
NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
|
|
|
|
if([[pboard types] containsObject:iTunesDropType] ||
|
2022-06-23 05:54:32 +00:00
|
|
|
[[pboard types] containsObject:NSPasteboardTypeFileURL]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSUInteger row = [[playlistController arrangedObjects] count];
|
|
|
|
return [playlistController tableView:[playlistController tableView] acceptDrop:sender row:row dropOperation:NSTableViewDropOn];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
2022-01-25 05:30:36 +00:00
|
|
|
}
|
|
|
|
|
2009-02-22 22:28:09 +00:00
|
|
|
@end
|