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>
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>
36 
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;
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();
51  vcl::Window& rWindow = GetView().GetViewFrame()->GetWindow();
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 
70  if (bAPI || ::avmedia::MediaWindow::executeMediaURLDialog(rWindow.GetFrameWeld(), aURL, & bLink))
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 
139  SdrMediaObj* pObj = new SdrMediaObj(
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: */
SfxViewFrame * GetViewFrame() const
URL aURL
static void executeFormatErrorBox(weld::Window *pParent)
bool InsertMediaDlg(SfxRequest const &)
Definition: grfshex.cxx:42
SwView & GetView()
Definition: basesh.hxx:59
SfxViewFrame * GetFrame() const
SwDocShell * GetDocShell()
Definition: doc.hxx:1351
SwWrtShell & GetShell()
Definition: basesh.cxx:2820
void EnterWait()
css::uno::Reference< css::frame::XModel3 > GetModel() const
bool HasDrawView() const
Definition: vnew.cxx:358
void EnterStdMode()
Definition: select.cxx:551
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
const SfxItemSet * GetArgs() const
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
constexpr tools::Long Width() const
weld::Window * GetFrameWeld() const
vcl::Window & GetWindow() const
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
static bool executeMediaURLDialog(weld::Window *pParent, OUString &rURL, bool *const o_pbLink)
void setURL(const OUString &rURL, const OUString &rReferer, const OUString &rMimeType=OUString())
const SwRect & VisArea() const
Definition: viewsh.cxx:630
Size GetDocSize() const
Definition: viewsh.cxx:2199
const OUString & GetValue() const
const T * GetArg(sal_uInt16 nSlotId) const
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
Point PixelToLogic(const Point &rDevicePt) const
sal_uInt16 GetSlot() const
void MakeDrawView()
Definition: vnew.cxx:363
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr tools::Long Height() const
Reference< XModel > xModel
void LeaveWait()
static void dispatchInsertAVMedia(const css::uno::Reference< css::frame::XDispatchProvider > &, const css::awt::Size &rSize, const OUString &rURL, bool bLink)
const Size & GetSize() const
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo