fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / avmedia / source / macavf / window.mm
blob82afa2fc425bec5c6933ecf89c0fbd0a7b9ed9a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
20 #include <com/sun/star/awt/SystemPointer.hpp>
21 #include <com/sun/star/awt/PosSize.hpp>
23 #include "window.hxx"
24 #include "player.hxx"
26 using namespace ::com::sun::star;
29 namespace avmedia { namespace macavf {
31 // ---------------
32 // - Window -
33 // ---------------
35 Window::Window( const uno::Reference< lang::XMultiServiceFactory >& i_rxMgr, Player& i_rPlayer, NSView* i_pParentView )
36 :   mxMgr( i_rxMgr )
37 ,   maListeners( maMutex )
38 ,   meZoomLevel( media::ZoomLevel_NOT_AVAILABLE )
39 ,   mrPlayer( i_rPlayer )
40 ,   mnPointerType( awt::SystemPointer::ARROW )
41 ,   mpView( i_pParentView )
42 ,   mpPlayerLayer( NULL )
44     OSL_TRACE ("Constructing an avmedia::macavf::Window");
45     if( !mpView ) // sanity check
46         return;
48     // check the media asset for video content
49     AVPlayer* pAVPlayer = mrPlayer.getAVPlayer();
50     AVAsset* pMovie = [[pAVPlayer currentItem] asset];
51     const int nVideoCount = [pMovie tracksWithMediaType:AVMediaTypeVideo].count;
52     const int nAudioCount = [pMovie tracksWithMediaType:AVMediaTypeAudio].count;
53     OSL_TRACE( "Found %d video and %d audio tracks.", nVideoCount, nAudioCount );
54     (void)nAudioCount;
55     if( nVideoCount <= 0 )
56         return;
58     // setup the AVPlayerLayer
59     [pAVPlayer retain];
60     [pAVPlayer pause];
61     mpPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:pAVPlayer];
62     [mpPlayerLayer retain];
63     NSRect viewFrame = [mpView frame];
64     [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
65     [mpPlayerLayer setHidden:YES];
66     [mpPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
67     [mpPlayerLayer addObserver:getObserver() forKeyPath:@"readyForDisplay" options:0 context:this];
69     // setup the target view
70     [mpView setWantsLayer:YES];
71     [mpView.layer addSublayer:mpPlayerLayer];
74 // ------------------------------------------------------------------------------
76 Window::~Window()
78     [mpPlayerLayer removeObserver:getObserver() forKeyPath:@"readyForDisplay"];
79     [mpPlayerLayer release];
82 // ------------------------------------------------------------------------------
84 bool Window::handleObservation( NSString* pKeyPath )
86     OSL_TRACE( "AVPlayer::handleObservation key=\"%s\"", [pKeyPath UTF8String]);
87     const BOOL bReadyForDisplay = [mpPlayerLayer isReadyForDisplay];
88     [mpPlayerLayer setHidden:!bReadyForDisplay];
89     return true;
92 // XPlayerWindow
93 // ------------------------------------------------------------------------------
95 void SAL_CALL Window::update()
96     throw (uno::RuntimeException)
99 // ------------------------------------------------------------------------------
101 sal_Bool SAL_CALL Window::setZoomLevel( media::ZoomLevel /* eZoomLevel */ )
102     throw (uno::RuntimeException)
104     return false;
107 // ------------------------------------------------------------------------------
109 media::ZoomLevel SAL_CALL Window::getZoomLevel(  )
110     throw (uno::RuntimeException)
112     return meZoomLevel;
115 // ------------------------------------------------------------------------------
117 void SAL_CALL Window::setPointerType( sal_Int32 nPointerType )
118     throw (uno::RuntimeException)
120     mnPointerType = nPointerType;
123 // XWindow
124 // ------------------------------------------------------------------------------
126 void SAL_CALL Window::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 /* Flags */ )
127     throw (uno::RuntimeException)
129     OSL_TRACE( "AVWindow::setPosSize( %dx%d%+d%+d)", (int)Width,(int)Height,(int)X,(int)Y);//######
130     if( !mpView )
131         return;
132     NSRect aRect = [mpView frame];
133     // NOTE: if( (Flags & awt::PosSize::WIDTH) )
134     aRect.size.width = Width;
135     // NOTE: if( (Flags & awt::PosSize::HEIGHT) )
136     aRect.size.height = Height;
138     [mpView setFrameSize: aRect.size];
139     NSRect viewFrame = [mpView frame];
140     [mpPlayerLayer setFrame:CGRectMake(viewFrame.origin.x, viewFrame.origin.y, viewFrame.size.width, viewFrame.size.height)];
143 // ------------------------------------------------------------------------------
145 awt::Rectangle SAL_CALL Window::getPosSize()
146     throw (uno::RuntimeException)
148     awt::Rectangle aRet;
150     NSRect aRect = [mpView frame];
151     aRet.X = aRet.Y = 0;
152     aRet.Width = aRect.size.width;
153     aRet.Height = aRect.size.height;
155     return aRet;
158 // ------------------------------------------------------------------------------
160 void SAL_CALL Window::setVisible( sal_Bool bVisible )
161     throw (uno::RuntimeException)
163     OSL_TRACE ("Window::setVisible(%d)", bVisible);
166 // ------------------------------------------------------------------------------
168 void SAL_CALL Window::setEnable( sal_Bool bEnable )
169     throw (uno::RuntimeException)
171     OSL_TRACE ("Window::setEnable(%d)", bEnable);
174 // ------------------------------------------------------------------------------
176 void SAL_CALL Window::setFocus()
177     throw (uno::RuntimeException)
179     OSL_TRACE ("Window::setFocus");
182 // ------------------------------------------------------------------------------
184 void SAL_CALL Window::addWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
185     throw (uno::RuntimeException)
187     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
190 // ------------------------------------------------------------------------------
192 void SAL_CALL Window::removeWindowListener( const uno::Reference< awt::XWindowListener >& xListener )
193     throw (uno::RuntimeException)
195     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
198 // ------------------------------------------------------------------------------
200 void SAL_CALL Window::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
201     throw (uno::RuntimeException)
203     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
206 // ------------------------------------------------------------------------------
208 void SAL_CALL Window::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
209     throw (uno::RuntimeException)
211     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
214 // ------------------------------------------------------------------------------
216 void SAL_CALL Window::addKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
217     throw (uno::RuntimeException)
219     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
222 // ------------------------------------------------------------------------------
224 void SAL_CALL Window::removeKeyListener( const uno::Reference< awt::XKeyListener >& xListener )
225     throw (uno::RuntimeException)
227     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
230 // ------------------------------------------------------------------------------
232 void SAL_CALL Window::addMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
233     throw (uno::RuntimeException)
235     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
238 // ------------------------------------------------------------------------------
240 void SAL_CALL Window::removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener )
241     throw (uno::RuntimeException)
243     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
246 // ------------------------------------------------------------------------------
248 void SAL_CALL Window::addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
249     throw (uno::RuntimeException)
251     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
254 // ------------------------------------------------------------------------------
256 void SAL_CALL Window::removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener )
257     throw (uno::RuntimeException)
259     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
262 // ------------------------------------------------------------------------------
264 void SAL_CALL Window::addPaintListener( const uno::Reference< awt::XPaintListener >& xListener )
265     throw (uno::RuntimeException)
267     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
270 // ------------------------------------------------------------------------------
272 void SAL_CALL Window::removePaintListener( const uno::Reference< awt::XPaintListener >& xListener )
273     throw (uno::RuntimeException)
275     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
279 // XComponent
280 // ------------------------------------------------------------------------------
282 void SAL_CALL Window::dispose(  )
283     throw (uno::RuntimeException)
287 // ------------------------------------------------------------------------------
289 void SAL_CALL Window::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
290     throw (uno::RuntimeException)
292     maListeners.addInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
295 // ------------------------------------------------------------------------------
297 void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
298     throw (uno::RuntimeException)
300     maListeners.removeInterface( cppu::UnoType<decltype(xListener)>::get(), xListener );
303 // XServiceInfo
304 // ------------------------------------------------------------------------------
306 ::rtl::OUString SAL_CALL Window::getImplementationName(  )
307     throw (uno::RuntimeException)
309     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( AVMEDIA_MACAVF_WINDOW_IMPLEMENTATIONNAME ) );
312 // ------------------------------------------------------------------------------
314 sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
315     throw (uno::RuntimeException)
317     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) );
320 // ------------------------------------------------------------------------------
322 uno::Sequence< ::rtl::OUString > SAL_CALL Window::getSupportedServiceNames(  )
323     throw (uno::RuntimeException)
325     uno::Sequence< ::rtl::OUString > aRet(1);
326     aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) );
328     return aRet;
331 } // namespace macavf
332 } // namespace avmedia
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */