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 * extension to NSWindow's interface to fix compilation warnings
41 * and let us access this functions properly
42 * this uses a private Apple-API, but works fine on all current OSX releases
43 * keep checking for compatiblity with future releases though
44 *****************************************************************************/
46 @interface NSWindow (UndocumentedWindowProperties)
47 - (void)setBottomCornerRounded: (BOOL)value;
50 /*****************************************************************************
51 * VLCEmbeddedWindow Implementation
52 *****************************************************************************/
54 @implementation VLCEmbeddedWindow
58 [self setDelegate: self];
59 [self setBottomCornerRounded:NO];
62 [o_btn_backward setToolTip: _NS("Rewind")];
63 [o_btn_forward setToolTip: _NS("Fast Forward")];
64 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
65 [o_btn_play setToolTip: _NS("Play")];
66 [o_timeslider setToolTip: _NS("Position")];
67 [o_btn_prev setToolTip: _NS("Previous")];
68 [o_btn_stop setToolTip: _NS("Stop")];
69 [o_btn_next setToolTip: _NS("Next")];
70 [o_volumeslider setToolTip: _NS("Volume")];
71 [o_btn_playlist setToolTip: _NS("Playlist")];
72 [self setTitle: _NS("VLC media player")];
74 o_img_play = [NSImage imageNamed: @"play_big"];
75 o_img_pause = [NSImage imageNamed: @"pause_big"];
77 [self controlTintChanged];
78 [[NSNotificationCenter defaultCenter] addObserver: self
79 selector: @selector( controlTintChanged )
80 name: NSControlTintDidChangeNotification
83 /* Set color of sidebar to Leopard's "Sidebar Blue" */
84 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedRed:0.820
89 [self setMinSize:NSMakeSize([o_sidebar_list convertRect:[o_sidebar_list bounds]
90 toView: nil].size.width + 551., 114.)];
92 /* Useful to save o_view frame in fullscreen mode */
93 o_temp_view = [[NSView alloc] init];
94 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
96 o_fullscreen_window = nil;
97 o_makekey_anim = o_fullscreen_anim1 = o_fullscreen_anim2 = nil;
99 /* Not fullscreen when we wake up */
100 [o_btn_fullscreen setState: NO];
103 /* Make sure setVisible: returns NO */
104 [self orderOut:self];
105 //b_window_is_invisible = YES;
106 videoRatio = NSMakeSize( 0., 0. );
109 - (void)controlTintChanged
112 if( [o_btn_play alternateImage] == o_img_play_pressed )
115 o_img_play_pressed = [NSImage imageNamed: @"play_big_down"];
116 o_img_pause_pressed = [NSImage imageNamed: @"pause_big_down"];
119 [o_btn_play setAlternateImage: o_img_play_pressed];
121 [o_btn_play setAlternateImage: o_img_pause_pressed];
126 [[NSNotificationCenter defaultCenter] removeObserver: self];
127 [o_img_play release];
128 [o_img_play_pressed release];
129 [o_img_pause release];
130 [o_img_pause_pressed release];
135 - (void)setTime:(NSString *)o_arg_time position:(float)f_position
137 [o_time setStringValue: o_arg_time];
138 [o_timeslider setFloatValue: f_position];
141 - (void)playStatusUpdated:(int)i_status
143 if( i_status == PLAYING_S )
145 [o_btn_play setImage: o_img_pause];
146 [o_btn_play setAlternateImage: o_img_pause_pressed];
147 [o_btn_play setToolTip: _NS("Pause")];
151 [o_btn_play setImage: o_img_play];
152 [o_btn_play setAlternateImage: o_img_play_pressed];
153 [o_btn_play setToolTip: _NS("Play")];
157 - (void)setSeekable:(BOOL)b_seekable
159 [o_btn_forward setEnabled: b_seekable];
160 [o_btn_backward setEnabled: b_seekable];
161 [o_timeslider setEnabled: b_seekable];
164 - (void)setScrollString:(NSString *)o_string
166 [o_scrollfield setStringValue: o_string];
177 - (void)setStop:(BOOL)b_input
179 [o_btn_stop setEnabled: b_input];
182 - (void)setNext:(BOOL)b_input
184 [o_btn_next setEnabled: b_input];
187 - (void)setPrev:(BOOL)b_input
189 [o_btn_prev setEnabled: b_input];
192 - (void)setVolumeEnabled:(BOOL)b_input
194 [o_volumeslider setEnabled: b_input];
197 - (void)setVolumeSlider:(float)f_level
199 [o_volumeslider setFloatValue: f_level];
202 - (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
204 [self setFrame: newFrame display: YES animate: YES];
208 - (BOOL)windowShouldClose:(id)sender
210 playlist_t * p_playlist = pl_Get( VLCIntf );
212 /* Only want to stop playback if video is playing */
213 if( videoRatio.height != 0. && videoRatio.width != 0. )
214 playlist_Stop( p_playlist );
220 if (o_fullscreen_window)
226 - (void)setVideoRatio:(NSSize)ratio
231 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
233 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
234 NSRect newList = [playlist_area frame];
235 if( newList.size.height < 50 && newList.size.height > 0 ) {
236 [self togglePlaylist:self];
239 /* With no video open or with the playlist open the behavior is odd */
240 if( newList.size.height > 50 )
241 return proposedFrameSize;
243 if( videoRatio.height == 0. || videoRatio.width == 0. )
244 return proposedFrameSize;
246 NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
247 NSRect contentRect = [self contentRectForFrameRect:[self frame]];
248 float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
249 float marginx = contentRect.size.width - viewRect.size.width;
251 proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
253 return proposedFrameSize;
256 - (void)becomeMainWindow
258 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedRed:0.820
262 [o_status becomeMainWindow];
263 [super becomeMainWindow];
266 - (void)resignMainWindow
268 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]];
269 [o_status resignMainWindow];
270 [super resignMainWindow];
273 - (CGFloat)splitView:(NSSplitView *) splitView constrainSplitPosition:(CGFloat) proposedPosition ofSubviewAt:(NSInteger) index
275 if([splitView isVertical])
276 return proposedPosition;
277 else if ( splitView == o_vertical_split )
278 return proposedPosition ;
280 float bottom = [splitView frame].size.height - [splitView dividerThickness];
281 if(proposedPosition > bottom - 50) {
282 [o_btn_playlist setState: NSOffState];
283 [o_searchfield setHidden:YES];
284 [o_playlist_view setHidden:YES];
288 [o_btn_playlist setState: NSOnState];
289 [o_searchfield setHidden:NO];
290 [o_playlist_view setHidden:NO];
291 [o_playlist swapPlaylists: o_playlist_table];
292 [o_vlc_main togglePlaylist:self];
293 return proposedPosition;
298 - (void)splitViewWillResizeSubviews:(NSNotification *) notification
303 - (CGFloat)splitView:(NSSplitView *) splitView constrainMinCoordinate:(CGFloat) proposedMin ofSubviewAt:(NSInteger) offset
305 if([splitView isVertical])
311 - (CGFloat)splitView:(NSSplitView *) splitView constrainMaxCoordinate:(CGFloat) proposedMax ofSubviewAt:(NSInteger) offset
313 if([splitView isVertical])
314 return MIN([self frame].size.width - 551, 300);
316 return [splitView frame].size.height;
319 - (BOOL)splitView:(NSSplitView *) splitView canCollapseSubview:(NSView *) subview
321 if([splitView isVertical])
327 - (NSRect)splitView:(NSSplitView *)splitView effectiveRect:(NSRect)proposedEffectiveRect forDrawnRect:(NSRect)drawnRect
328 ofDividerAtIndex:(NSInteger)dividerIndex
330 if([splitView isVertical]) {
331 drawnRect.origin.x -= 3;
332 drawnRect.size.width += 5;
339 - (IBAction)togglePlaylist:(id)sender
341 NSView *playback_area = [[o_vertical_split subviews] objectAtIndex:0];
342 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
343 NSRect newVid = [playback_area frame];
344 NSRect newList = [playlist_area frame];
345 if(newList.size.height < 50 && sender != self && sender != o_vlc_main) {
346 newList.size.height = newVid.size.height/2;
347 newVid.size.height = newVid.size.height/2;
348 newVid.origin.y = newVid.origin.y + newList.size.height;
349 [o_btn_playlist setState: NSOnState];
350 [o_searchfield setHidden:NO];
351 [o_playlist_view setHidden:NO];
352 [o_playlist swapPlaylists: o_playlist_table];
353 [o_vlc_main togglePlaylist:self];
356 newVid.size.height = newVid.size.height + newList.size.height;
357 newList.size.height = 0;
359 [o_btn_playlist setState: NSOffState];
360 [o_searchfield setHidden:YES];
361 [o_playlist_view setHidden:YES];
363 [playback_area setFrame: newVid];
364 [playlist_area setFrame: newList];
367 /*****************************************************************************
376 - (void)lockFullscreenAnimation
378 [o_animation_lock lock];
381 - (void)unlockFullscreenAnimation
383 [o_animation_lock unlock];
386 - (void)enterFullscreen
388 NSMutableDictionary *dict1, *dict2;
392 vout_thread_t *p_vout = getVout();
393 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
395 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
397 [self lockFullscreenAnimation];
401 msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
402 screen = [self screen];
406 msg_Dbg( p_vout, "Using deepest screen" );
407 screen = [NSScreen deepestScreen];
410 vlc_object_release( p_vout );
412 screen_rect = [screen frame];
414 [o_btn_fullscreen setState: YES];
416 [NSCursor setHiddenUntilMouseMoves: YES];
418 if( blackout_other_displays )
419 [screen blackoutOtherScreens];
421 /* Make sure we don't see the window flashes in float-on-top mode */
422 originalLevel = [self level];
423 [self setLevel:NSNormalWindowLevel];
425 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
426 if (!o_fullscreen_window)
428 /* We can't change the styleMask of an already created NSWindow, so we create an other window, and do eye catching stuff */
430 rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
431 rect.origin.x += [self frame].origin.x;
432 rect.origin.y += [self frame].origin.y;
433 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
434 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
435 [o_fullscreen_window setCanBecomeKeyWindow: YES];
437 if (![self isVisible] || [self alphaValue] == 0.0)
439 /* We don't animate if we are not visible, instead we
440 * simply fade the display */
441 CGDisplayFadeReservationToken token;
443 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
444 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
446 if ([screen isMainScreen])
447 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
449 [[o_view superview] replaceSubview:o_view with:o_temp_view];
450 [o_temp_view setFrame:[o_view frame]];
451 [o_fullscreen_window setContentView:o_view];
453 [o_fullscreen_window makeKeyAndOrderFront:self];
455 [o_fullscreen_window makeKeyAndOrderFront:self];
456 [o_fullscreen_window orderFront:self animate:YES];
458 [o_fullscreen_window setFrame:screen_rect display:YES];
460 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
461 CGReleaseDisplayFadeReservation( token);
463 /* Will release the lock */
464 [self hasBecomeFullscreen];
469 /* Make sure we don't see the o_view disappearing of the screen during this operation */
470 NSDisableScreenUpdates();
471 [[o_view superview] replaceSubview:o_view with:o_temp_view];
472 [o_temp_view setFrame:[o_view frame]];
473 [o_fullscreen_window setContentView:o_view];
474 [o_fullscreen_window makeKeyAndOrderFront:self];
475 NSEnableScreenUpdates();
478 /* We are in fullscreen (and no animation is running) */
481 /* Make sure we are hidden */
482 [super orderOut: self];
483 [self unlockFullscreenAnimation];
487 if (o_fullscreen_anim1)
489 [o_fullscreen_anim1 stopAnimation];
490 [o_fullscreen_anim1 release];
492 if (o_fullscreen_anim2)
494 [o_fullscreen_anim2 stopAnimation];
495 [o_fullscreen_anim2 release];
498 if ([screen isMainScreen])
499 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
501 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
502 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
504 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
505 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
507 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
508 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
509 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
511 /* Strategy with NSAnimation allocation:
512 - Keep at most 2 animation at a time
513 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
515 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
516 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
521 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
522 [o_fullscreen_anim1 setDuration: 0.3];
523 [o_fullscreen_anim1 setFrameRate: 30];
524 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
525 [o_fullscreen_anim2 setDuration: 0.2];
526 [o_fullscreen_anim2 setFrameRate: 30];
528 [o_fullscreen_anim2 setDelegate: self];
529 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
531 [o_fullscreen_anim1 startAnimation];
532 /* fullscreenAnimation will be unlocked when animation ends */
535 - (void)hasBecomeFullscreen
537 [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] controls] voutView]];
539 [o_fullscreen_window makeKeyWindow];
540 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
542 /* tell the fspanel to move itself to front next time it's triggered */
543 [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
546 [super orderOut: self];
548 [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
551 [self unlockFullscreenAnimation];
554 - (void)leaveFullscreen
556 [self leaveFullscreenAndFadeOut: NO];
559 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
561 NSMutableDictionary *dict1, *dict2;
564 [self lockFullscreenAnimation];
567 [o_btn_fullscreen setState: NO];
569 /* We always try to do so */
570 [NSScreen unblackoutScreens];
572 /* Don't do anything if o_fullscreen_window is already closed */
573 if (!o_fullscreen_window)
575 [self unlockFullscreenAnimation];
581 /* We don't animate if we are not visible, instead we
582 * simply fade the display */
583 CGDisplayFadeReservationToken token;
585 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
586 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
588 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
589 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
591 /* Will release the lock */
592 [self hasEndedFullscreen];
594 /* Our window is hidden, and might be faded. We need to workaround that, so note it
596 b_window_is_invisible = YES;
598 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
599 CGReleaseDisplayFadeReservation( token);
603 [self setAlphaValue: 0.0];
604 [self orderFront: self];
606 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
607 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
609 if (o_fullscreen_anim1)
611 [o_fullscreen_anim1 stopAnimation];
612 [o_fullscreen_anim1 release];
614 if (o_fullscreen_anim2)
616 [o_fullscreen_anim2 stopAnimation];
617 [o_fullscreen_anim2 release];
620 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
621 frame.origin.x += [self frame].origin.x;
622 frame.origin.y += [self frame].origin.y;
624 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
625 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
626 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
628 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
631 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
632 [o_fullscreen_anim2 setDuration: 0.3];
633 [o_fullscreen_anim2 setFrameRate: 30];
635 [o_fullscreen_anim2 setDelegate: self];
637 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
639 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
640 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
641 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
643 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
646 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
647 [o_fullscreen_anim1 setDuration: 0.2];
648 [o_fullscreen_anim1 setFrameRate: 30];
649 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
651 /* Make sure o_fullscreen_window is the frontmost window */
652 [o_fullscreen_window orderFront: self];
654 [o_fullscreen_anim1 startAnimation];
655 /* fullscreenAnimation will be unlocked when animation ends */
658 - (void)hasEndedFullscreen
660 /* This function is private and should be only triggered at the end of the fullscreen change animation */
661 /* Make sure we don't see the o_view disappearing of the screen during this operation */
662 NSDisableScreenUpdates();
664 [o_view removeFromSuperviewWithoutNeedingDisplay];
665 [[o_temp_view superview] replaceSubview:o_temp_view with:o_view];
667 [o_view setFrame:[o_temp_view frame]];
668 [self makeFirstResponder: o_view];
669 if ([self isVisible])
670 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
671 [o_fullscreen_window orderOut: self];
672 NSEnableScreenUpdates();
674 [o_fullscreen_window release];
675 o_fullscreen_window = nil;
676 [self setLevel:originalLevel];
678 [self unlockFullscreenAnimation];
681 - (void)animationDidEnd:(NSAnimation*)animation
683 NSArray *viewAnimations;
684 if( o_makekey_anim == animation )
686 [o_makekey_anim release];
689 if ([animation currentValue] < 1.0)
692 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
693 viewAnimations = [o_fullscreen_anim2 viewAnimations];
694 if ([viewAnimations count] >=1 &&
695 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
697 /* Fullscreen ended */
698 [self hasEndedFullscreen];
702 /* Fullscreen started */
703 [self hasBecomeFullscreen];
707 - (void)orderOut: (id)sender
709 [super orderOut: sender];
711 /* Make sure we leave fullscreen */
712 [self leaveFullscreenAndFadeOut: YES];
715 - (void)makeKeyAndOrderFront: (id)sender
718 * when we exit fullscreen and fade out, we may endup in
719 * having a window that is faded. We can't have it fade in unless we
722 if(!b_window_is_invisible)
724 /* Make sure we don't do it too much */
725 [super makeKeyAndOrderFront: sender];
729 [super setAlphaValue:0.0f];
730 [super makeKeyAndOrderFront: sender];
732 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
733 [dict setObject:self forKey:NSViewAnimationTargetKey];
734 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
736 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
739 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
740 [o_makekey_anim setDuration: 0.1];
741 [o_makekey_anim setFrameRate: 30];
742 [o_makekey_anim setDelegate: self];
744 [o_makekey_anim startAnimation];
745 b_window_is_invisible = NO;
747 /* fullscreenAnimation will be unlocked when animation ends */
752 /* Make sure setFrame gets executed on main thread especially if we are animating.
753 * (Thus we won't block the video output thread) */
754 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
756 struct { NSRect frame; BOOL display; BOOL animate;} args;
760 args.display = display;
761 args.animate = animate;
763 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
765 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
766 withObject: packedargs waitUntilDone: YES];
769 - (void)setFrameOnMainThread:(NSData*)packedargs
771 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
775 /* Make sure we don't block too long and set up a non blocking animation */
776 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
777 self, NSViewAnimationTargetKey,
778 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
779 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
781 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
784 [anim setAnimationBlockingMode: NSAnimationNonblocking];
785 [anim setDuration: 0.4];
786 [anim setFrameRate: 30];
787 [anim startAnimation];
790 [super setFrame:args->frame display:args->display animate:args->animate];
796 /*****************************************************************************
798 *****************************************************************************/
801 @implementation embeddedbackground
805 [self unregisterDraggedTypes];
811 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
812 NSFilenamesPboardType, nil]];
813 [self addSubview: o_timeslider];
814 [self addSubview: o_scrollfield];
815 [self addSubview: o_time];
816 [self addSubview: o_main_pgbar];
817 [self addSubview: o_btn_backward];
818 [self addSubview: o_btn_forward];
819 [self addSubview: o_btn_fullscreen];
820 [self addSubview: o_btn_equalizer];
821 [self addSubview: o_btn_playlist];
822 [self addSubview: o_btn_play];
823 [self addSubview: o_btn_prev];
824 [self addSubview: o_btn_stop];
825 [self addSubview: o_btn_next];
826 [self addSubview: o_btn_volume_down];
827 [self addSubview: o_volumeslider];
828 [self addSubview: o_btn_volume_up];
829 [self addSubview: o_searchfield];
832 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
834 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
835 == NSDragOperationGeneric)
837 return NSDragOperationGeneric;
841 return NSDragOperationNone;
845 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
850 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
852 NSPasteboard *o_paste = [sender draggingPasteboard];
853 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
854 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
855 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
856 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
860 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
863 NSArray *o_array = [NSArray array];
864 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
865 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
867 for( i = 0; i < (int)[o_values count]; i++)
870 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
871 o_array = [o_array arrayByAddingObject: o_dic];
874 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
876 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
880 [self setNeedsDisplay:YES];
884 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
886 [self setNeedsDisplay:YES];
889 - (void)drawRect:(NSRect)rect
891 NSImage *leftImage = [NSImage imageNamed:@"display_left"];
892 NSImage *middleImage = [NSImage imageNamed:@"display_middle"];
893 NSImage *rightImage = [NSImage imageNamed:@"display_right"];
894 [middleImage setSize:NSMakeSize(NSWidth( [self bounds] ) - 134 - [leftImage size].width - [rightImage size].width, [middleImage size].height)];
895 [middleImage setScalesWhenResized:YES];
896 [leftImage compositeToPoint:NSMakePoint( 122., 40. ) operation:NSCompositeSourceOver];
897 [middleImage compositeToPoint:NSMakePoint( 122. + [leftImage size].width, 40. ) operation:NSCompositeSourceOver];
898 [rightImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - 12 - [rightImage size].width, 40. ) operation:NSCompositeSourceOver];
901 - (void)mouseDown:(NSEvent *)event
903 dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
906 - (void)mouseDragged:(NSEvent *)event
908 NSPoint dragLocation = [self convertPoint:[event locationInWindow] fromView:nil];
909 NSPoint winOrigin = [o_window frame].origin;
911 NSPoint newOrigin = NSMakePoint(winOrigin.x + (dragLocation.x - dragStart.x),
912 winOrigin.y + (dragLocation.y - dragStart.y));
913 [o_window setFrameOrigin: newOrigin];
918 /*****************************************************************************
920 *****************************************************************************/
923 @implementation statusbar
926 [self addSubview: o_text];
930 - (void)resignMainWindow
936 - (void)becomeMainWindow
942 - (void)drawRect:(NSRect)rect
945 [[NSColor colorWithCalibratedRed:0.820
950 [[NSColor colorWithCalibratedWhite:0.91 alpha:1.0] set];
952 /*NSRect divider = rect;
953 divider.origin.y += divider.size.height - 1;
954 divider.size.height = 1;
955 [[NSColor colorWithCalibratedWhite:0.65 alpha:1.] set];
956 NSRectFill(divider);*/