1 /*****************************************************************************
2 * VLCVideoView.h: VLC.framework VLCVideoView implementation
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.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 #import "VLCVideoView.h"
26 #import "VLCLibrary.h"
27 #import "VLCEventManager.h"
28 #import "VLCVideoCommon.h"
36 #include <vlc/libvlc.h>
38 #import <QuartzCore/QuartzCore.h>
40 /******************************************************************************
41 * Soon deprecated stuff
44 /* This is a forward reference to VLCOpenGLVoutView specified in minimal_macosx
45 library. We could get rid of this, but it prevents warnings from the
46 compiler. (Scheduled to deletion) */
47 @interface VLCOpenGLVoutView : NSView
48 - (void)detachFromVout;
51 /* Depreacted methods */
52 @interface VLCVideoView (Deprecated)
53 - (void)setStretchesVideo:(BOOL)value;
54 - (BOOL)stretchesVideo;
56 - (void)addVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
57 - (void)removeVoutSubview:(NSView *)aView; /* (Scheduled to deletion) */
60 /******************************************************************************
61 * VLCVideoView (Private)
64 @interface VLCVideoView (Private)
66 - (void)addVoutLayer:(CALayer *)aLayer;
69 @interface VLCVideoView ()
70 @property (readwrite) BOOL hasVideo;
73 /******************************************************************************
74 * Implementation VLCVideoView
77 @implementation VLCVideoView
79 - (id)initWithFrame:(NSRect)rect
81 if (self = [super initWithFrame:rect])
84 [self setBackColor:[NSColor blackColor]];
85 [self setStretchesVideo:NO];
86 [self setAutoresizesSubviews:YES];
87 [self setFillScreen: NO];
89 layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
96 [layoutManager release];
102 - (void)drawRect:(NSRect)aRect
115 @synthesize delegate;
116 @synthesize backColor;
117 @synthesize hasVideo;
121 return [layoutManager fillScreenEntirely];
124 - (void)setFillScreen:(BOOL)fillScreen
126 [layoutManager setFillScreenEntirely:fillScreen];
127 [[self layer] setNeedsLayout];
131 /******************************************************************************
132 * Implementation VLCVideoView (Private)
135 @implementation VLCVideoView (Private)
137 /* This is called by the libvlc module 'opengllayer' as soon as there is one
140 - (void)addVoutLayer:(CALayer *)aLayer
142 [CATransaction begin];
143 [self setWantsLayer: YES];
144 CALayer * rootLayer = [self layer];
146 aLayer.name = @"vlcopengllayer";
148 [layoutManager setOriginalVideoSize:aLayer.bounds.size];
149 [rootLayer setLayoutManager:layoutManager];
150 [rootLayer insertSublayer:aLayer atIndex:0];
152 [aLayer setNeedsLayout];
153 [aLayer setNeedsDisplay];
155 [rootLayer setNeedsDisplayOnBoundsChange:YES];
156 [rootLayer setNeedsDisplay];
157 [rootLayer layoutIfNeeded];
158 [CATransaction commit];
162 - (void)removeVoutLayer:(CALayer*)voutLayer
164 [CATransaction begin];
165 [voutLayer removeFromSuperlayer];
166 [CATransaction commit];
172 /******************************************************************************
173 * Implementation VLCVideoView (Deprecated)
176 @implementation VLCVideoView (Deprecated)
178 - (void)setStretchesVideo:(BOOL)value
180 stretchesVideo = value;
183 - (BOOL)stretchesVideo
185 return stretchesVideo;
188 /* This is called by the libvlc module 'minimal_macosx' as soon as there is one
191 - (void)addVoutSubview:(NSView *)aView /* (Scheduled to deletion) */
193 /* This is where the real video comes from */
194 if( [[self subviews] count] )
196 /* XXX: This is a hack until core gets fixed */
198 for( i = 0; i < [[self subviews] count]; i++ )
200 [[[self subviews] objectAtIndex:i] detachFromVout];
201 [[[self subviews] objectAtIndex:i] retain];
202 [[[self subviews] objectAtIndex:i] removeFromSuperview];
206 [aView setFrame:[self bounds]];
208 [self addSubview:aView];
210 // TODO: Should we let the media player specify these values?
211 [aView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
214 - (void)removeVoutSubview:(NSView *)view /* (Scheduled to deletion) */
216 // Should we do something? I don't know, however the protocol requires
217 // this to be implemented