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 <wrtsh.hxx>
21 #include <view.hxx>
22 #include <textsh.hxx>
23 #include <drawdoc.hxx>
24 #include <doc.hxx>
26 #include <docsh.hxx>
27 #include <svx/svdomedia.hxx>
28 
29 #include <sfx2/request.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svl/stritem.hxx>
32 #include <avmedia/mediawindow.hxx>
33 
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::ui::dialogs;
37 using namespace ::sfx2;
38 
40 {
41  OUString aURL;
42  const SfxItemSet* pReqArgs = rReq.GetArgs();
43  vcl::Window& rWindow = GetView().GetViewFrame()->GetWindow();
44  bool bAPI = false, bRet = false;
45 
46  if( pReqArgs )
47  {
48  const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
49  if( pStringItem )
50  {
51  aURL = pStringItem->GetValue();
52  bAPI = !aURL.isEmpty();
53  }
54  }
55 
56  bool bLink(true);
57  if (bAPI || ::avmedia::MediaWindow::executeMediaURLDialog(rWindow.GetFrameWeld(), aURL, & bLink))
58  {
59  Size aPrefSize;
60 
61  rWindow.EnterWait();
62 
63  if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
64  {
65  rWindow.LeaveWait();
66 
67  if( !bAPI )
69  }
70  else
71  {
72  SwWrtShell& rSh = GetShell();
73 
74  if( !rSh.HasDrawView() )
75  rSh.MakeDrawView();
76 
77  Size aDocSz( rSh.GetDocSize() );
78  const SwRect& rVisArea = rSh.VisArea();
79  Point aPos( rVisArea.Center() );
80  Size aSize;
81 
82  if( rVisArea.Width() > aDocSz.Width())
83  aPos.setX( aDocSz.Width() / 2 + rVisArea.Left() );
84 
85  if(rVisArea.Height() > aDocSz.Height())
86  aPos.setY( aDocSz.Height() / 2 + rVisArea.Top() );
87 
88  if( aPrefSize.Width() && aPrefSize.Height() )
89  aSize = rWindow.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip));
90  else
91  aSize = Size( 2835, 2835 );
92 
93  OUString realURL;
94  if (bLink)
95  {
96  realURL = aURL;
97  }
98  else
99  {
100  uno::Reference<frame::XModel> const xModel(
101  rSh.GetDoc()->GetDocShell()->GetModel());
102  bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL);
103  if (!bRet) { return bRet; }
104  }
105 
106  SdrMediaObj* pObj = new SdrMediaObj(
108  tools::Rectangle(aPos, aSize));
109 
110  pObj->setURL( realURL, "" );
111  rSh.EnterStdMode();
112  rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
113  bRet = true;
114 
115  rWindow.LeaveWait();
116  }
117  }
118 
119  return bRet;
120 }
121 
122 /* 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:39
SwView & GetView()
Definition: basesh.hxx:57
SwDocShell * GetDocShell()
Definition: doc.hxx:1350
SwWrtShell & GetShell()
Definition: basesh.cxx:2687
void EnterWait()
bool HasDrawView() const
Definition: vnew.cxx:360
void EnterStdMode()
Definition: select.cxx:550
css::uno::Reference< css::frame::XModel > GetModel() const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
const SfxItemSet * GetArgs() const
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
weld::Window * GetFrameWeld() const
vcl::Window & GetWindow() const
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
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:560
Size GetDocSize() const
Definition: viewsh.cxx:2098
const OUString & GetValue() const
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
tools::Long Width() const
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
Point PixelToLogic(const Point &rDevicePt) const
sal_uInt16 GetSlot() const
void MakeDrawView()
Definition: vnew.cxx:365
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
tools::Long Height() const
Reference< XModel > xModel
void LeaveWait()