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;
278 else if ( splitView == o_vertical_split )
279 return proposedPosition ;
281 float bottom = [splitView frame].size.height - [splitView dividerThickness];
282 if(proposedPosition > bottom - 50) {
283 [o_btn_playlist setState: NSOffState];
284 [o_searchfield setHidden:YES];
285 [o_playlist_view setHidden:YES];
289 [o_btn_playlist setState: NSOnState];
290 [o_searchfield setHidden:NO];
291 [o_playlist_view setHidden:NO];
292 [o_playlist swapPlaylists: o_playlist_table];
293 [o_vlc_main togglePlaylist:self];
294 return proposedPosition;
299 - (void)splitViewWillResizeSubviews:(NSNotification *) notification
304 - (CGFloat)splitView:(NSSplitView *) splitView constrainMinCoordinate:(CGFloat) proposedMin ofSubviewAt:(NSInteger) offset
306 if([splitView isVertical])
312 - (CGFloat)splitView:(NSSplitView *) splitView constrainMaxCoordinate:(CGFloat) proposedMax ofSubviewAt:(NSInteger) offset
314 if([splitView isVertical])
315 return MIN([self frame].size.width - 551, 300);
317 return [splitView frame].size.height;
320 - (BOOL)splitView:(NSSplitView *) splitView canCollapseSubview:(NSView *) subview
322 if([splitView isVertical])
328 - (NSRect)splitView:(NSSplitView *)splitView effectiveRect:(NSRect)proposedEffectiveRect forDrawnRect:(NSRect)drawnRect
329 ofDividerAtIndex:(NSInteger)dividerIndex
331 if([splitView isVertical]) {
332 drawnRect.origin.x -= 3;
333 drawnRect.size.width += 5;
340 - (IBAction)togglePlaylist:(id)sender
342 NSView *playback_area = [[o_vertical_split subviews] objectAtIndex:0];
343 NSView *playlist_area = [[o_vertical_split subviews] objectAtIndex:1];
344 NSRect newVid = [playback_area frame];
345 NSRect newList = [playlist_area frame];
346 if(newList.size.height < 50 && sender != self && sender != o_vlc_main) {
347 newList.size.height = newVid.size.height/2;
348 newVid.size.height = newVid.size.height/2;
349 newVid.origin.y = newVid.origin.y + newList.size.height;
350 [o_btn_playlist setState: NSOnState];
351 [o_searchfield setHidden:NO];
352 [o_playlist_view setHidden:NO];
353 [o_playlist swapPlaylists: o_playlist_table];
354 [o_vlc_main togglePlaylist:self];
357 newVid.size.height = newVid.size.height + newList.size.height;
358 newList.size.height = 0;
360 [o_btn_playlist setState: NSOffState];
361 [o_searchfield setHidden:YES];
362 [o_playlist_view setHidden:YES];
364 [playback_area setFrame: newVid];
365 [playlist_area setFrame: newList];
368 /*****************************************************************************
377 - (void)lockFullscreenAnimation
379 [o_animation_lock lock];
382 - (void)unlockFullscreenAnimation
384 [o_animation_lock unlock];
387 - (void)enterFullscreen
389 NSMutableDictionary *dict1, *dict2;
393 vout_thread_t *p_vout = getVout();
394 BOOL blackout_other_displays = config_GetInt( VLCIntf, "macosx-black" );
396 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_GetInteger( p_vout, "video-device" )];
398 [self lockFullscreenAnimation];
402 msg_Dbg( p_vout, "chosen screen isn't present, using current screen for fullscreen mode" );
403 screen = [self screen];
407 msg_Dbg( p_vout, "Using deepest screen" );
408 screen = [NSScreen deepestScreen];
411 vlc_object_release( p_vout );
413 screen_rect = [screen frame];
415 [o_btn_fullscreen setState: YES];
417 [NSCursor setHiddenUntilMouseMoves: YES];
419 if( blackout_other_displays )
420 [screen blackoutOtherScreens];
422 /* Make sure we don't see the window flashes in float-on-top mode */
423 originalLevel = [self level];
424 [self setLevel:NSNormalWindowLevel];
426 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
427 if (!o_fullscreen_window)
429 /* We can't change the styleMask of an already created NSWindow, so we create an other window, and do eye catching stuff */
431 rect = [[o_view superview] convertRect: [o_view frame] toView: nil]; /* Convert to Window base coord */
432 rect.origin.x += [self frame].origin.x;
433 rect.origin.y += [self frame].origin.y;
434 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
435 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
436 [o_fullscreen_window setCanBecomeKeyWindow: YES];
438 if (![self isVisible] || [self alphaValue] == 0.0)
440 /* We don't animate if we are not visible, instead we
441 * simply fade the display */
442 CGDisplayFadeReservationToken token;
444 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
445 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
447 if ([screen isMainScreen])
448 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
450 [[o_view superview] replaceSubview:o_view with:o_temp_view];
451 [o_temp_view setFrame:[o_view frame]];
452 [o_fullscreen_window setContentView:o_view];
454 [o_fullscreen_window makeKeyAndOrderFront:self];
456 [o_fullscreen_window makeKeyAndOrderFront:self];
457 [o_fullscreen_window orderFront:self animate:YES];
459 [o_fullscreen_window setFrame:screen_rect display:YES];
461 CGDisplayFade( token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
462 CGReleaseDisplayFadeReservation( token);
464 /* Will release the lock */
465 [self hasBecomeFullscreen];
470 /* Make sure we don't see the o_view disappearing of the screen during this operation */
471 NSDisableScreenUpdates();
472 [[o_view superview] replaceSubview:o_view with:o_temp_view];
473 [o_temp_view setFrame:[o_view frame]];
474 [o_fullscreen_window setContentView:o_view];
475 [o_fullscreen_window makeKeyAndOrderFront:self];
476 NSEnableScreenUpdates();
479 /* We are in fullscreen (and no animation is running) */
482 /* Make sure we are hidden */
483 [super orderOut: self];
484 [self unlockFullscreenAnimation];
488 if (o_fullscreen_anim1)
490 [o_fullscreen_anim1 stopAnimation];
491 [o_fullscreen_anim1 release];
493 if (o_fullscreen_anim2)
495 [o_fullscreen_anim2 stopAnimation];
496 [o_fullscreen_anim2 release];
499 if ([screen isMainScreen])
500 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
502 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
503 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
505 [dict1 setObject:self forKey:NSViewAnimationTargetKey];
506 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
508 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
509 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
510 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
512 /* Strategy with NSAnimation allocation:
513 - Keep at most 2 animation at a time
514 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
516 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
517 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
522 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
523 [o_fullscreen_anim1 setDuration: 0.3];
524 [o_fullscreen_anim1 setFrameRate: 30];
525 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
526 [o_fullscreen_anim2 setDuration: 0.2];
527 [o_fullscreen_anim2 setFrameRate: 30];
529 [o_fullscreen_anim2 setDelegate: self];
530 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
532 [o_fullscreen_anim1 startAnimation];
533 /* fullscreenAnimation will be unlocked when animation ends */
536 - (void)hasBecomeFullscreen
538 [o_fullscreen_window makeFirstResponder: [[[VLCMain sharedInstance] controls] voutView]];
540 [o_fullscreen_window makeKeyWindow];
541 [o_fullscreen_window setAcceptsMouseMovedEvents: TRUE];
543 /* tell the fspanel to move itself to front next time it's triggered */
544 [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
547 [super orderOut: self];
549 [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
552 [self unlockFullscreenAnimation];
555 - (void)leaveFullscreen
557 [self leaveFullscreenAndFadeOut: NO];
560 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
562 NSMutableDictionary *dict1, *dict2;
565 [self lockFullscreenAnimation];
568 [o_btn_fullscreen setState: NO];
570 /* We always try to do so */
571 [NSScreen unblackoutScreens];
573 /* Don't do anything if o_fullscreen_window is already closed */
574 if (!o_fullscreen_window)
576 [self unlockFullscreenAnimation];
582 /* We don't animate if we are not visible, instead we
583 * simply fade the display */
584 CGDisplayFadeReservationToken token;
586 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
587 CGDisplayFade( token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
589 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
590 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
592 /* Will release the lock */
593 [self hasEndedFullscreen];
595 /* Our window is hidden, and might be faded. We need to workaround that, so note it
597 b_window_is_invisible = YES;
599 CGDisplayFade( token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
600 CGReleaseDisplayFadeReservation( token);
604 [self setAlphaValue: 0.0];
605 [self orderFront: self];
607 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
608 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
610 if (o_fullscreen_anim1)
612 [o_fullscreen_anim1 stopAnimation];
613 [o_fullscreen_anim1 release];
615 if (o_fullscreen_anim2)
617 [o_fullscreen_anim2 stopAnimation];
618 [o_fullscreen_anim2 release];
621 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
622 frame.origin.x += [self frame].origin.x;
623 frame.origin.y += [self frame].origin.y;
625 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
626 [dict2 setObject:self forKey:NSViewAnimationTargetKey];
627 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
629 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
632 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
633 [o_fullscreen_anim2 setDuration: 0.3];
634 [o_fullscreen_anim2 setFrameRate: 30];
636 [o_fullscreen_anim2 setDelegate: self];
638 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
640 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
641 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
642 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
644 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
647 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
648 [o_fullscreen_anim1 setDuration: 0.2];
649 [o_fullscreen_anim1 setFrameRate: 30];
650 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
652 /* Make sure o_fullscreen_window is the frontmost window */
653 [o_fullscreen_window orderFront: self];
655 [o_fullscreen_anim1 startAnimation];
656 /* fullscreenAnimation will be unlocked when animation ends */
659 - (void)hasEndedFullscreen
661 /* This function is private and should be only triggered at the end of the fullscreen change animation */
662 /* Make sure we don't see the o_view disappearing of the screen during this operation */
663 NSDisableScreenUpdates();
665 [o_view removeFromSuperviewWithoutNeedingDisplay];
666 [[o_temp_view superview] replaceSubview:o_temp_view with:o_view];
668 [o_view setFrame:[o_temp_view frame]];
669 [self makeFirstResponder: o_view];
670 if ([self isVisible])
671 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
672 [o_fullscreen_window orderOut: self];
673 NSEnableScreenUpdates();
675 [o_fullscreen_window release];
676 o_fullscreen_window = nil;
677 [self setLevel:originalLevel];
679 [self unlockFullscreenAnimation];
682 - (void)animationDidEnd:(NSAnimation*)animation
684 NSArray *viewAnimations;
685 if( o_makekey_anim == animation )
687 [o_makekey_anim release];
690 if ([animation currentValue] < 1.0)
693 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
694 viewAnimations = [o_fullscreen_anim2 viewAnimations];
695 if ([viewAnimations count] >=1 &&
696 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect])
698 /* Fullscreen ended */
699 [self hasEndedFullscreen];
703 /* Fullscreen started */
704 [self hasBecomeFullscreen];
708 - (void)orderOut: (id)sender
710 [super orderOut: sender];
712 /* Make sure we leave fullscreen */
713 [self leaveFullscreenAndFadeOut: YES];
716 - (void)makeKeyAndOrderFront: (id)sender
719 * when we exit fullscreen and fade out, we may endup in
720 * having a window that is faded. We can't have it fade in unless we
723 if(!b_window_is_invisible)
725 /* Make sure we don't do it too much */
726 [super makeKeyAndOrderFront: sender];
730 [super setAlphaValue:0.0f];
731 [super makeKeyAndOrderFront: sender];
733 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
734 [dict setObject:self forKey:NSViewAnimationTargetKey];
735 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
737 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
740 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
741 [o_makekey_anim setDuration: 0.1];
742 [o_makekey_anim setFrameRate: 30];
743 [o_makekey_anim setDelegate: self];
745 [o_makekey_anim startAnimation];
746 b_window_is_invisible = NO;
748 /* fullscreenAnimation will be unlocked when animation ends */
753 /* Make sure setFrame gets executed on main thread especially if we are animating.
754 * (Thus we won't block the video output thread) */
755 - (void)setFrame:(NSRect)frame display:(BOOL)display animate:(BOOL)animate
757 struct { NSRect frame; BOOL display; BOOL animate;} args;
761 args.display = display;
762 args.animate = animate;
764 packedargs = [NSData dataWithBytes:&args length:sizeof(args)];
766 [self performSelectorOnMainThread:@selector(setFrameOnMainThread:)
767 withObject: packedargs waitUntilDone: YES];
770 - (void)setFrameOnMainThread:(NSData*)packedargs
772 struct args { NSRect frame; BOOL display; BOOL animate; } * args = (struct args*)[packedargs bytes];
776 /* Make sure we don't block too long and set up a non blocking animation */
777 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
778 self, NSViewAnimationTargetKey,
779 [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
780 [NSValue valueWithRect:args->frame], NSViewAnimationEndFrameKey, nil];
782 NSViewAnimation * anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
785 [anim setAnimationBlockingMode: NSAnimationNonblocking];
786 [anim setDuration: 0.4];
787 [anim setFrameRate: 30];
788 [anim startAnimation];
791 [super setFrame:args->frame display:args->display animate:args->animate];
797 /*****************************************************************************
799 *****************************************************************************/
802 @implementation embeddedbackground
806 [self unregisterDraggedTypes];
812 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
813 NSFilenamesPboardType, nil]];
814 [self addSubview: o_timeslider];
815 [self addSubview: o_scrollfield];
816 [self addSubview: o_time];
817 [self addSubview: o_main_pgbar];
818 [self addSubview: o_btn_backward];
819 [self addSubview: o_btn_forward];
820 [self addSubview: o_btn_fullscreen];
821 [self addSubview: o_btn_equalizer];
822 [self addSubview: o_btn_playlist];
823 [self addSubview: o_btn_play];
824 [self addSubview: o_btn_prev];
825 [self addSubview: o_btn_stop];
826 [self addSubview: o_btn_next];
827 [self addSubview: o_btn_volume_down];
828 [self addSubview: o_volumeslider];
829 [self addSubview: o_btn_volume_up];
830 [self addSubview: o_searchfield];
833 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
835 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
836 == NSDragOperationGeneric)
838 return NSDragOperationGeneric;
842 return NSDragOperationNone;
846 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
851 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
853 NSPasteboard *o_paste = [sender draggingPasteboard];
854 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
855 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
856 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
857 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
861 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
864 NSArray *o_array = [NSArray array];
865 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
866 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
868 for( i = 0; i < (int)[o_values count]; i++)
871 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
872 o_array = [o_array arrayByAddingObject: o_dic];
875 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
877 [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
881 [self setNeedsDisplay:YES];
885 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
887 [self setNeedsDisplay:YES];
890 - (void)drawRect:(NSRect)rect
892 NSImage *leftImage = [NSImage imageNamed:@"display_left"];
893 NSImage *middleImage = [NSImage imageNamed:@"display_middle"];
894 NSImage *rightImage = [NSImage imageNamed:@"display_right"];
895 [middleImage setSize:NSMakeSize(NSWidth( [self bounds] ) - 134 - [leftImage size].width - [rightImage size].width, [middleImage size].height)];
896 [middleImage setScalesWhenResized:YES];
897 [leftImage compositeToPoint:NSMakePoint( 122., 40. ) operation:NSCompositeSourceOver];
898 [middleImage compositeToPoint:NSMakePoint( 122. + [leftImage size].width, 40. ) operation:NSCompositeSourceOver];
899 [rightImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - 12 - [rightImage size].width, 40. ) operation:NSCompositeSourceOver];
902 - (void)mouseDown:(NSEvent *)event
904 dragStart = [self convertPoint:[event locationInWindow] fromView:nil];
907 - (void)mouseDragged:(NSEvent *)event
909 NSPoint dragLocation = [self convertPoint:[event locationInWindow] fromView:nil];
910 NSPoint winOrigin = [o_window frame].origin;
912 NSPoint newOrigin = NSMakePoint(winOrigin.x + (dragLocation.x - dragStart.x),
913 winOrigin.y + (dragLocation.y - dragStart.y));
914 [o_window setFrameOrigin: newOrigin];
919 /*****************************************************************************
921 *****************************************************************************/
924 @implementation statusbar
927 [self addSubview: o_text];
931 - (void)resignMainWindow
937 - (void)becomeMainWindow
943 - (void)drawRect:(NSRect)rect
946 [[NSColor colorWithCalibratedRed:0.820
951 [[NSColor colorWithCalibratedWhite:0.91 alpha:1.0] set];
953 /*NSRect divider = rect;
954 divider.origin.y += divider.size.height - 1;
955 divider.size.height = 1;
956 [[NSColor colorWithCalibratedWhite:0.65 alpha:1.] set];
957 NSRectFill(divider);*/