1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/awt/SystemPointer.hpp>
21 #include <com/sun/star/awt/PosSize.hpp>
26 using namespace ::com::sun::star;
29 namespace avmedia { namespace macavf {
31 Window::Window( const uno::Reference< lang::XMultiServiceFactory >& i_rxMgr, Player& i_rPlayer, NSView* i_pParentView )
33 , maListeners( maMutex )
34 , meZoomLevel( media::ZoomLevel_NOT_AVAILABLE )
35 , mrPlayer( i_rPlayer )
36 , mnPointerType( awt::SystemPointer::ARROW )
37 , mpView( i_pParentView )
38 , mpPlayerLayer( nullptr )
40 if( !mpView ) // sanity check
43 // check the media asset for video content
44 AVPlayer* pAVPlayer = mrPlayer.getAVPlayer();
45 AVAsset* pMovie = [[pAVPlayer currentItem] asset];
46 const int nVideoCount = [pMovie tracksWithMediaType:AVMediaTypeVideo].count;
47 const int nAudioCount = [pMovie tracksWithMediaType:AVMediaTypeAudio].count;
49 if( nVideoCount <= 0 )
52 // setup the AVPlayerLayer
55 mpPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:pAVPlayer];
56 [mpPlayerLayer retain];
57 NSRect viewFrame = [mpView frame];
58 [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
59 [mpPlayerLayer setHidden:YES];
60 [mpPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
61 [mpPlayerLayer addObserver:getObserver() forKeyPath:@"readyForDisplay" options:0 context:this];
63 // setup the target view
64 [mpView setWantsLayer:YES];
65 [mpView.layer addSublayer:mpPlayerLayer];
71 [mpPlayerLayer removeObserver:getObserver() forKeyPath:@"readyForDisplay"];
72 [mpPlayerLayer release];
76 bool Window::handleObservation( NSString* /*pKeyPath*/ )
78 const BOOL bReadyForDisplay = [mpPlayerLayer isReadyForDisplay];
79 [mpPlayerLayer setHidden:!bReadyForDisplay];
85 void SAL_CALL Window::update()
89 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel /* eZoomLevel */ )
95 media::ZoomLevel SAL_CALL Window::getZoomLevel( )
101 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
103 mnPointerType = nPointerType;
108 void SAL_CALL Window::setPosSize( sal_Int32 /*X*/, sal_Int32 /*Y*/, sal_Int32 Width, sal_Int32 Height, sal_Int16 /* Flags */ )
112 NSRect aRect = [mpView frame];
113 // NOTE: if( (Flags & awt::PosSize::WIDTH) )
114 aRect.size.width = Width;
115 // NOTE: if( (Flags & awt::PosSize::HEIGHT) )
116 aRect.size.height = Height;
118 [mpView setFrameSize: aRect.size];
119 NSRect viewFrame = [mpView frame];
120 [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
124 awt::Rectangle SAL_CALL Window::getPosSize()
128 NSRect aRect = [mpView frame];
130 aRet.Width = aRect.size.width;
131 aRet.Height = aRect.size.height;
137 void SAL_CALL Window::setVisible( sal_Bool /*bVisible*/ )
142 void SAL_CALL Window::setEnable( sal_Bool /*bEnable*/ )
147 void SAL_CALL Window::setFocus()
152 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
154 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
158 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
160 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
164 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
166 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
170 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
172 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
176 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
178 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
182 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
184 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
188 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
190 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
194 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
196 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
200 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
202 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
206 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
208 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
212 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
214 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
218 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
220 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
226 void SAL_CALL Window::dispose( )
231 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
233 maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
237 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
239 maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
244 ::rtl::OUString SAL_CALL Window::getImplementationName( )
246 return ::rtl::OUString( AVMEDIA_MACAVF_WINDOW_IMPLEMENTATIONNAME );
250 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
252 return ServiceName == AVMEDIA_MACAVF_WINDOW_SERVICENAME;
256 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames( )
258 return { AVMEDIA_MACAVF_WINDOW_SERVICENAME };
261 } // namespace macavf
262 } // namespace avmedia
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */