Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / grfshex.cxx
blobbb6d1bedbf9eab94e484dc27c626b67d05d6e0ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grfshex.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <docary.hxx>
36 #ifndef _GRFSH_HXX
37 #include <grfsh.hxx>
38 #endif
39 #include <wrtsh.hxx>
40 #ifndef _VIEW_HXX
41 #include <view.hxx>
42 #endif
43 #include <docary.hxx>
44 #ifndef _TEXTSH_HXX
45 #include <textsh.hxx>
46 #endif
47 #include <viewopt.hxx>
48 #include <swundo.hxx>
49 #ifndef _SHELLS_HRC
50 #include <shells.hrc>
51 #endif
52 #include <caption.hxx>
53 #define _SVSTDARR_STRINGSSORTDTOR
54 #include <svtools/svstdarr.hxx>
55 #include <svtools/filter.hxx>
56 #include <svx/impgrf.hxx>
57 #include <svx/htmlmode.hxx>
58 #ifndef _DOCSH_HXX
59 #include <docsh.hxx>
60 #endif
61 #include <frmfmt.hxx>
62 #include <frmmgr.hxx>
63 #include <vcl/msgbox.hxx>
64 #ifndef _SVX_SVDOMEDIA_HXX
65 #include <svx/svdomedia.hxx>
66 #endif
67 #ifndef _SVX_SVDVIEW_HXX
68 #include <svx/svdview.hxx>
69 #endif
70 #ifndef _SVX_SVDPAGV_HXX
71 #include <svx/svdpagv.hxx>
72 #endif
73 #include <SwStyleNameMapper.hxx>
74 #include <sfx2/filedlghelper.hxx>
75 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
76 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
77 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
78 #ifndef _POOLFMT_HRC
79 #include <poolfmt.hrc>
80 #endif
82 #include <sfx2/request.hxx>
83 #include <sfx2/viewfrm.hxx>
84 #include <svtools/stritem.hxx>
85 #include <avmedia/mediawindow.hxx>
86 #include <vcl/svapp.hxx>
88 // -> #111827#
89 #include <SwRewriter.hxx>
90 #include <undobj.hxx>
91 #include <comcore.hrc>
92 // <- #111827#
94 using namespace ::com::sun::star::uno;
95 using namespace ::com::sun::star::ui::dialogs;
96 using namespace ::sfx2;
97 using ::rtl::OUString;
99 bool SwTextShell::InsertMediaDlg( SfxRequest& rReq )
101 ::rtl::OUString aURL;
102 const SfxItemSet* pReqArgs = rReq.GetArgs();
103 Window* pWindow = &GetView().GetViewFrame()->GetWindow();
104 bool bAPI = false, bRet = false;
106 if( pReqArgs )
108 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
110 if( pStringItem )
112 aURL = pStringItem->GetValue();
113 bAPI = aURL.getLength();
117 if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( pWindow, aURL ) )
119 Size aPrefSize;
121 if( pWindow )
122 pWindow->EnterWait();
124 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
126 if( pWindow )
127 pWindow->LeaveWait();
129 if( !bAPI )
130 ::avmedia::MediaWindow::executeFormatErrorBox( pWindow );
132 else
134 SwWrtShell& rSh = GetShell();
136 if( !rSh.HasDrawView() )
137 rSh.MakeDrawView();
139 Size aDocSz( rSh.GetDocSize() );
140 const SwRect& rVisArea = rSh.VisArea();
141 Point aPos( rVisArea.Center() );
142 Size aSize;
144 if( rVisArea.Width() > aDocSz.Width())
145 aPos.X() = aDocSz.Width() / 2 + rVisArea.Left();
147 if(rVisArea.Height() > aDocSz.Height())
148 aPos.Y() = aDocSz.Height() / 2 + rVisArea.Top();
150 if( aPrefSize.Width() && aPrefSize.Height() )
152 if( pWindow )
153 aSize = pWindow->PixelToLogic( aPrefSize, MAP_TWIP );
154 else
155 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP );
157 else
158 aSize = Size( 2835, 2835 );
160 SdrMediaObj* pObj = new SdrMediaObj( Rectangle( aPos, aSize ) );
162 pObj->setURL( aURL );
163 rSh.EnterStdMode();
164 rSh.SwFEShell::Insert( *pObj, 0, 0, &aPos );
165 bRet = true;
167 if( pWindow )
168 pWindow->LeaveWait();
172 return bRet;