1 /*****************************************************************************
2 * VLCVideoView.m: VLCKit.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 ()
71 @property (readwrite) BOOL hasVideo;
74 /******************************************************************************
75 * Implementation VLCVideoView
78 @implementation VLCVideoView
81 - (id)initWithFrame:(NSRect)rect
83 if (self = [super initWithFrame:rect])
86 self.backColor = [NSColor blackColor];
90 [self setStretchesVideo:NO];
91 [self setAutoresizesSubviews:YES];
92 layoutManager = [[VLCVideoLayoutManager layoutManager] retain];
100 self.backColor = nil;
101 [layoutManager release];
105 /* NSView Overrides */
106 - (void)drawRect:(NSRect)aRect
120 @synthesize delegate;
121 @synthesize backColor;
122 @synthesize hasVideo;
126 return [layoutManager fillScreenEntirely];
129 - (void)setFillScreen:(BOOL)fillScreen
131 [(VLCVideoLayoutManager *)layoutManager setFillScreenEntirely:fillScreen];
132 [[self layer] setNeedsLayout];
136 /******************************************************************************
137 * Implementation VLCVideoView (Private)
140 @implementation VLCVideoView (Private)
142 /* This is called by the libvlc module 'opengllayer' as soon as there is one
145 - (void)addVoutLayer:(CALayer *)aLayer
147 [CATransaction begin];
148 [self setWantsLayer: YES];
149 CALayer * rootLayer = [self layer];
151 aLayer.name = @"vlcopengllayer";
153 [layoutManager setOriginalVideoSize:aLayer.bounds.size];
154 [rootLayer setLayoutManager:layoutManager];
155 [rootLayer insertSublayer:aLayer atIndex:0];
156 [aLayer setNeedsDisplayOnBoundsChange:YES];
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