bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / grfshex.cxx
blob1c7ea14300cacd03f8acc888e0aedc15a31104bd
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 <docary.hxx>
21 #include <grfsh.hxx>
22 #include <wrtsh.hxx>
23 #include <view.hxx>
24 #include <textsh.hxx>
25 #include <viewopt.hxx>
26 #include <swundo.hxx>
27 #include <shells.hrc>
28 #include <caption.hxx>
29 #include <vcl/graphicfilter.hxx>
30 #include <sfx2/htmlmode.hxx>
31 #include <doc.hxx>
32 #include <docsh.hxx>
33 #include <frmfmt.hxx>
34 #include <frmmgr.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svx/svdomedia.hxx>
37 #include <svx/svdview.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <SwStyleNameMapper.hxx>
40 #include <sfx2/filedlghelper.hxx>
41 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
42 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
43 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
44 #include <poolfmt.hrc>
46 #include <sfx2/request.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <svl/stritem.hxx>
49 #include <avmedia/mediawindow.hxx>
50 #include <vcl/svapp.hxx>
52 // -> #111827#
53 #include <SwRewriter.hxx>
54 #include <comcore.hrc>
55 // <- #111827#
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::ui::dialogs;
60 using namespace ::sfx2;
62 bool SwTextShell::InsertMediaDlg( SfxRequest& rReq )
64 OUString aURL;
65 const SfxItemSet* pReqArgs = rReq.GetArgs();
66 Window* pWindow = &GetView().GetViewFrame()->GetWindow();
67 bool bAPI = false, bRet = false;
69 if( pReqArgs )
71 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
73 if( pStringItem )
75 aURL = pStringItem->GetValue();
76 bAPI = !aURL.isEmpty();
80 bool bLink(true);
81 if (bAPI ||
82 ::avmedia::MediaWindow::executeMediaURLDialog(pWindow, aURL, & bLink))
84 Size aPrefSize;
86 if( pWindow )
87 pWindow->EnterWait();
89 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
91 if( pWindow )
92 pWindow->LeaveWait();
94 if( !bAPI )
95 ::avmedia::MediaWindow::executeFormatErrorBox( pWindow );
97 else
99 SwWrtShell& rSh = GetShell();
101 if( !rSh.HasDrawView() )
102 rSh.MakeDrawView();
104 Size aDocSz( rSh.GetDocSize() );
105 const SwRect& rVisArea = rSh.VisArea();
106 Point aPos( rVisArea.Center() );
107 Size aSize;
109 if( rVisArea.Width() > aDocSz.Width())
110 aPos.X() = aDocSz.Width() / 2 + rVisArea.Left();
112 if(rVisArea.Height() > aDocSz.Height())
113 aPos.Y() = aDocSz.Height() / 2 + rVisArea.Top();
115 if( aPrefSize.Width() && aPrefSize.Height() )
117 if( pWindow )
118 aSize = pWindow->PixelToLogic( aPrefSize, MAP_TWIP );
119 else
120 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP );
122 else
123 aSize = Size( 2835, 2835 );
125 OUString realURL;
126 if (bLink)
128 realURL = aURL;
130 else
132 uno::Reference<frame::XModel> const xModel(
133 rSh.GetDoc()->GetDocShell()->GetModel());
134 bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL);
135 if (!bRet) { return bRet; }
138 SdrMediaObj* pObj = new SdrMediaObj( Rectangle( aPos, aSize ) );
140 pObj->SetModel(rSh.GetDoc()->GetDrawModel()); // set before setURL
141 pObj->setURL( realURL );
142 rSh.EnterStdMode();
143 rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
144 bRet = true;
146 if( pWindow )
147 pWindow->LeaveWait();
151 return bRet;
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */