1*efeef26fSAndrew Rist /**************************************************************
2*efeef26fSAndrew Rist *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <docary.hxx>
29cdf0e10cSrcweir #include <grfsh.hxx>
30cdf0e10cSrcweir #include <wrtsh.hxx>
31cdf0e10cSrcweir #include <view.hxx>
32cdf0e10cSrcweir #include <docary.hxx>
33cdf0e10cSrcweir #include <textsh.hxx>
34cdf0e10cSrcweir #include <viewopt.hxx>
35cdf0e10cSrcweir #include <swundo.hxx>
36cdf0e10cSrcweir #include <shells.hrc>
37cdf0e10cSrcweir #include <caption.hxx>
38cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR
39cdf0e10cSrcweir #include <svl/svstdarr.hxx>
40cdf0e10cSrcweir #include <svtools/filter.hxx>
41cdf0e10cSrcweir #include <svx/htmlmode.hxx>
42cdf0e10cSrcweir #include <docsh.hxx>
43cdf0e10cSrcweir #include <frmfmt.hxx>
44cdf0e10cSrcweir #include <frmmgr.hxx>
45cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46cdf0e10cSrcweir #include <svx/svdomedia.hxx>
47cdf0e10cSrcweir #include <svx/svdview.hxx>
48cdf0e10cSrcweir #include <svx/svdpagv.hxx>
49cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
50cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
51cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
52cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
54cdf0e10cSrcweir #include <poolfmt.hrc>
55cdf0e10cSrcweir
56cdf0e10cSrcweir #include <sfx2/request.hxx>
57cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
58cdf0e10cSrcweir #include <svl/stritem.hxx>
59cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
60cdf0e10cSrcweir #include <vcl/svapp.hxx>
61cdf0e10cSrcweir
62cdf0e10cSrcweir // -> #111827#
63cdf0e10cSrcweir #include <SwRewriter.hxx>
64cdf0e10cSrcweir #include <comcore.hrc>
65cdf0e10cSrcweir // <- #111827#
66cdf0e10cSrcweir
67cdf0e10cSrcweir using namespace ::com::sun::star::uno;
68cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
69cdf0e10cSrcweir using namespace ::sfx2;
70cdf0e10cSrcweir using ::rtl::OUString;
71cdf0e10cSrcweir
InsertMediaDlg(SfxRequest & rReq)72cdf0e10cSrcweir bool SwTextShell::InsertMediaDlg( SfxRequest& rReq )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir ::rtl::OUString aURL;
75cdf0e10cSrcweir const SfxItemSet* pReqArgs = rReq.GetArgs();
76cdf0e10cSrcweir Window* pWindow = &GetView().GetViewFrame()->GetWindow();
77cdf0e10cSrcweir bool bAPI = false, bRet = false;
78cdf0e10cSrcweir
79cdf0e10cSrcweir if( pReqArgs )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
82cdf0e10cSrcweir
83cdf0e10cSrcweir if( pStringItem )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir aURL = pStringItem->GetValue();
86cdf0e10cSrcweir bAPI = aURL.getLength();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( pWindow, aURL ) )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir Size aPrefSize;
93cdf0e10cSrcweir
94cdf0e10cSrcweir if( pWindow )
95cdf0e10cSrcweir pWindow->EnterWait();
96cdf0e10cSrcweir
97cdf0e10cSrcweir if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir if( pWindow )
100cdf0e10cSrcweir pWindow->LeaveWait();
101cdf0e10cSrcweir
102cdf0e10cSrcweir if( !bAPI )
103cdf0e10cSrcweir ::avmedia::MediaWindow::executeFormatErrorBox( pWindow );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir else
106cdf0e10cSrcweir {
107cdf0e10cSrcweir SwWrtShell& rSh = GetShell();
108cdf0e10cSrcweir
109cdf0e10cSrcweir if( !rSh.HasDrawView() )
110cdf0e10cSrcweir rSh.MakeDrawView();
111cdf0e10cSrcweir
112cdf0e10cSrcweir Size aDocSz( rSh.GetDocSize() );
113cdf0e10cSrcweir const SwRect& rVisArea = rSh.VisArea();
114cdf0e10cSrcweir Point aPos( rVisArea.Center() );
115cdf0e10cSrcweir Size aSize;
116cdf0e10cSrcweir
117cdf0e10cSrcweir if( rVisArea.Width() > aDocSz.Width())
118cdf0e10cSrcweir aPos.X() = aDocSz.Width() / 2 + rVisArea.Left();
119cdf0e10cSrcweir
120cdf0e10cSrcweir if(rVisArea.Height() > aDocSz.Height())
121cdf0e10cSrcweir aPos.Y() = aDocSz.Height() / 2 + rVisArea.Top();
122cdf0e10cSrcweir
123cdf0e10cSrcweir if( aPrefSize.Width() && aPrefSize.Height() )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if( pWindow )
126cdf0e10cSrcweir aSize = pWindow->PixelToLogic( aPrefSize, MAP_TWIP );
127cdf0e10cSrcweir else
128cdf0e10cSrcweir aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir else
131cdf0e10cSrcweir aSize = Size( 2835, 2835 );
132cdf0e10cSrcweir
133cdf0e10cSrcweir SdrMediaObj* pObj = new SdrMediaObj( Rectangle( aPos, aSize ) );
134cdf0e10cSrcweir
135cdf0e10cSrcweir pObj->setURL( aURL );
136cdf0e10cSrcweir rSh.EnterStdMode();
137cdf0e10cSrcweir rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
138cdf0e10cSrcweir bRet = true;
139cdf0e10cSrcweir
140cdf0e10cSrcweir if( pWindow )
141cdf0e10cSrcweir pWindow->LeaveWait();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir return bRet;
146cdf0e10cSrcweir }
147