fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / avmedia / source / viewer / mediawindow.cxx
blob6e7934890e8cde9514d04cd118409e09917dc919
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <avmedia/mediawindow.hxx>
21 #include "mediawindow_impl.hxx"
22 #include "mediamisc.hxx"
23 #include "mediawindow.hrc"
24 #include <tools/urlobj.hxx>
25 #include <vcl/layout.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/media/XManager.hpp>
31 #include "com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp"
32 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
33 #include "com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp"
34 #include <memory>
36 #define AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME 3.0
38 using namespace ::com::sun::star;
40 namespace avmedia {
43 // - MediaWindow -
46 MediaWindow::MediaWindow( vcl::Window* parent, bool bInternalMediaControl ) :
47 mpImpl( VclPtr<priv::MediaWindowImpl>::Create( parent, this, bInternalMediaControl ) )
49 mpImpl->Show();
54 MediaWindow::~MediaWindow()
56 mpImpl.disposeAndClear();
61 void MediaWindow::setURL( const OUString& rURL, const OUString& rReferer )
63 mpImpl->setURL( rURL, OUString(), rReferer );
68 const OUString& MediaWindow::getURL() const
70 return mpImpl->getURL();
75 bool MediaWindow::isValid() const
77 return mpImpl->isValid();
82 void MediaWindow::MouseMove( const MouseEvent& /* rMEvt */ )
88 void MediaWindow::MouseButtonDown( const MouseEvent& /* rMEvt */ )
94 void MediaWindow::MouseButtonUp( const MouseEvent& /* rMEvt */ )
100 void MediaWindow::KeyInput( const KeyEvent& /* rKEvt */ )
106 void MediaWindow::KeyUp( const KeyEvent& /* rKEvt */ )
112 void MediaWindow::Command( const CommandEvent& /* rCEvt */ )
118 sal_Int8 MediaWindow::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
120 return 0;
125 sal_Int8 MediaWindow::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
127 return 0;
132 void MediaWindow::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
138 Size MediaWindow::getPreferredSize() const
140 return mpImpl->getPreferredSize();
145 void MediaWindow::setPosSize( const Rectangle& rNewRect )
147 mpImpl->setPosSize( rNewRect );
152 void MediaWindow::setPointer( const Pointer& rPointer )
154 mpImpl->setPointer( rPointer );
159 bool MediaWindow::start()
161 return mpImpl->start();
166 void MediaWindow::updateMediaItem( MediaItem& rItem ) const
168 mpImpl->updateMediaItem( rItem );
173 void MediaWindow::executeMediaItem( const MediaItem& rItem )
175 mpImpl->executeMediaItem( rItem );
180 void MediaWindow::show()
182 mpImpl->Show();
187 void MediaWindow::hide()
189 mpImpl->Hide();
194 vcl::Window* MediaWindow::getWindow() const
196 return mpImpl.get();
201 void MediaWindow::getMediaFilters( FilterNameVector& rFilterNameVector )
203 static const char* pFilters[] = { "Advanced Audio Coding", "aac",
204 "AIF Audio", "aif;aiff",
205 "Advanced Systems Format", "asf;wma;wmv",
206 "AU Audio", "au",
207 "AC3 Audio", "ac3",
208 "AVI", "avi",
209 "CD Audio", "cda",
210 "Digital Video", "dv",
211 "FLAC Audio", "flac",
212 "Flash Video", "flv",
213 "Matroska Media", "mkv",
214 "MIDI Audio", "mid;midi",
215 "MPEG Audio", "mp2;mp3;mpa;m4a",
216 "MPEG Video", "mpg;mpeg;mpv;mp4;m4v",
217 "Ogg Audio", "ogg;oga;opus",
218 "Ogg Video", "ogv;ogx",
219 "Real Audio", "ra",
220 "Real Media", "rm",
221 "RMI MIDI Audio", "rmi",
222 "SND (SouND) Audio", "snd",
223 "Quicktime Video", "mov",
224 "Vivo Video", "viv",
225 "WAVE Audio", "wav",
226 "WebM Video", "webm",
227 "Windows Media Audio", "wma",
228 "Windows Media Video", "wmv"};
230 for( size_t i = 0; i < SAL_N_ELEMENTS(pFilters); i += 2 )
232 rFilterNameVector.push_back( ::std::make_pair< OUString, OUString >(
233 OUString::createFromAscii(pFilters[i]),
234 OUString::createFromAscii(pFilters[i+1]) ) );
240 bool MediaWindow::executeMediaURLDialog(vcl::Window* /* pParent */,
241 OUString& rURL, bool *const o_pbLink)
243 ::sfx2::FileDialogHelper aDlg( (o_pbLink)
244 ? ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW
245 : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
246 static const char aWildcard[] = "*.";
247 FilterNameVector aFilters;
248 static const char aSeparator[] = ";";
249 OUString aAllTypes;
251 aDlg.SetTitle( AVMEDIA_RESSTR( (o_pbLink)
252 ? AVMEDIA_STR_INSERTMEDIA_DLG : AVMEDIA_STR_OPENMEDIA_DLG ) );
254 getMediaFilters( aFilters );
256 unsigned int i;
257 for( i = 0; i < aFilters.size(); ++i )
259 for( sal_Int32 nIndex = 0; nIndex >= 0; )
261 if( !aAllTypes.isEmpty() )
262 aAllTypes += aSeparator;
264 ( aAllTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
268 // add filter for all media types
269 aDlg.AddFilter( AVMEDIA_RESSTR( AVMEDIA_STR_ALL_MEDIAFILES ), aAllTypes );
271 for( i = 0; i < aFilters.size(); ++i )
273 OUString aTypes;
275 for( sal_Int32 nIndex = 0; nIndex >= 0; )
277 if( !aTypes.isEmpty() )
278 aTypes += aSeparator;
280 ( aTypes += aWildcard ) += aFilters[ i ].second.getToken( 0, ';', nIndex );
283 // add single filters
284 aDlg.AddFilter( aFilters[ i ].first, aTypes );
287 // add filter for all types
288 aDlg.AddFilter( AVMEDIA_RESSTR( AVMEDIA_STR_ALL_FILES ), OUString( "*.*" ) );
290 uno::Reference<ui::dialogs::XFilePicker> const xFP(aDlg.GetFilePicker());
291 uno::Reference<ui::dialogs::XFilePickerControlAccess> const xCtrlAcc(xFP,
292 uno::UNO_QUERY_THROW);
293 if (o_pbLink)
295 // for video link should be the default
296 xCtrlAcc->setValue(
297 ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0,
298 uno::makeAny(true) );
299 // disabled for now: TODO: preview?
300 xCtrlAcc->enableControl(
301 ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW,
302 false);
305 if( aDlg.Execute() == ERRCODE_NONE )
307 const INetURLObject aURL( aDlg.GetPath() );
308 rURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
310 if (o_pbLink)
312 uno::Any const any = xCtrlAcc->getValue(
313 ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
314 if (!(any >>= *o_pbLink))
316 SAL_WARN("avmedia", "invalid link property");
317 *o_pbLink = true;
321 else if( !rURL.isEmpty() )
322 rURL.clear();
324 return !rURL.isEmpty();
329 void MediaWindow::executeFormatErrorBox( vcl::Window* pParent )
331 ScopedVclPtrInstance< MessageDialog > aErrBox( pParent, AVMEDIA_RESID( AVMEDIA_STR_ERR_URL ) );
333 aErrBox->Execute();
334 aErrBox.disposeAndClear();
339 bool MediaWindow::isMediaURL( const OUString& rURL, const OUString& rReferer, bool bDeep, Size* pPreferredSizePixel )
341 const INetURLObject aURL( rURL );
342 bool bRet = false;
344 if( aURL.GetProtocol() != INetProtocol::NotValid )
346 if( bDeep || pPreferredSizePixel )
350 uno::Reference< media::XPlayer > xPlayer( priv::MediaWindowImpl::createPlayer(
351 aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ),
352 rReferer ) );
354 if( xPlayer.is() )
356 bRet = true;
358 if( pPreferredSizePixel )
360 const awt::Size aAwtSize( xPlayer->getPreferredPlayerWindowSize() );
362 pPreferredSizePixel->Width() = aAwtSize.Width;
363 pPreferredSizePixel->Height() = aAwtSize.Height;
367 catch( ... )
371 else
373 FilterNameVector aFilters;
374 const OUString aExt( aURL.getExtension() );
376 getMediaFilters( aFilters );
378 unsigned int i;
379 for( i = 0; ( i < aFilters.size() ) && !bRet; ++i )
381 for( sal_Int32 nIndex = 0; nIndex >= 0 && !bRet; )
383 if( aExt.equalsIgnoreAsciiCase( aFilters[ i ].second.getToken( 0, ';', nIndex ) ) )
384 bRet = true;
390 return bRet;
395 uno::Reference< media::XPlayer > MediaWindow::createPlayer( const OUString& rURL, const OUString& rReferer, const OUString* pMimeType )
397 return priv::MediaWindowImpl::createPlayer( rURL, rReferer, pMimeType );
402 uno::Reference< graphic::XGraphic > MediaWindow::grabFrame( const OUString& rURL,
403 const OUString& rReferer,
404 const OUString& sMimeType,
405 double fMediaTime )
407 uno::Reference< media::XPlayer > xPlayer( createPlayer( rURL, rReferer, &sMimeType ) );
408 uno::Reference< graphic::XGraphic > xRet;
409 std::unique_ptr< Graphic > xGraphic;
411 if( xPlayer.is() )
413 uno::Reference< media::XFrameGrabber > xGrabber( xPlayer->createFrameGrabber() );
415 if( xGrabber.is() )
417 if( AVMEDIA_FRAMEGRABBER_DEFAULTFRAME == fMediaTime )
418 fMediaTime = AVMEDIA_FRAMEGRABBER_DEFAULTFRAME_MEDIATIME;
420 if( fMediaTime >= xPlayer->getDuration() )
421 fMediaTime = ( xPlayer->getDuration() * 0.5 );
423 xRet = xGrabber->grabFrame( fMediaTime );
426 if( !xRet.is() )
428 awt::Size aPrefSize( xPlayer->getPreferredPlayerWindowSize() );
430 if( !aPrefSize.Width && !aPrefSize.Height )
432 const BitmapEx aBmpEx( getAudioLogo() );
433 xGraphic.reset( new Graphic( aBmpEx ) );
438 if( !xRet.is() && !xGraphic.get() )
440 const BitmapEx aBmpEx( getEmptyLogo() );
441 xGraphic.reset( new Graphic( aBmpEx ) );
444 if( xGraphic.get() )
445 xRet = xGraphic->GetXGraphic();
447 return xRet;
450 BitmapEx MediaWindow::getAudioLogo()
452 return BitmapEx(AVMEDIA_RESID(AVMEDIA_BMP_AUDIOLOGO));
455 BitmapEx MediaWindow::getEmptyLogo()
457 return BitmapEx(AVMEDIA_RESID(AVMEDIA_BMP_EMPTYLOGO));
461 } // namespace avemdia
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */