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