LibreOffice Module sw (master) 1
grfshex.cxx
Go to the documentation of this file.
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 */
19
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>
27#include <docsh.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>
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::ui::dialogs;
40using namespace ::sfx2;
41
43{
44 bool bRet = false;
45
46#if !HAVE_FEATURE_AVMEDIA
47 (void) rReq;
48#else
49 OUString aURL;
50 const SfxItemSet* pReqArgs = rReq.GetArgs();
52 bool bAPI = false;
53
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;
57
58 if( pReqArgs )
59 {
60 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
61 if( pStringItem )
62 {
63 aURL = pStringItem->GetValue();
64 bAPI = !aURL.isEmpty();
65 }
66 }
67
68 bool bLink(pLinkItem ? pLinkItem->GetValue() : true);
69
71 {
72 Size aPrefSize;
73
74 if (!bSizeUnknown)
75 aPrefSize = pSizeItem->GetSize();
76 else
77 {
78 rWindow.EnterWait();
79
80 css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(GetView().GetViewFrame().GetFrame().GetFrameInterface(), css::uno::UNO_QUERY);
81
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 }));
87
88 const bool bIsMediaURL = ::avmedia::MediaWindow::isMediaURL(aURL, "", true, xPlayerListener);
89
90 rWindow.LeaveWait();
91
92 if (!bIsMediaURL)
93 {
94 if( !bAPI )
96
97 return bRet;
98 }
99
100 return true;
101 }
102
103 rWindow.EnterWait();
104
105 SwWrtShell& rSh = GetShell();
106
107 if( !rSh.HasDrawView() )
108 rSh.MakeDrawView();
109
110 Size aDocSz( rSh.GetDocSize() );
111 const SwRect& rVisArea = rSh.VisArea();
112 Point aPos( rVisArea.Center() );
113 Size aSize;
114
115 if( rVisArea.Width() > aDocSz.Width())
116 aPos.setX( aDocSz.Width() / 2 + rVisArea.Left() );
117
118 if(rVisArea.Height() > aDocSz.Height())
119 aPos.setY( aDocSz.Height() / 2 + rVisArea.Top() );
120
121 if( aPrefSize.Width() && aPrefSize.Height() )
122 aSize = rWindow.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip));
123 else
124 aSize = Size( 2835, 2835 );
125
126 OUString realURL;
127 if (bLink)
128 {
129 realURL = aURL;
130 }
131 else
132 {
133 uno::Reference<frame::XModel> const xModel(
134 rSh.GetDoc()->GetDocShell()->GetModel());
135 bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL);
136 if (!bRet) { return bRet; }
137 }
138
141 tools::Rectangle(aPos, aSize));
142
143 pObj->setURL( realURL, "" );
144 rSh.EnterStdMode();
145 rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
146 bRet = true;
147
148 rWindow.LeaveWait();
149 }
150#endif
151
152 return bRet;
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetValue() const
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void setX(tools::Long nX)
void setY(tools::Long nY)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
css::uno::Reference< css::frame::XModel3 > GetModel() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
SfxViewFrame * GetFrame() const
vcl::Window & GetWindow() const
SfxViewFrame & GetViewFrame() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Size & GetSize() const
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
SwView & GetView()
Definition: basesh.hxx:59
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:169
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
Point Center() const
Definition: swrect.hxx:338
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
void Width(tools::Long nNew)
Definition: swrect.hxx:189
bool InsertMediaDlg(SfxRequest const &)
Definition: grfshex.cxx:42
bool HasDrawView() const
Definition: vnew.cxx:371
Size GetDocSize() const
Definition: viewsh.cxx:2190
void MakeDrawView()
Definition: vnew.cxx:376
const SwRect & VisArea() const
Definition: viewsh.cxx:642
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void EnterStdMode()
Definition: select.cxx:560
static void dispatchInsertAVMedia(const css::uno::Reference< css::frame::XDispatchProvider > &, const css::awt::Size &rSize, const OUString &rURL, bool bLink)
static bool executeMediaURLDialog(weld::Window *pParent, OUString &rURL, bool *const o_pbLink)
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
static void executeFormatErrorBox(weld::Window *pParent)
void LeaveWait()
Point PixelToLogic(const Point &rDevicePt) const
void EnterWait()
weld::Window * GetFrameWeld() const
URL aURL
Reference< XModel > xModel