1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <docary.hxx> 33 #include <grfsh.hxx> 34 #include <wrtsh.hxx> 35 #include <view.hxx> 36 #include <docary.hxx> 37 #include <textsh.hxx> 38 #include <viewopt.hxx> 39 #include <swundo.hxx> 40 #include <shells.hrc> 41 #include <caption.hxx> 42 #define _SVSTDARR_STRINGSSORTDTOR 43 #include <svl/svstdarr.hxx> 44 #include <svtools/filter.hxx> 45 #include <svx/htmlmode.hxx> 46 #include <docsh.hxx> 47 #include <frmfmt.hxx> 48 #include <frmmgr.hxx> 49 #include <vcl/msgbox.hxx> 50 #include <svx/svdomedia.hxx> 51 #include <svx/svdview.hxx> 52 #include <svx/svdpagv.hxx> 53 #include <SwStyleNameMapper.hxx> 54 #include <sfx2/filedlghelper.hxx> 55 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 56 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 57 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> 58 #include <poolfmt.hrc> 59 60 #include <sfx2/request.hxx> 61 #include <sfx2/viewfrm.hxx> 62 #include <svl/stritem.hxx> 63 #include <avmedia/mediawindow.hxx> 64 #include <vcl/svapp.hxx> 65 66 // -> #111827# 67 #include <SwRewriter.hxx> 68 #include <comcore.hrc> 69 // <- #111827# 70 71 using namespace ::com::sun::star::uno; 72 using namespace ::com::sun::star::ui::dialogs; 73 using namespace ::sfx2; 74 using ::rtl::OUString; 75 76 bool SwTextShell::InsertMediaDlg( SfxRequest& rReq ) 77 { 78 ::rtl::OUString aURL; 79 const SfxItemSet* pReqArgs = rReq.GetArgs(); 80 Window* pWindow = &GetView().GetViewFrame()->GetWindow(); 81 bool bAPI = false, bRet = false; 82 83 if( pReqArgs ) 84 { 85 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) ); 86 87 if( pStringItem ) 88 { 89 aURL = pStringItem->GetValue(); 90 bAPI = aURL.getLength(); 91 } 92 } 93 94 if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( pWindow, aURL ) ) 95 { 96 Size aPrefSize; 97 98 if( pWindow ) 99 pWindow->EnterWait(); 100 101 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) ) 102 { 103 if( pWindow ) 104 pWindow->LeaveWait(); 105 106 if( !bAPI ) 107 ::avmedia::MediaWindow::executeFormatErrorBox( pWindow ); 108 } 109 else 110 { 111 SwWrtShell& rSh = GetShell(); 112 113 if( !rSh.HasDrawView() ) 114 rSh.MakeDrawView(); 115 116 Size aDocSz( rSh.GetDocSize() ); 117 const SwRect& rVisArea = rSh.VisArea(); 118 Point aPos( rVisArea.Center() ); 119 Size aSize; 120 121 if( rVisArea.Width() > aDocSz.Width()) 122 aPos.X() = aDocSz.Width() / 2 + rVisArea.Left(); 123 124 if(rVisArea.Height() > aDocSz.Height()) 125 aPos.Y() = aDocSz.Height() / 2 + rVisArea.Top(); 126 127 if( aPrefSize.Width() && aPrefSize.Height() ) 128 { 129 if( pWindow ) 130 aSize = pWindow->PixelToLogic( aPrefSize, MAP_TWIP ); 131 else 132 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP ); 133 } 134 else 135 aSize = Size( 2835, 2835 ); 136 137 SdrMediaObj* pObj = new SdrMediaObj( Rectangle( aPos, aSize ) ); 138 139 pObj->setURL( aURL ); 140 rSh.EnterStdMode(); 141 rSh.SwFEShell::InsertDrawObj( *pObj, aPos ); 142 bRet = true; 143 144 if( pWindow ) 145 pWindow->LeaveWait(); 146 } 147 } 148 149 return bRet; 150 } 151