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 #include <sfx2/filedlghelper.hxx>
29 
30 #include <sfx2/request.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <svl/stritem.hxx>
33 #include <avmedia/mediawindow.hxx>
34 
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::ui::dialogs;
38 using namespace ::sfx2;
39 
41 {
42  OUString aURL;
43  const SfxItemSet* pReqArgs = rReq.GetArgs();
44  vcl::Window& rWindow = GetView().GetViewFrame()->GetWindow();
45  bool bAPI = false, bRet = false;
46 
47  if( pReqArgs )
48  {
49  const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
50  if( pStringItem )
51  {
52  aURL = pStringItem->GetValue();
53  bAPI = !aURL.isEmpty();
54  }
55  }
56 
57  bool bLink(true);
58  if (bAPI || ::avmedia::MediaWindow::executeMediaURLDialog(rWindow.GetFrameWeld(), aURL, & bLink))
59  {
60  Size aPrefSize;
61 
62  rWindow.EnterWait();
63 
64  if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
65  {
66  rWindow.LeaveWait();
67 
68  if( !bAPI )
70  }
71  else
72  {
73  SwWrtShell& rSh = GetShell();
74 
75  if( !rSh.HasDrawView() )
76  rSh.MakeDrawView();
77 
78  Size aDocSz( rSh.GetDocSize() );
79  const SwRect& rVisArea = rSh.VisArea();
80  Point aPos( rVisArea.Center() );
81  Size aSize;
82 
83  if( rVisArea.Width() > aDocSz.Width())
84  aPos.setX( aDocSz.Width() / 2 + rVisArea.Left() );
85 
86  if(rVisArea.Height() > aDocSz.Height())
87  aPos.setY( aDocSz.Height() / 2 + rVisArea.Top() );
88 
89  if( aPrefSize.Width() && aPrefSize.Height() )
90  aSize = rWindow.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip));
91  else
92  aSize = Size( 2835, 2835 );
93 
94  OUString realURL;
95  if (bLink)
96  {
97  realURL = aURL;
98  }
99  else
100  {
101  uno::Reference<frame::XModel> const xModel(
102  rSh.GetDoc()->GetDocShell()->GetModel());
103  bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL);
104  if (!bRet) { return bRet; }
105  }
106 
107  SdrMediaObj* pObj = new SdrMediaObj(
109  tools::Rectangle(aPos, aSize));
110 
111  pObj->setURL( realURL, "" );
112  rSh.EnterStdMode();
113  rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
114  bRet = true;
115 
116  rWindow.LeaveWait();
117  }
118  }
119 
120  return bRet;
121 }
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
long Width() const
URL aURL
static void executeFormatErrorBox(weld::Window *pParent)
bool InsertMediaDlg(SfxRequest const &)
Definition: grfshex.cxx:40
SwView & GetView()
Definition: basesh.hxx:57
SwDocShell * GetDocShell()
Definition: doc.hxx:1348
long Height() const
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:2097
const OUString & GetValue() const
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
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
Reference< XModel > xModel
void LeaveWait()