1 /*****************************************************************************
2 * embeddedwindow.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2005-2008 the VideoLAN team
7 * Authors: Benjamin Pracht <bigben at videolan dot org>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #import "embeddedwindow.h"
36 /* SetSystemUIMode, ... */
37 #import <Carbon/Carbon.h>
39 /*****************************************************************************
40 * VLCEmbeddedWindow Implementation
41 *****************************************************************************/
43 @implementation VLCEmbeddedWindow
45 - (id)initWithContentRect:(NSRect)contentRect styleMask: (NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
47 BOOL b_useTextured = YES;
48 if( [[NSWindow class] instancesRespondToSelector:@selector(setContentBorderThickness:forEdge:)] )
51 windowStyle ^= NSTexturedBackgroundWindowMask;
53 self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
56 [self setContentBorderThickness:28.0 forEdge:NSMinYEdge];
63 [self setDelegate: self];
66 [o_btn_backward setToolTip: _NS("Rewind")];
67 [o_btn_forward setToolTip: _NS("Fast Forward")];
68 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
69 [o_btn_play setToolTip: _NS("Play")];
70 [o_timeslider setToolTip: _NS("Position")];
71 [o_btn_prev setToolTip: _NS("Previous")];
72 [o_btn_stop setToolTip: _NS("Stop")];
73 [o_btn_next setToolTip: _NS("Next")];
74 [o_volumeslider setToolTip: _NS("Volume")];
75 [o_btn_playlist setToolTip: _NS("Playlist")];
76 [self setTitle: _NS("VLC media player")];
78 o_img_play = [NSImage imageNamed: @"play_embedded"];
79 o_img_pause = [NSImage imageNamed: @"pause_embedded"];
81 [self controlTintChanged];
82 [[NSNotificationCenter defaultCenter] addObserver: self
83 selector: @selector( controlTintChanged )
84 name: NSControlTintDidChangeNotification
87 /* Set color of sidebar to Leopard's "Sidebar Blue" */
88 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedRed:0.820
93 [self setMinSize:NSMakeSize([o_sidebar_list convertRect:[o_sidebar_list bounds]
94 toView: nil].size.width + 551., 114.)];
96 /* Useful to save o_view frame in fullscreen mode */
97 o_temp_view = [[NSView alloc] init];
98 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
100 o_fullscreen_window = nil;
101 o_makekey_anim = o_fullscreen_anim1 = o_fullscreen_anim2 = nil;
103 /* Not fullscreen when we wake up */
104 [o_btn_fullscreen setState: NO];
107 [self setMovableByWindowBackground:YES];
109 [self setDelegate:self];
111 /* Make sure setVisible: returns NO */
112 [self orderOut:self];
113 b_window_is_invisible = YES;
114 videoRatio = NSMakeSize( 0., 0. );
117 - (void)controlTintChanged
120 if( [o_btn_play alternateImage] == o_img_play_pressed )
123 if( [NSColor currentControlTint] == NSGraphiteControlTint )
125 o_img_play_pressed = [NSImage imageNamed: @"play_embedded_graphite"];
126 o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_graphite"];
127 [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_graphite"]];
128 [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_graphite"]];
129 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
131 o_img_play_pressed = [NSImage imageNamed: @"play_embedded_blue"];
132 o_img_pause_pressed = [NSImage imageNamed: @"pause_embedded_blue"];
133 [o_btn_backward setAlternateImage: [NSImage imageNamed: @"skip_previous_embedded_blue"]];
134 [o_btn_forward setAlternateImage: [NSImage imageNamed: @"skip_forward_embedded_blue"]];
135 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
139 [o_btn_play setAlternateImage: o_img_play_pressed];
141 [o_btn_play setAlternateImage: o_img_pause_pressed];
146 [[NSNotificationCenter defaultCenter] removeObserver: self];
147 [o_img_play release];
148 [o_img_play_pressed release];
149 [o_img_pause release];
150 [o_img_pause_pressed release];
155 - (void)setTime:(NSString *)o_arg_time position:(float)f_position
157 [o_time setStringValue: o_arg_time];
158 [o_timeslider setFloatValue: f_position];
161 - (void)playStatusUpdated:(int)i_status
163 if( i_status == PLAYING_S )
165 [o_btn_play setImage: o_img_pause];
166 [o_btn_play setAlternateImage: o_img_pause_pressed];
167 [o_btn_play setToolTip: _NS("Pause")];
171 [o_btn_play setImage: o_img_play];
172 [o_btn_play setAlternateImage: o_img_play_pressed];
173 [o_btn_play setToolTip: _NS("Play")];
177 - (void)setSeekable:(BOOL)b_seekable
179 [o_btn_forward setEnabled: b_seekable];
180 [o_btn_backward setEnabled: b_seekable];
181 [o_timeslider setEnabled: b_seekable];
184 - (void)setScrollString:(NSString *)o_string
186 [o_scrollfield setStringValue: o_string];
197 - (void)setStop:(BOOL)b_input
199 [o_btn_stop setEnabled: b_input];
202 - (void)setNext:(BOOL)b_input
204 [o_btn_next setEnabled: b_input];
207 - (void)setPrev:(BOOL)b_input
209 [o_btn_prev setEnabled: b_input];
212 - (void)setVolumeEnabled:(BOOL)b_input
214 [o_volumeslider setEnabled: b_input];
217 - (void)setVolumeSlider:(float)f_level
219 [o_volumeslider setFloatValue: f_level];
222 - (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
224 [self setFrame: newFrame display: YES animate: YES];
228 - (BOOL)windowShouldClose:(id)sender
230 playlist_t * p_playlist = pl_Get( VLCIntf );
231 playlist_Stop( p_playlist );
238 if (o_fullscreen_window)
244 - (void)setVideoRatio:(NSSize)ratio
249 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
251 if( videoRatio.height == 0. || videoRatio.width == 0. )
252 return proposedFrameSize;
254 if( [[[VLCMain sharedInstance] controls] aspectRatioIsLocked] )
256 NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
257 NSRect contentRect = [self contentRectForFrameRect:[self frame]];
258 float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
259 float marginx = contentRect.size.width - viewRect.size.width;
260 proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
263 return proposedFrameSize;
266 - (void)becomeMainWindow
268 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedRed:0.820
272 [o_status becomeMainWindow];
273 [super becomeMainWindow];
276 - (void)resignMainWindow
278 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]];
279 [o_status resignMainWindow];
280 [super resignMainWindow];
283 - (CGFloat)splitView:(NSSplitView *) splitView constrainSplitPosition:(CGFloat) proposedPosition ofSubviewAt:(NSInteger) index
285 if([splitView isVertical])
286 return proposedPosition;
287 else if ( splitView == o_vertical_split )
288 return proposedPosition ;
290 float bottom = [splitView frame].size.height - [splitView dividerThickness];
291 if(proposedPosition > bottom - 50) {
292 [o_btn_playlist setState: NSOffState];
293 [o_searchfield setHidden:YES];
294 [o_playlist_view setHidden:YES];
298 [o_btn_playlist setState: NSOnState];
299 [o_searchfield setHidden:NO];
300 [o_playlist_view setHidden:NO];
301 [o_playlist swapPlaylists: o_playlist_table];
302 [o_vlc_main togglePlaylist:self];
303 return proposedPosition;
308 - (void)splitViewWillResizeSubviews:(NSNotification *) notification
313 - (CGFloat)splitView:(NSSplitView *) splitView constrainMinCoordinate:(CGFloat) proposedMin ofSubviewAt:(NSInteger) offset
315 if([splitView isVertical])
321 - (CGFloat)splitView:(NSSplitView *) splitView constrainMaxCoordinate:(CGFloat) proposedMax ofSubviewAt:(NSInteger) offset
323 if([splitView isVertical])
324 return MIN([self frame].size.width - 551, 300);
326 return [splitView frame].size.height;
329 - (BOOL)splitView:(NSSplitView *) splitView canCollapseSubview:(NSView *) subview
331 if([splitView isVertical])
337 - (NSRect)splitView:(NSSplitView *)splitView effectiveRect:(NSRect)proposedEffectiveRect forDrawnRect:(NSRect)drawnRect
338 ofDividerAtIndex:(NSInteger)dividerIndex
340 if([splitView isVertical]) {
341 drawnRect.origin.x -= 3;
342 drawnRect.size.width += 5;
349 - (IBAction)togglePlaylist:(id)sender
351 NSView *playback_area = [[o_vertical_split subviews] objectAtIndex:0];
352 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
353 NSRect newVid = [playback_area frame];
354 NSRect newList = [playlist_area frame];
355 if(newList.size.height < 50 && sender != self && sender != o_vlc_main) {
356 newList.size.height = newVid.size.height/2;
357 newVid.size.height = newVid.size.height/2;
358 newVid.origin.y = newVid.origin.y + newList.size.height;
359 [o_btn_playlist setState: NSOnState];
360 [o_searchfield setHidden:NO];
361 [o_playlist_view setHidden:NO];
362 [o_playlist swapPlaylists: o_playlist_table];
363 [o_vlc_main togglePlaylist:self];
366 newVid.size.height = newVid.size.height + newList.size.height;
367 newList.size.height = 0;
369 [o_btn_playlist setState: NSOffState];
370 [o_searchfield setHidden:YES];
371 [o_playlist_view setHidden:YES];
373 [playback_area setFrame: newVid];
374 [playlist_area setFrame: newList];
377 /*****************************************************************************
386 - (void)lockFullscreenAnimation
388 [o_animation_lock lock];
391 - (void)unlockFullscreenAnimation
393 [o_animation_lock unlock];
396 - (void)enterFullscreen
398 NSMutableDictionary *dict1, *dict2;
402 vout_thread_t *p_vout = getVout();
403 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
405 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
407 [self lockFullscreenAnimation];
411 msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
412 screen = [self screen];
416 msg_Dbg( p_vout, "Using deepest screen" );
417 screen = [NSScreen deepestScreen];
420 vlc_object_release( p_vout );
422 screen_rect = [screen frame];
424 [o_btn_fullscreen setState: YES];
426 [NSCursor setHiddenUntilMouseMoves: YES];
428 if( blackout_other_displays )
429 [screen blackoutOtherScreens];
431 /* Make sure we don't see the window flashes in float-on-top mode */
432 originalLevel = [self level];
433 [self setLevel:NSNormalWindowLevel];
435 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
436 if (!o_fullscreen_window)
438 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
440 rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
441 rect.origin.x += [self frame].origin.x;
442 rect.origin.y += [self frame].origin.y;
443 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
444 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
445 [o_fullscreen_window setCanBecomeKeyWindow: YES];
447 if (![self isVisible] || [self alphaValue] == 0.0)
449 /* We don't animate if we are not visible, instead we
450 * simply fade the display */
451 CGDisplayFadeReservationToken token;
453 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
454 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
456 if ([screen isMainScreen])
457 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
459 [[o_view superview] replaceSubview:o_view with:o_temp_view];
460 [o_temp_view setFrame:[o_view frame]];
461 [o_fullscreen_window setContentView:o_view];
463 [o_fullscreen_window makeKeyAndOrderFront:self];
464 [o_fullscreen_window orderFront:self animate:YES];
466 [o_fullscreen_window setFrame:screen_rect display:YES];
468 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
469 CGReleaseDisplayFadeReservation( token);
471 /* Will release the lock */
472 [self hasBecomeFullscreen];
477 /* Make sure we don't see the o_view disappearing of the screen during this operation */
478 NSDisableScreenUpdates();
479 [[o_view superview] replaceSubview:o_view with:o_temp_view];
480 [o_temp_view setFrame:[o_view frame]];
481 [o_fullscreen_window setContentView:o_view];
482 [o_fullscreen_window makeKeyAndOrderFront:self];
483 NSEnableScreenUpdates();
486 /* We are in fullscreen (and no animation is running) */
489 /* Make sure we are hidden */
490 [super orderOut: self];
491 [self unlockFullscreenAnimation];
495 if (o_fullscreen_anim1)
497 [o_fullscreen_anim1 stopAnimation];
498 [o_fullscreen_anim1 release];
500 if (o_fullscreen_anim2)
502 [o_fullscreen_anim2 stopAnimation];
503 [o_fullscreen_anim2 release];
506 if ([screen isMainScreen])
507 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
509 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
510 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
512 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
513 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
515 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
516 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
517 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
519 /* Strategy with NSAnimation allocation:
520 - Keep at most 2 animation at a time
521 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
523 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
524 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
529 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
530 [o_fullscreen_anim1 setDuration: 0.3];
531 [o_fullscreen_anim1 setFrameRate: 30];
532 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
533 [o_fullscreen_anim2 setDuration: 0.2];
534 [o_fullscreen_anim2 setFrameRate: 30];
536 [o_fullscreen_anim2 setDelegate: self];
537 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
539 [o_fullscreen_anim1 startAnimation];
540 /* fullscreenAnimation will be unlocked when animation ends */
543 - (void)hasBecomeFullscreen
545 [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] controls] voutView]];
547 [o_fullscreen_window makeKeyWindow];
548 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
550 /* tell the fspanel to move itself to front next time it's triggered */
551 [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
554 [super orderOut: self];
556 [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
559 [self unlockFullscreenAnimation];
562 - (void)leaveFullscreen
564 [self leaveFullscreenAndFadeOut: NO];
567 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
569 NSMutableDictionary *dict1, *dict2;
572 [self lockFullscreenAnimation];
575 [o_btn_fullscreen setState: NO];
577 /* We always try to do so */
578 [NSScreen unblackoutScreens];
580 /* Don't do anything if o_fullscreen_window is already closed */
581 if (!o_fullscreen_window)
583 [self unlockFullscreenAnimation];
589 /* We don't animate if we are not visible, instead we
590 * simply fade the display */
591 CGDisplayFadeReservationToken token;
593 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
594 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
596 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
597 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
599 /* Will release the lock */
600 [self hasEndedFullscreen];
602 /* Our window is hidden, and might be faded. We need to workaround that, so note it
604 b_window_is_invisible = YES;
606 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
607 CGReleaseDisplayFadeReservation( token);
611 [self setAlphaValue: 0.0];
612 [self orderFront: self];
614 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
615 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
617 if (o_fullscreen_anim1)
619 [o_fullscreen_anim1 stopAnimation];
620 [o_fullscreen_anim1 release];
622 if (o_fullscreen_anim2)
624 [o_fullscreen_anim2 stopAnimation];
625 [o_fullscreen_anim2 release];
628 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
629 frame.origin.x += [self frame].origin.x;
630 frame.origin.y += [self frame].origin.y;
632 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
633 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
634 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
636 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
639 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
640 [o_fullscreen_anim2 setDuration: 0.3];
641 [o_fullscreen_anim2 setFrameRate: 30];
643 [o_fullscreen_anim2 setDelegate: self];
645 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
647 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
648 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
649 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
651 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
654 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
655 [o_fullscreen_anim1 setDuration: 0.2];
656 [o_fullscreen_anim1 setFrameRate: 30];
657 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
659 /* Make sure o_fullscreen_window is the frontmost window */
660 [o_fullscreen_window orderFront: self];
662 [o_fullscreen_anim1 startAnimation];
663 /* fullscreenAnimation will be unlocked when animation ends */
666 - (void)hasEndedFullscreen
668 /* This function is private and should be only triggered at the end of the fullscreen change animation */
669 /* Make sure we don't see the o_view disappearing of the screen during this operation */
670 NSDisableScreenUpdates();
672 [o_view removeFromSuperviewWithoutNeedingDisplay];
673 [[o_temp_view superview] replaceSubview:o_temp_view with:o_view];
675 [o_view setFrame:[o_temp_view frame]];
676 [self makeFirstResponder: o_view];
677 if ([self isVisible])
678 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
679 [o_fullscreen_window orderOut: self];
680 NSEnableScreenUpdates();
682 [o_fullscreen_window release];
683 o_fullscreen_window = nil;
684 [self setLevel:originalLevel];
686 [self unlockFullscreenAnimation];
689 - (void)animationDidEnd:(NSAnimation*)animation
691 NSArray *viewAnimations;
692 if( o_makekey_anim == animation )
694 [o_makekey_anim release];
697 if ([animation currentValue] < 1.0)
700 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
701 viewAnimations = [o_fullscreen_anim2 viewAnimations];
702 if ([viewAnimations count] >=1 &&
703 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
705 /* Fullscreen ended */
706 [self hasEndedFullscreen];
710 /* Fullscreen started */
711 [self hasBecomeFullscreen];
715 - (void)orderOut: (id)sender
717 [super orderOut: sender];
719 /* Make sure we leave fullscreen */
720 [self leaveFullscreenAndFadeOut: YES];
723 - (void)makeKeyAndOrderFront: (id)sender
726 * when we exit fullscreen and fade out, we may endup in
727 * having a window that is faded. We can't have it fade in unless we
730 if(!b_window_is_invisible)
732 /* Make sure we don't do it too much */
733 [super makeKeyAndOrderFront: sender];
737 [super setAlphaValue:0.0f];
738 [super makeKeyAndOrderFront: sender];
740 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
741 [dict setObject:self forKey:NSViewAnimationTargetKey];
742 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
744 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
747 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
748 [o_makekey_anim setDuration: 0.1];
749 [o_makekey_anim setFrameRate: 30];
750 [o_makekey_anim setDelegate: self];
752 [o_makekey_anim startAnimation];
753 b_window_is_invisible = NO;
755 /* fullscreenAnimation will be unlocked when animation ends */
760 /* Make sure setFrame gets executed on main thread especially if we are animating.
761 * (Thus we won't block the video output thread) */
762 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
764 struct { NSRect frame; BOOL display; BOOL animate;} args;
768 args.display = display;
769 args.animate = animate;
771 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
773 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
774 withObject: packedargs waitUntilDone: YES];
777 - (void)setFrameOnMainThread:(NSData*)packedargs
779 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
783 /* Make sure we don't block too long and set up a non blocking animation */
784 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
785 self, NSViewAnimationTargetKey,
786 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
787 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
789 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
792 [anim setAnimationBlockingMode: NSAnimationNonblocking];
793 [anim setDuration: 0.4];
794 [anim setFrameRate: 30];
795 [anim startAnimation];
798 [super setFrame:args->frame display:args->display animate:args->animate];
804 /*****************************************************************************
806 *****************************************************************************/
809 @implementation embeddedbackground
813 [self unregisterDraggedTypes];
819 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
820 NSFilenamesPboardType, nil]];
821 [self addSubview: o_timeslider];
822 [self addSubview: o_scrollfield];
823 [self addSubview: o_time];
824 [self addSubview: o_main_pgbar];
825 [self addSubview: o_btn_backward];
826 [self addSubview: o_btn_forward];
827 [self addSubview: o_btn_fullscreen];
828 [self addSubview: o_btn_equalizer];
829 [self addSubview: o_btn_playlist];
830 [self addSubview: o_btn_play];
831 [self addSubview: o_btn_prev];
832 [self addSubview: o_btn_stop];
833 [self addSubview: o_btn_next];
834 [self addSubview: o_btn_volume_down];
835 [self addSubview: o_volumeslider];
836 [self addSubview: o_btn_volume_up];
837 [self addSubview: o_searchfield];
840 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
842 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
843 == NSDragOperationGeneric)
845 return NSDragOperationGeneric;
849 return NSDragOperationNone;
853 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
858 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
860 NSPasteboard *o_paste = [sender draggingPasteboard];
861 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
862 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
863 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
864 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
868 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
871 NSArray *o_array = [NSArray array];
872 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
873 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
875 for( i = 0; i < (int)[o_values count]; i++)
878 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
879 o_array = [o_array arrayByAddingObject: o_dic];
882 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
884 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
888 [self setNeedsDisplay:YES];
892 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
894 [self setNeedsDisplay:YES];
897 - (void)drawRect:(NSRect)rect
899 NSImage *leftImage = [NSImage imageNamed:@"display_left"];
900 NSImage *middleImage = [NSImage imageNamed:@"display_middle"];
901 NSImage *rightImage = [NSImage imageNamed:@"display_right"];
902 [middleImage setSize:NSMakeSize(NSWidth( [self bounds] ) - 134 - [leftImage size].width - [rightImage size].width, [middleImage size].height)];
903 [middleImage setScalesWhenResized:YES];
904 [leftImage compositeToPoint:NSMakePoint( 122., 40. ) operation:NSCompositeSourceOver];
905 [middleImage compositeToPoint:NSMakePoint( 122. + [leftImage size].width, 40. ) operation:NSCompositeSourceOver];
906 [rightImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - 12 - [rightImage size].width, 40. ) operation:NSCompositeSourceOver];
909 - (void)mouseDown:(NSEvent *)event
911 dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
914 - (void)mouseDragged:(NSEvent *)event
916 NSPoint dragLocation = [self convertPoint:[event locationInWindow] fromView:nil];
917 NSPoint winOrigin = [o_window frame].origin;
919 NSPoint newOrigin = NSMakePoint(winOrigin.x + (dragLocation.x - dragStart.x),
920 winOrigin.y + (dragLocation.y - dragStart.y));
921 [o_window setFrameOrigin: newOrigin];
926 /*****************************************************************************
928 *****************************************************************************/
931 @implementation statusbar
934 [self addSubview: o_text];
938 - (void)resignMainWindow
944 - (void)becomeMainWindow
950 - (void)drawRect:(NSRect)rect
953 [[NSColor colorWithCalibratedRed:0.820
958 [[NSColor colorWithCalibratedWhite:0.91 alpha:1.0] set];
960 /*NSRect divider = rect;
961 divider.origin.y += divider.size.height - 1;
962 divider.size.height = 1;
963 [[NSColor colorWithCalibratedWhite:0.65 alpha:1.] set];
964 NSRectFill(divider);*/