Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / grfshex.cxx
blob45d40764525bbf5eea2da431403e264539df6f71
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 <config_features.h>
21 #include <wrtsh.hxx>
22 #include <view.hxx>
23 #include <textsh.hxx>
24 #include <drawdoc.hxx>
25 #include <doc.hxx>
26 #include <IDocumentDrawModelAccess.hxx>
27 #include <docsh.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 )
44 bool bRet = false;
46 #if !HAVE_FEATURE_AVMEDIA
47 (void) rReq;
48 #else
49 OUString aURL;
50 const SfxItemSet* pReqArgs = rReq.GetArgs();
51 vcl::Window& rWindow = GetView().GetViewFrame().GetWindow();
52 bool bAPI = false;
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;
58 if( pReqArgs )
60 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
61 if( pStringItem )
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))
72 Size aPrefSize;
74 if (!bSizeUnknown)
75 aPrefSize = pSizeItem->GetSize();
76 else
78 rWindow.EnterWait();
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);
86 }));
88 const bool bIsMediaURL = ::avmedia::MediaWindow::isMediaURL(aURL, "", true, xPlayerListener);
90 rWindow.LeaveWait();
92 if (!bIsMediaURL)
94 if( !bAPI )
95 ::avmedia::MediaWindow::executeFormatErrorBox(rWindow.GetFrameWeld());
97 return bRet;
100 return true;
103 rWindow.EnterWait();
105 SwWrtShell& rSh = GetShell();
107 if( !rSh.HasDrawView() )
108 rSh.MakeDrawView();
110 Size aDocSz( rSh.GetDocSize() );
111 const SwRect& rVisArea = rSh.VisArea();
112 Point aPos( rVisArea.Center() );
113 Size aSize;
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));
123 else
124 aSize = Size( 2835, 2835 );
126 OUString realURL;
127 if (bLink)
129 realURL = aURL;
131 else
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, "" );
144 rSh.EnterStdMode();
145 rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
146 bRet = true;
148 rWindow.LeaveWait();
150 #endif
152 return bRet;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */