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 <config_features.h>
24 #include <drawdoc.hxx>
26 #include <IDocumentDrawModelAccess.hxx>
28 #include <avmedia/mediawindow.hxx>
29 #include <editeng/sizeitem.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <svl/stritem.hxx>
33 #include <svx/svdomedia.hxx>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/media/XPlayer.hpp>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::ui::dialogs
;
40 using namespace ::sfx2
;
42 bool SwTextShell::InsertMediaDlg( SfxRequest
const & rReq
)
46 #if !HAVE_FEATURE_AVMEDIA
50 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
51 vcl::Window
& rWindow
= GetView().GetViewFrame().GetWindow();
54 const SvxSizeItem
* pSizeItem
= rReq
.GetArg
<SvxSizeItem
>(FN_PARAM_1
);
55 const SfxBoolItem
* pLinkItem
= rReq
.GetArg
<SfxBoolItem
>(FN_PARAM_2
);
56 const bool bSizeUnknown
= !pSizeItem
;
60 const SfxStringItem
* pStringItem
= dynamic_cast<const SfxStringItem
*>( &pReqArgs
->Get( rReq
.GetSlot() ) );
63 aURL
= pStringItem
->GetValue();
64 bAPI
= !aURL
.isEmpty();
68 bool bLink(pLinkItem
? pLinkItem
->GetValue() : true);
70 if (bAPI
|| ::avmedia::MediaWindow::executeMediaURLDialog(rWindow
.GetFrameWeld(), aURL
, & bLink
))
75 aPrefSize
= pSizeItem
->GetSize();
80 css::uno::Reference
<css::frame::XDispatchProvider
> xDispatchProvider(GetView().GetViewFrame().GetFrame().GetFrameInterface(), css::uno::UNO_QUERY
);
82 rtl::Reference
<avmedia::PlayerListener
> xPlayerListener(new avmedia::PlayerListener(
83 [xDispatchProvider
, aURL
, bLink
](const css::uno::Reference
<css::media::XPlayer
>& rPlayer
){
84 css::awt::Size aSize
= rPlayer
->getPreferredPlayerWindowSize();
85 avmedia::MediaWindow::dispatchInsertAVMedia(xDispatchProvider
, aSize
, aURL
, bLink
);
88 const bool bIsMediaURL
= ::avmedia::MediaWindow::isMediaURL(aURL
, "", true, xPlayerListener
);
95 ::avmedia::MediaWindow::executeFormatErrorBox(rWindow
.GetFrameWeld());
105 SwWrtShell
& rSh
= GetShell();
107 if( !rSh
.HasDrawView() )
110 Size
aDocSz( rSh
.GetDocSize() );
111 const SwRect
& rVisArea
= rSh
.VisArea();
112 Point
aPos( rVisArea
.Center() );
115 if( rVisArea
.Width() > aDocSz
.Width())
116 aPos
.setX( aDocSz
.Width() / 2 + rVisArea
.Left() );
118 if(rVisArea
.Height() > aDocSz
.Height())
119 aPos
.setY( aDocSz
.Height() / 2 + rVisArea
.Top() );
121 if( aPrefSize
.Width() && aPrefSize
.Height() )
122 aSize
= rWindow
.PixelToLogic(aPrefSize
, MapMode(MapUnit::MapTwip
));
124 aSize
= Size( 2835, 2835 );
133 uno::Reference
<frame::XModel
> const xModel(
134 rSh
.GetDoc()->GetDocShell()->GetModel());
135 bRet
= ::avmedia::EmbedMedia(xModel
, aURL
, realURL
);
136 if (!bRet
) { return bRet
; }
139 rtl::Reference
<SdrMediaObj
> pObj
= new SdrMediaObj(
140 *rSh
.GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(),
141 tools::Rectangle(aPos
, aSize
));
143 pObj
->setURL( realURL
, "" );
145 rSh
.SwFEShell::InsertDrawObj( *pObj
, aPos
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */