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_Hold( VLCIntf );
212 /* Only want to stop playback if video is playing */
213 if( videoRatio.height != 0. && videoRatio.width != 0. )
214 playlist_Stop( p_playlist );
215 pl_Release( VLCIntf );
221 if (o_fullscreen_window)
227 - (void)setVideoRatio:(NSSize)ratio
232 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
234 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
235 NSRect newList = [playlist_area frame];
236 if( newList.size.height < 50 && newList.size.height > 0 ) {
237 [self togglePlaylist:self];
240 /* With no video open or with the playlist open the behavior is odd */
241 if( newList.size.height > 50 )
242 return proposedFrameSize;
244 if( videoRatio.height == 0. || videoRatio.width == 0. )
245 return proposedFrameSize;
247 NSRect viewRect = [o_view convertRect:[o_view bounds] toView: nil];
248 NSRect contentRect = [self contentRectForFrameRect:[self frame]];
249 float marginy = viewRect.origin.y + [self frame].size.height - contentRect.size.height;
250 float marginx = contentRect.size.width - viewRect.size.width;
252 proposedFrameSize.height = (proposedFrameSize.width - marginx) * videoRatio.height / videoRatio.width + marginy;
254 return proposedFrameSize;
257 - (void)becomeMainWindow
259 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedRed:0.820
263 [o_status becomeMainWindow];
264 [super becomeMainWindow];
267 - (void)resignMainWindow
269 [o_sidebar_list setBackgroundColor: [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]];
270 [o_status resignMainWindow];
271 [super resignMainWindow];
274 - (CGFloat)splitView:(NSSplitView *) splitView constrainSplitPosition:(CGFloat) proposedPosition ofSubviewAt:(NSInteger) index
276 if([splitView isVertical])
277 return proposedPosition;
279 float bottom = [splitView frame].size.height - [splitView dividerThickness];
280 if(proposedPosition > bottom - 50) {
281 [o_btn_playlist setState: NSOffState];
282 [o_searchfield setHidden:YES];
283 [o_playlist_view setHidden:YES];
287 [o_btn_playlist setState: NSOnState];
288 [o_searchfield setHidden:NO];
289 [o_playlist_view setHidden:NO];
290 [o_playlist swapPlaylists: o_playlist_table];
291 [o_vlc_main togglePlaylist:self];
292 return proposedPosition;
297 - (void)splitViewWillResizeSubviews:(NSNotification *) notification
302 - (CGFloat)splitView:(NSSplitView *) splitView constrainMinCoordinate:(CGFloat) proposedMin ofSubviewAt:(NSInteger) offset
304 if([splitView isVertical])
310 - (CGFloat)splitView:(NSSplitView *) splitView constrainMaxCoordinate:(CGFloat) proposedMax ofSubviewAt:(NSInteger) offset
312 if([splitView isVertical])
313 return MIN([self frame].size.width - 551, 300);
315 return [splitView frame].size.height;
318 - (BOOL)splitView:(NSSplitView *) splitView canCollapseSubview:(NSView *) subview
320 if([splitView isVertical])
326 - (NSRect)splitView:(NSSplitView *)splitView effectiveRect:(NSRect)proposedEffectiveRect forDrawnRect:(NSRect)drawnRect
327 ofDividerAtIndex:(NSInteger)dividerIndex
329 if([splitView isVertical]) {
330 drawnRect.origin.x -= 3;
331 drawnRect.size.width += 5;
338 - (IBAction)togglePlaylist:(id)sender
340 NSView *playback_area = [[o_vertical_split subviews] objectAtIndex:0];
341 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
342 NSRect newVid = [playback_area frame];
343 NSRect newList = [playlist_area frame];
344 if(newList.size.height < 50 && sender != self && sender != o_vlc_main) {
345 newList.size.height = newVid.size.height/2;
346 newVid.size.height = newVid.size.height/2;
347 newVid.origin.y = newVid.origin.y + newList.size.height;
348 [o_btn_playlist setState: NSOnState];
349 [o_searchfield setHidden:NO];
350 [o_playlist_view setHidden:NO];
351 [o_playlist swapPlaylists: o_playlist_table];
352 [o_vlc_main togglePlaylist:self];
355 newVid.size.height = newVid.size.height + newList.size.height;
356 newList.size.height = 0;
358 [o_btn_playlist setState: NSOffState];
359 [o_searchfield setHidden:YES];
360 [o_playlist_view setHidden:YES];
362 [playback_area setFrame: newVid];
363 [playlist_area setFrame: newList];
366 /*****************************************************************************
375 - (void)lockFullscreenAnimation
377 [o_animation_lock lock];
380 - (void)unlockFullscreenAnimation
382 [o_animation_lock unlock];
385 - (void)enterFullscreen
387 NSMutableDictionary *dict1, *dict2;
391 vout_thread_t *p_vout = getVout();
392 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
394 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
396 [self lockFullscreenAnimation];
400 msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
401 screen = [self screen];
405 msg_Dbg( p_vout, "Using deepest screen" );
406 screen = [NSScreen deepestScreen];
409 vlc_object_release( p_vout );
411 screen_rect = [screen frame];
413 [o_btn_fullscreen setState: YES];
415 [NSCursor setHiddenUntilMouseMoves: YES];
417 if( blackout_other_displays )
418 [screen blackoutOtherScreens];
420 /* Make sure we don't see the window flashes in float-on-top mode */
421 originalLevel = [self level];
422 [self setLevel:NSNormalWindowLevel];
424 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
425 if (!o_fullscreen_window)
427 /* We can't change the styleMask of an already created NSWindow, so we create an other window, and do eye catching stuff */
429 rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
430 rect.origin.x += [self frame].origin.x;
431 rect.origin.y += [self frame].origin.y;
432 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
433 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
434 [o_fullscreen_window setCanBecomeKeyWindow: YES];
436 if (![self isVisible] || [self alphaValue] == 0.0)
438 /* We don't animate if we are not visible, instead we
439 * simply fade the display */
440 CGDisplayFadeReservationToken token;
442 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
443 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
445 if ([screen isMainScreen])
446 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
448 [[o_view superview] replaceSubview:o_view with:o_temp_view];
449 [o_temp_view setFrame:[o_view frame]];
450 [o_fullscreen_window setContentView:o_view];
452 [o_fullscreen_window makeKeyAndOrderFront:self];
454 [o_fullscreen_window makeKeyAndOrderFront:self];
455 [o_fullscreen_window orderFront:self animate:YES];
457 [o_fullscreen_window setFrame:screen_rect display:YES];
459 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
460 CGReleaseDisplayFadeReservation( token);
462 /* Will release the lock */
463 [self hasBecomeFullscreen];
468 /* Make sure we don't see the o_view disappearing of the screen during this operation */
469 NSDisableScreenUpdates();
470 [[o_view superview] replaceSubview:o_view with:o_temp_view];
471 [o_temp_view setFrame:[o_view frame]];
472 [o_fullscreen_window setContentView:o_view];
473 [o_fullscreen_window makeKeyAndOrderFront:self];
474 NSEnableScreenUpdates();
477 /* We are in fullscreen (and no animation is running) */
480 /* Make sure we are hidden */
481 [super orderOut: self];
482 [self unlockFullscreenAnimation];
486 if (o_fullscreen_anim1)
488 [o_fullscreen_anim1 stopAnimation];
489 [o_fullscreen_anim1 release];
491 if (o_fullscreen_anim2)
493 [o_fullscreen_anim2 stopAnimation];
494 [o_fullscreen_anim2 release];
497 if ([screen isMainScreen])
498 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
500 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
501 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
503 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
504 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
506 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
507 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
508 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
510 /* Strategy with NSAnimation allocation:
511 - Keep at most 2 animation at a time
512 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
514 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
515 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
520 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
521 [o_fullscreen_anim1 setDuration: 0.3];
522 [o_fullscreen_anim1 setFrameRate: 30];
523 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
524 [o_fullscreen_anim2 setDuration: 0.2];
525 [o_fullscreen_anim2 setFrameRate: 30];
527 [o_fullscreen_anim2 setDelegate: self];
528 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
530 [o_fullscreen_anim1 startAnimation];
531 /* fullscreenAnimation will be unlocked when animation ends */
534 - (void)hasBecomeFullscreen
536 [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] controls] voutView]];
538 [o_fullscreen_window makeKeyWindow];
539 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
541 /* tell the fspanel to move itself to front next time it's triggered */
542 [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
545 [super orderOut: self];
547 [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
550 [self unlockFullscreenAnimation];
553 - (void)leaveFullscreen
555 [self leaveFullscreenAndFadeOut: NO];
558 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
560 NSMutableDictionary *dict1, *dict2;
563 [self lockFullscreenAnimation];
566 [o_btn_fullscreen setState: NO];
568 /* We always try to do so */
569 [NSScreen unblackoutScreens];
571 /* Don't do anything if o_fullscreen_window is already closed */
572 if (!o_fullscreen_window)
574 [self unlockFullscreenAnimation];
580 /* We don't animate if we are not visible, instead we
581 * simply fade the display */
582 CGDisplayFadeReservationToken token;
584 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
585 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
587 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
588 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
590 /* Will release the lock */
591 [self hasEndedFullscreen];
593 /* Our window is hidden, and might be faded. We need to workaround that, so note it
595 b_window_is_invisible = YES;
597 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
598 CGReleaseDisplayFadeReservation( token);
602 [self setAlphaValue: 0.0];
603 [self orderFront: self];
605 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
606 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
608 if (o_fullscreen_anim1)
610 [o_fullscreen_anim1 stopAnimation];
611 [o_fullscreen_anim1 release];
613 if (o_fullscreen_anim2)
615 [o_fullscreen_anim2 stopAnimation];
616 [o_fullscreen_anim2 release];
619 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
620 frame.origin.x += [self frame].origin.x;
621 frame.origin.y += [self frame].origin.y;
623 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
624 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
625 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
627 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
630 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
631 [o_fullscreen_anim2 setDuration: 0.3];
632 [o_fullscreen_anim2 setFrameRate: 30];
634 [o_fullscreen_anim2 setDelegate: self];
636 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
638 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
639 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
640 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
642 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
645 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
646 [o_fullscreen_anim1 setDuration: 0.2];
647 [o_fullscreen_anim1 setFrameRate: 30];
648 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
650 /* Make sure o_fullscreen_window is the frontmost window */
651 [o_fullscreen_window orderFront: self];
653 [o_fullscreen_anim1 startAnimation];
654 /* fullscreenAnimation will be unlocked when animation ends */
657 - (void)hasEndedFullscreen
659 /* This function is private and should be only triggered at the end of the fullscreen change animation */
660 /* Make sure we don't see the o_view disappearing of the screen during this operation */
661 NSDisableScreenUpdates();
663 [o_view removeFromSuperviewWithoutNeedingDisplay];
664 [[o_temp_view superview] replaceSubview:o_temp_view with:o_view];
666 [o_view setFrame:[o_temp_view frame]];
667 [self makeFirstResponder: o_view];
668 if ([self isVisible])
669 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
670 [o_fullscreen_window orderOut: self];
671 NSEnableScreenUpdates();
673 [o_fullscreen_window release];
674 o_fullscreen_window = nil;
675 [self setLevel:originalLevel];
677 [self unlockFullscreenAnimation];
680 - (void)animationDidEnd:(NSAnimation*)animation
682 NSArray *viewAnimations;
683 if( o_makekey_anim == animation )
685 [o_makekey_anim release];
688 if ([animation currentValue] < 1.0)
691 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
692 viewAnimations = [o_fullscreen_anim2 viewAnimations];
693 if ([viewAnimations count] >=1 &&
694 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
696 /* Fullscreen ended */
697 [self hasEndedFullscreen];
701 /* Fullscreen started */
702 [self hasBecomeFullscreen];
706 - (void)orderOut: (id)sender
708 [super orderOut: sender];
710 /* Make sure we leave fullscreen */
711 [self leaveFullscreenAndFadeOut: YES];
714 - (void)makeKeyAndOrderFront: (id)sender
717 * when we exit fullscreen and fade out, we may endup in
718 * having a window that is faded. We can't have it fade in unless we
721 if(!b_window_is_invisible)
723 /* Make sure we don't do it too much */
724 [super makeKeyAndOrderFront: sender];
728 [super setAlphaValue:0.0f];
729 [super makeKeyAndOrderFront: sender];
731 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
732 [dict setObject:self forKey:NSViewAnimationTargetKey];
733 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
735 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
738 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
739 [o_makekey_anim setDuration: 0.1];
740 [o_makekey_anim setFrameRate: 30];
741 [o_makekey_anim setDelegate: self];
743 [o_makekey_anim startAnimation];
744 b_window_is_invisible = NO;
746 /* fullscreenAnimation will be unlocked when animation ends */
751 /* Make sure setFrame gets executed on main thread especially if we are animating.
752 * (Thus we won't block the video output thread) */
753 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
755 struct { NSRect frame; BOOL display; BOOL animate;} args;
759 args.display = display;
760 args.animate = animate;
762 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
764 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
765 withObject: packedargs waitUntilDone: YES];
768 - (void)setFrameOnMainThread:(NSData*)packedargs
770 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
774 /* Make sure we don't block too long and set up a non blocking animation */
775 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
776 self, NSViewAnimationTargetKey,
777 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
778 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
780 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
783 [anim setAnimationBlockingMode: NSAnimationNonblocking];
784 [anim setDuration: 0.4];
785 [anim setFrameRate: 30];
786 [anim startAnimation];
789 [super setFrame:args->frame display:args->display animate:args->animate];
795 /*****************************************************************************
797 *****************************************************************************/
800 @implementation embeddedbackground
804 [self unregisterDraggedTypes];
810 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
811 NSFilenamesPboardType, nil]];
812 [self addSubview: o_timeslider];
813 [self addSubview: o_scrollfield];
814 [self addSubview: o_time];
815 [self addSubview: o_main_pgbar];
816 [self addSubview: o_btn_backward];
817 [self addSubview: o_btn_forward];
818 [self addSubview: o_btn_fullscreen];
819 [self addSubview: o_btn_equalizer];
820 [self addSubview: o_btn_playlist];
821 [self addSubview: o_btn_play];
822 [self addSubview: o_btn_prev];
823 [self addSubview: o_btn_stop];
824 [self addSubview: o_btn_next];
825 [self addSubview: o_btn_volume_down];
826 [self addSubview: o_volumeslider];
827 [self addSubview: o_btn_volume_up];
828 [self addSubview: o_searchfield];
831 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
833 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
834 == NSDragOperationGeneric)
836 return NSDragOperationGeneric;
840 return NSDragOperationNone;
844 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
849 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
851 NSPasteboard *o_paste = [sender draggingPasteboard];
852 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
853 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
854 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
855 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
859 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
862 NSArray *o_array = [NSArray array];
863 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
864 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
866 for( i = 0; i < (int)[o_values count]; i++)
869 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
870 o_array = [o_array arrayByAddingObject: o_dic];
873 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
875 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
879 [self setNeedsDisplay:YES];
883 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
885 [self setNeedsDisplay:YES];
888 - (void)drawRect:(NSRect)rect
890 NSImage *leftImage = [NSImage imageNamed:@"display_left"];
891 NSImage *middleImage = [NSImage imageNamed:@"display_middle"];
892 NSImage *rightImage = [NSImage imageNamed:@"display_right"];
893 [middleImage setSize:NSMakeSize(NSWidth( [self bounds] ) - 134 - [leftImage size].width - [rightImage size].width, [middleImage size].height)];
894 [middleImage setScalesWhenResized:YES];
895 [leftImage compositeToPoint:NSMakePoint( 122., 40. ) operation:NSCompositeSourceOver];
896 [middleImage compositeToPoint:NSMakePoint( 122. + [leftImage size].width, 40. ) operation:NSCompositeSourceOver];
897 [rightImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - 12 - [rightImage size].width, 40. ) operation:NSCompositeSourceOver];
900 - (void)mouseDown:(NSEvent *)event
902 dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
905 - (void)mouseDragged:(NSEvent *)event
907 NSPoint dragLocation = [self convertPoint:[event locationInWindow] fromView:nil];
908 NSPoint winOrigin = [o_window frame].origin;
910 NSPoint newOrigin = NSMakePoint(winOrigin.x + (dragLocation.x - dragStart.x),
911 winOrigin.y + (dragLocation.y - dragStart.y));
912 [o_window setFrameOrigin: newOrigin];
917 /*****************************************************************************
919 *****************************************************************************/
922 @implementation statusbar
925 [self addSubview: o_text];
929 - (void)resignMainWindow
935 - (void)becomeMainWindow
941 - (void)drawRect:(NSRect)rect
944 [[NSColor colorWithCalibratedRed:0.820
949 [[NSColor colorWithCalibratedWhite:0.91 alpha:1.0] set];
951 /*NSRect divider = rect;
952 divider.origin.y += divider.size.height - 1;
953 divider.size.height = 1;
954 [[NSColor colorWithCalibratedWhite:0.65 alpha:1.] set];
955 NSRectFill(divider);*/