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 <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 <caption.hxx>
28 #include <vcl/graphicfilter.hxx>
29 #include <sfx2/htmlmode.hxx>
30 #include <drawdoc.hxx>
31 #include <doc.hxx>
32 #include <IDocumentDrawModelAccess.hxx>
33 #include <docsh.hxx>
34 #include <frmfmt.hxx>
35 #include <frmmgr.hxx>
36 #include <vcl/weld.hxx>
37 #include <svx/svdomedia.hxx>
38 #include <svx/svdview.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <SwStyleNameMapper.hxx>
41 #include <sfx2/filedlghelper.hxx>
42
43 #include <sfx2/request.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <svl/stritem.hxx>
46 #include <avmedia/mediawindow.hxx>
47 #include <vcl/svapp.hxx>
48
49 // -> #111827#
50 #include <SwRewriter.hxx>
51 // <- #111827#
52
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::ui::dialogs;
56 using namespace ::sfx2;
57
InsertMediaDlg(SfxRequest const & rReq)58 bool SwTextShell::InsertMediaDlg( SfxRequest const & rReq )
59 {
60 OUString aURL;
61 const SfxItemSet* pReqArgs = rReq.GetArgs();
62 vcl::Window& rWindow = GetView().GetViewFrame()->GetWindow();
63 bool bAPI = false, bRet = false;
64
65 if( pReqArgs )
66 {
67 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
68 if( pStringItem )
69 {
70 aURL = pStringItem->GetValue();
71 bAPI = !aURL.isEmpty();
72 }
73 }
74
75 bool bLink(true);
76 if (bAPI || ::avmedia::MediaWindow::executeMediaURLDialog(rWindow.GetFrameWeld(), aURL, & bLink))
77 {
78 Size aPrefSize;
79
80 rWindow.EnterWait();
81
82 if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
83 {
84 rWindow.LeaveWait();
85
86 if( !bAPI )
87 ::avmedia::MediaWindow::executeFormatErrorBox(rWindow.GetFrameWeld());
88 }
89 else
90 {
91 SwWrtShell& rSh = GetShell();
92
93 if( !rSh.HasDrawView() )
94 rSh.MakeDrawView();
95
96 Size aDocSz( rSh.GetDocSize() );
97 const SwRect& rVisArea = rSh.VisArea();
98 Point aPos( rVisArea.Center() );
99 Size aSize;
100
101 if( rVisArea.Width() > aDocSz.Width())
102 aPos.setX( aDocSz.Width() / 2 + rVisArea.Left() );
103
104 if(rVisArea.Height() > aDocSz.Height())
105 aPos.setY( aDocSz.Height() / 2 + rVisArea.Top() );
106
107 if( aPrefSize.Width() && aPrefSize.Height() )
108 aSize = rWindow.PixelToLogic(aPrefSize, MapMode(MapUnit::MapTwip));
109 else
110 aSize = Size( 2835, 2835 );
111
112 OUString realURL;
113 if (bLink)
114 {
115 realURL = aURL;
116 }
117 else
118 {
119 uno::Reference<frame::XModel> const xModel(
120 rSh.GetDoc()->GetDocShell()->GetModel());
121 bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL);
122 if (!bRet) { return bRet; }
123 }
124
125 SdrMediaObj* pObj = new SdrMediaObj(
126 *rSh.GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(),
127 tools::Rectangle(aPos, aSize));
128
129 pObj->setURL( realURL, "" );
130 rSh.EnterStdMode();
131 rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
132 bRet = true;
133
134 rWindow.LeaveWait();
135 }
136 }
137
138 return bRet;
139 }
140
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
142