/src/libreoffice/sd/source/ui/view/sdview4.cxx
Line | Count | Source |
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 <config_features.h> |
21 | | |
22 | | #include <View.hxx> |
23 | | |
24 | | #include <comphelper/propertyvalue.hxx> |
25 | | #include <osl/diagnose.h> |
26 | | #include <osl/file.hxx> |
27 | | #include <sfx2/bindings.hxx> |
28 | | #include <sfx2/request.hxx> |
29 | | #include <sfx2/docfilt.hxx> |
30 | | #include <sfx2/fcontnr.hxx> |
31 | | #include <sfx2/docfile.hxx> |
32 | | #include <sfx2/sfxsids.hrc> |
33 | | #include <tools/stream.hxx> |
34 | | #include <vcl/gfxlink.hxx> |
35 | | #include <vcl/outdev.hxx> |
36 | | #include <vcl/pdfread.hxx> |
37 | | #include <vcl/svapp.hxx> |
38 | | #include <vcl/weld/MessageDialog.hxx> |
39 | | #include <vcl/weld/weld.hxx> |
40 | | #include <svx/svdpagv.hxx> |
41 | | #include <svx/xbtmpit.hxx> |
42 | | #include <svx/svdundo.hxx> |
43 | | #include <svx/xfillit0.hxx> |
44 | | #include <svx/svdograf.hxx> |
45 | | #include <svx/svdomedia.hxx> |
46 | | #include <svx/svdoole2.hxx> |
47 | | #include <svx/ImageMapInfo.hxx> |
48 | | #include <sfx2/app.hxx> |
49 | | #include <avmedia/mediawindow.hxx> |
50 | | #include <svtools/ehdl.hxx> |
51 | | #include <svtools/sfxecode.hxx> |
52 | | #include <svtools/embedhlp.hxx> |
53 | | #include <vcl/graphicfilter.hxx> |
54 | | #include <app.hrc> |
55 | | #include <Window.hxx> |
56 | | #include <DrawDocShell.hxx> |
57 | | #include <DrawViewShell.hxx> |
58 | | #include <fuinsfil.hxx> |
59 | | #include <drawdoc.hxx> |
60 | | #include <sdresid.hxx> |
61 | | #include <strings.hrc> |
62 | | #include <sdpage.hxx> |
63 | | #include <view/SlideSorterView.hxx> |
64 | | #include <com/sun/star/embed/XEmbedPersist.hpp> |
65 | | #include <com/sun/star/embed/Aspects.hpp> |
66 | | #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> |
67 | | #include <com/sun/star/embed/XEmbeddedObject.hpp> |
68 | | #include <com/sun/star/frame/XModel3.hpp> |
69 | | #include <com/sun/star/media/XPlayer.hpp> |
70 | | #include <svtools/soerr.hxx> |
71 | | #include <sfx2/ipclient.hxx> |
72 | | #include <tools/debug.hxx> |
73 | | #include <tools/urlobj.hxx> |
74 | | |
75 | | using namespace com::sun::star; |
76 | | |
77 | | namespace sd { |
78 | | |
79 | | /** |
80 | | * If an empty graphic object is provided, we fill it. Otherwise we fill an |
81 | | * existing object at the specified position. If there is no object at the |
82 | | * position, we create a new object and return a pointer to it. |
83 | | */ |
84 | | SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, |
85 | | const Point& rPos, SdrObject* pObj, ImageMap const * pImageMap ) |
86 | 0 | { |
87 | 0 | SdrEndTextEdit(); |
88 | 0 | mnAction = rAction; |
89 | | |
90 | | // Is there an object at the position rPos? |
91 | 0 | rtl::Reference<SdrGrafObj> pNewGrafObj; |
92 | 0 | SdrPageView* pPV = GetSdrPageView(); |
93 | 0 | SdrObject* pPickObj = pObj; |
94 | 0 | const bool bOnMaster = pPV && pPV->GetPage() && pPV->GetPage()->IsMasterPage(); |
95 | |
|
96 | 0 | if(pPV && dynamic_cast< const ::sd::slidesorter::view::SlideSorterView* >(this) != nullptr) |
97 | 0 | { |
98 | 0 | if(!pPV->GetPageRect().Contains(rPos)) |
99 | 0 | pPV = nullptr; |
100 | 0 | } |
101 | |
|
102 | 0 | if( !pPickObj && pPV ) |
103 | 0 | { |
104 | 0 | SdrPageView* pPageView = pPV; |
105 | 0 | pPickObj = PickObj(rPos, getHitTolLog(), pPageView); |
106 | 0 | } |
107 | |
|
108 | 0 | const bool bIsGraphic(dynamic_cast< const SdrGrafObj* >(pPickObj) != nullptr); |
109 | |
|
110 | 0 | if (DND_ACTION_LINK == mnAction |
111 | 0 | && pPickObj |
112 | 0 | && pPV |
113 | 0 | && (bIsGraphic || (pPickObj->IsEmptyPresObj() && !bOnMaster))) // #121603# Do not use pObj, it may be NULL |
114 | 0 | { |
115 | | // hit on SdrGrafObj with wanted new linked graphic (or PresObj placeholder hit) |
116 | 0 | if( IsUndoEnabled() ) |
117 | 0 | BegUndo(SdResId(STR_INSERTGRAPHIC)); |
118 | |
|
119 | 0 | SdPage* pPage = static_cast<SdPage*>( pPickObj->getSdrPageFromSdrObject() ); |
120 | |
|
121 | 0 | if( bIsGraphic ) |
122 | 0 | { |
123 | | // We fill the object with the Bitmap |
124 | 0 | pNewGrafObj = SdrObject::Clone(static_cast<SdrGrafObj&>(*pPickObj), pPickObj->getSdrModelFromSdrObject()); |
125 | 0 | pNewGrafObj->SetGraphic(rGraphic); |
126 | 0 | } |
127 | 0 | else |
128 | 0 | { |
129 | 0 | pNewGrafObj = new SdrGrafObj( |
130 | 0 | getSdrModelFromSdrView(), |
131 | 0 | rGraphic, |
132 | 0 | pPickObj->GetLogicRect()); |
133 | 0 | pNewGrafObj->SetEmptyPresObj(true); |
134 | 0 | } |
135 | |
|
136 | 0 | if ( pNewGrafObj->IsEmptyPresObj() ) |
137 | 0 | { |
138 | 0 | ::tools::Rectangle aRect( pNewGrafObj->GetLogicRect() ); |
139 | 0 | pNewGrafObj->AdjustToMaxRect( aRect ); |
140 | 0 | pNewGrafObj->SetOutlinerParaObject(std::nullopt); |
141 | 0 | pNewGrafObj->SetEmptyPresObj(false); |
142 | 0 | } |
143 | |
|
144 | 0 | if (pPage && pPage->IsPresObj(pPickObj)) |
145 | 0 | { |
146 | | // Insert new PresObj into the list |
147 | 0 | pPage->InsertPresObj( pNewGrafObj.get(), PresObjKind::Graphic ); |
148 | 0 | pNewGrafObj->SetUserCall(pPickObj->GetUserCall()); |
149 | 0 | } |
150 | |
|
151 | 0 | if (pImageMap) |
152 | 0 | pNewGrafObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(*pImageMap))); |
153 | |
|
154 | 0 | ReplaceObjectAtView(pPickObj, *pPV, pNewGrafObj.get()); // maybe ReplaceObjectAtView |
155 | |
|
156 | 0 | if( IsUndoEnabled() ) |
157 | 0 | EndUndo(); |
158 | 0 | } |
159 | 0 | else if (DND_ACTION_LINK == mnAction |
160 | 0 | && pPickObj |
161 | 0 | && !bIsGraphic |
162 | 0 | && pPickObj->IsClosedObj() |
163 | 0 | && !dynamic_cast< const SdrOle2Obj* >(pPickObj)) |
164 | 0 | { |
165 | | // fill style change (fill object with graphic), independent of mnAction |
166 | | // and thus of DND_ACTION_LINK or DND_ACTION_MOVE |
167 | 0 | if( IsUndoEnabled() ) |
168 | 0 | { |
169 | 0 | BegUndo(SdResId(STR_UNDO_DRAGDROP)); |
170 | 0 | AddUndo(GetModel().GetSdrUndoFactory().CreateUndoAttrObject(*pPickObj)); |
171 | 0 | EndUndo(); |
172 | 0 | } |
173 | |
|
174 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<XATTR_FILLSTYLE, XATTR_FILLBITMAP>(mpDocSh->GetPool())); |
175 | |
|
176 | 0 | aSet.Put(XFillStyleItem(drawing::FillStyle_BITMAP)); |
177 | 0 | aSet.Put(XFillBitmapItem(rGraphic)); |
178 | 0 | pPickObj->SetMergedItemSetAndBroadcast(aSet); |
179 | 0 | } |
180 | | |
181 | 0 | else if ( pPV ) |
182 | 0 | { |
183 | 0 | Size aSizePixel = rGraphic.GetSizePixel(); |
184 | | |
185 | | // create new object |
186 | 0 | Size aSize; |
187 | |
|
188 | 0 | if ( rGraphic.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel ) |
189 | 0 | { |
190 | 0 | ::OutputDevice* pOutDev = nullptr; |
191 | 0 | if( mpViewSh ) |
192 | 0 | pOutDev = mpViewSh->GetActiveWindow()->GetOutDev(); |
193 | |
|
194 | 0 | if( !pOutDev ) |
195 | 0 | pOutDev = Application::GetDefaultDevice(); |
196 | |
|
197 | 0 | if( pOutDev ) |
198 | 0 | aSize = pOutDev->PixelToLogic(rGraphic.GetPrefSize(), MapMode(MapUnit::Map100thMM)); |
199 | 0 | } |
200 | 0 | else |
201 | 0 | { |
202 | 0 | aSize = OutputDevice::LogicToLogic( rGraphic.GetPrefSize(), |
203 | 0 | rGraphic.GetPrefMapMode(), |
204 | 0 | MapMode( MapUnit::Map100thMM ) ); |
205 | 0 | } |
206 | |
|
207 | 0 | sal_Int32 nPreferredDPI = mrDoc.getImagePreferredDPI(); |
208 | |
|
209 | 0 | if (rGraphic.GetGfxLink().GetType() == GfxLinkType::NativePdf && nPreferredDPI == 0 && vcl::PDF_INSERT_MAGIC_SCALE_FACTOR > 1) |
210 | 0 | nPreferredDPI = Application::GetDefaultDevice()->GetDPIX() * vcl::PDF_INSERT_MAGIC_SCALE_FACTOR; |
211 | |
|
212 | 0 | if (nPreferredDPI > 0) |
213 | 0 | { |
214 | 0 | auto nWidth = o3tl::convert(aSizePixel.Width() / double(nPreferredDPI), o3tl::Length::in, o3tl::Length::mm100); |
215 | 0 | auto nHeight = o3tl::convert(aSizePixel.Height() / double(nPreferredDPI), o3tl::Length::in, o3tl::Length::mm100); |
216 | 0 | if (nWidth > 0 && nHeight > 0) |
217 | 0 | aSize = Size(nWidth, nHeight); |
218 | 0 | } |
219 | |
|
220 | 0 | pNewGrafObj = new SdrGrafObj(getSdrModelFromSdrView(), rGraphic, ::tools::Rectangle(rPos, aSize)); |
221 | |
|
222 | 0 | if (nPreferredDPI > 0) |
223 | 0 | { |
224 | | // move to the center of insertion point |
225 | 0 | pNewGrafObj->NbcMove(Size(-aSize.Width() / 2, -aSize.Height() / 2)); |
226 | 0 | } |
227 | 0 | else |
228 | 0 | { |
229 | 0 | SdrPage* pPage = pPV->GetPage(); |
230 | 0 | Size aPageSize( pPage->GetSize() ); |
231 | 0 | aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) ); |
232 | 0 | aPageSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) ); |
233 | 0 | pNewGrafObj->AdjustToMaxRect( ::tools::Rectangle( Point(), aPageSize ), true ); |
234 | 0 | } |
235 | |
|
236 | 0 | SdrInsertFlags nOptions = SdrInsertFlags::SETDEFLAYER; |
237 | 0 | bool bIsPresTarget = false; |
238 | |
|
239 | 0 | if ((mpViewSh |
240 | 0 | && mpViewSh->GetViewShell()!=nullptr |
241 | 0 | && mpViewSh->GetViewShell()->GetIPClient() |
242 | 0 | && mpViewSh->GetViewShell()->GetIPClient()->IsObjectInPlaceActive()) |
243 | 0 | || dynamic_cast<const ::sd::slidesorter::view::SlideSorterView* >(this)) |
244 | 0 | nOptions |= SdrInsertFlags::DONTMARK; |
245 | |
|
246 | 0 | if( ( mnAction & DND_ACTION_MOVE ) && pPickObj && (pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall()) ) |
247 | 0 | { |
248 | 0 | SdPage* pP = static_cast< SdPage* >( pPickObj->getSdrPageFromSdrObject() ); |
249 | |
|
250 | 0 | if ( pP && pP->IsMasterPage() ) |
251 | 0 | bIsPresTarget = pP->IsPresObj(pPickObj); |
252 | 0 | } |
253 | |
|
254 | 0 | if( ( mnAction & DND_ACTION_MOVE ) && pPickObj && !bIsPresTarget ) |
255 | 0 | { |
256 | | // replace object |
257 | 0 | if (pImageMap) |
258 | 0 | pNewGrafObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(*pImageMap))); |
259 | |
|
260 | 0 | ::tools::Rectangle aPickObjRect(pPickObj->GetCurrentBoundRect()); |
261 | 0 | Size aPickObjSize(aPickObjRect.GetSize()); |
262 | 0 | ::tools::Rectangle aObjRect(pNewGrafObj->GetCurrentBoundRect()); |
263 | 0 | Size aObjSize(aObjRect.GetSize()); |
264 | |
|
265 | 0 | double aScaleWidth = double(aPickObjSize.Width()) / aObjSize.Width(); |
266 | 0 | double aScaleHeight = double(aPickObjSize.Height()) / aObjSize.Height(); |
267 | 0 | pNewGrafObj->NbcResize(aObjRect.TopLeft(), aScaleWidth, aScaleHeight); |
268 | |
|
269 | 0 | Point aVec = aPickObjRect.TopLeft() - aObjRect.TopLeft(); |
270 | 0 | pNewGrafObj->NbcMove(Size(aVec.X(), aVec.Y())); |
271 | |
|
272 | 0 | const bool bUndo = IsUndoEnabled(); |
273 | |
|
274 | 0 | if( bUndo ) |
275 | 0 | BegUndo(SdResId(STR_UNDO_DRAGDROP)); |
276 | 0 | pNewGrafObj->NbcSetLayer(pPickObj->GetLayer()); |
277 | 0 | SdrPage* pP = pPV->GetPage(); |
278 | 0 | pP->InsertObject(pNewGrafObj.get()); |
279 | 0 | if( bUndo ) |
280 | 0 | { |
281 | 0 | AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoNewObject(*pNewGrafObj)); |
282 | 0 | AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoDeleteObject(*pPickObj)); |
283 | 0 | } |
284 | 0 | pP->RemoveObject(pPickObj->GetOrdNum()); |
285 | |
|
286 | 0 | if( bUndo ) |
287 | 0 | { |
288 | 0 | EndUndo(); |
289 | 0 | } |
290 | 0 | mnAction = DND_ACTION_COPY; |
291 | 0 | } |
292 | 0 | else |
293 | 0 | { |
294 | 0 | bool bSuccess = InsertObjectAtView(pNewGrafObj.get(), *pPV, nOptions); |
295 | 0 | if (!bSuccess) |
296 | 0 | pNewGrafObj = nullptr; |
297 | 0 | else if (pImageMap) |
298 | 0 | pNewGrafObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(*pImageMap))); |
299 | 0 | } |
300 | 0 | } |
301 | |
|
302 | 0 | rAction = mnAction; |
303 | |
|
304 | 0 | return pNewGrafObj.get(); |
305 | 0 | } |
306 | | |
307 | | void View::InsertMediaURL( const OUString& rMediaURL, sal_Int8& rAction, |
308 | | const Point& rPos, const Size& rSize, |
309 | | bool const bLink ) |
310 | 0 | { |
311 | 0 | OUString realURL; |
312 | 0 | if (bLink) |
313 | 0 | { |
314 | 0 | realURL = rMediaURL; |
315 | 0 | } |
316 | 0 | else |
317 | 0 | { |
318 | 0 | uno::Reference<frame::XModel> const xModel( |
319 | 0 | GetDoc().GetObjectShell()->GetModel()); |
320 | 0 | #if HAVE_FEATURE_AVMEDIA |
321 | 0 | bool const bRet = ::avmedia::EmbedMedia(xModel, rMediaURL, realURL); |
322 | 0 | if (!bRet) { return; } |
323 | | #else |
324 | | return; |
325 | | #endif |
326 | 0 | } |
327 | | |
328 | 0 | InsertMediaObj(realURL, rAction, rPos, rSize); |
329 | 0 | } |
330 | | |
331 | | SdrMediaObj* View::InsertMediaObj( const OUString& rMediaURL, sal_Int8& rAction, |
332 | | const Point& rPos, const Size& rSize ) |
333 | 0 | { |
334 | 0 | SdrEndTextEdit(); |
335 | 0 | mnAction = rAction; |
336 | |
|
337 | 0 | rtl::Reference<SdrMediaObj> pNewMediaObj; |
338 | 0 | SdrPageView* pPV = GetSdrPageView(); |
339 | 0 | SdrObject* pPickObj = GetEmptyPresentationObject( PresObjKind::Media ); |
340 | |
|
341 | 0 | if(pPV && dynamic_cast<const ::sd::slidesorter::view::SlideSorterView* >(this) ) |
342 | 0 | { |
343 | 0 | if(!pPV->GetPageRect().Contains(rPos)) |
344 | 0 | pPV = nullptr; |
345 | 0 | } |
346 | |
|
347 | 0 | if( mnAction == DND_ACTION_LINK && pPV && dynamic_cast< SdrMediaObj *>( pPickObj ) ) |
348 | 0 | { |
349 | 0 | pNewMediaObj = SdrObject::Clone(static_cast<SdrMediaObj&>(*pPickObj), pPickObj->getSdrModelFromSdrObject()); |
350 | 0 | pNewMediaObj->setURL(rMediaURL, u""_ustr/*TODO?*/); |
351 | |
|
352 | 0 | BegUndo(SdResId(STR_UNDO_DRAGDROP)); |
353 | 0 | ReplaceObjectAtView(pPickObj, *pPV, pNewMediaObj.get()); |
354 | 0 | EndUndo(); |
355 | 0 | } |
356 | 0 | else if( pPV ) |
357 | 0 | { |
358 | 0 | ::tools::Rectangle aRect( rPos, rSize ); |
359 | 0 | SdrObjUserCall* pUserCall = nullptr; |
360 | 0 | if( pPickObj ) |
361 | 0 | { |
362 | 0 | aRect = pPickObj->GetLogicRect(); |
363 | 0 | pUserCall = pPickObj->GetUserCall(); // ReplaceObjectAtView can free pPickObj |
364 | 0 | } |
365 | |
|
366 | 0 | pNewMediaObj = new SdrMediaObj( |
367 | 0 | getSdrModelFromSdrView(), |
368 | 0 | aRect); |
369 | |
|
370 | 0 | bool bIsPres = false; |
371 | 0 | if( pPickObj ) |
372 | 0 | { |
373 | 0 | SdPage* pPage = static_cast< SdPage* >(pPickObj->getSdrPageFromSdrObject()); |
374 | 0 | bIsPres = pPage && pPage->IsPresObj(pPickObj); |
375 | 0 | if( bIsPres ) |
376 | 0 | { |
377 | 0 | pPage->InsertPresObj( pNewMediaObj.get(), PresObjKind::Media ); |
378 | 0 | } |
379 | 0 | } |
380 | |
|
381 | 0 | if( pPickObj ) |
382 | 0 | ReplaceObjectAtView(pPickObj, *pPV, pNewMediaObj.get()); |
383 | 0 | else |
384 | 0 | { |
385 | 0 | if (!InsertObjectAtView(pNewMediaObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER)) |
386 | 0 | pNewMediaObj = nullptr; |
387 | 0 | } |
388 | |
|
389 | 0 | OUString referer; |
390 | 0 | DrawDocShell * sh = GetDocSh(); |
391 | 0 | if (sh != nullptr && sh->HasName()) { |
392 | 0 | referer = sh->GetMedium()->GetName(); |
393 | 0 | } |
394 | |
|
395 | 0 | if (pNewMediaObj) |
396 | 0 | { |
397 | 0 | pNewMediaObj->setURL(rMediaURL, referer); |
398 | |
|
399 | 0 | if( pPickObj ) |
400 | 0 | { |
401 | 0 | pNewMediaObj->AdjustToMaxRect( aRect ); |
402 | 0 | if( bIsPres ) |
403 | 0 | pNewMediaObj->SetUserCall( pUserCall ); |
404 | 0 | } |
405 | 0 | } |
406 | 0 | } |
407 | |
|
408 | 0 | rAction = mnAction; |
409 | |
|
410 | 0 | return pNewMediaObj.get(); |
411 | 0 | } |
412 | | |
413 | | /** |
414 | | * Timer handler for InsertFile at Drop() |
415 | | */ |
416 | | IMPL_LINK_NOARG(View, DropInsertFileHdl, Timer *, void) |
417 | 0 | { |
418 | 0 | DBG_ASSERT( mpViewSh, "sd::View::DropInsertFileHdl(), I need a view shell to work!" ); |
419 | 0 | if( !mpViewSh ) |
420 | 0 | return; |
421 | | |
422 | 0 | SfxErrorContext aEc( ERRCTX_ERROR, mpViewSh->GetFrameWeld(), RID_SO_ERRCTX ); |
423 | 0 | ErrCode nError = ERRCODE_NONE; |
424 | |
|
425 | 0 | ::std::vector< OUString >::const_iterator aIter( maDropFileVector.begin() ); |
426 | |
|
427 | 0 | while( (aIter != maDropFileVector.end()) && !nError ) |
428 | 0 | { |
429 | 0 | OUString aCurrentDropFile( *aIter ); |
430 | 0 | INetURLObject aURL( aCurrentDropFile ); |
431 | 0 | bool bHandled = false; |
432 | |
|
433 | 0 | if( aURL.GetProtocol() == INetProtocol::NotValid ) |
434 | 0 | { |
435 | 0 | OUString aURLStr; |
436 | 0 | osl::FileBase::getFileURLFromSystemPath( aCurrentDropFile, aURLStr ); |
437 | 0 | aURL = INetURLObject( aURLStr ); |
438 | 0 | } |
439 | |
|
440 | 0 | GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); |
441 | 0 | Graphic aGraphic; |
442 | |
|
443 | 0 | aCurrentDropFile = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); |
444 | |
|
445 | 0 | #if HAVE_FEATURE_AVMEDIA |
446 | 0 | if( !::avmedia::MediaWindow::isMediaURL( aCurrentDropFile, u""_ustr/*TODO?*/ ) ) |
447 | | #else |
448 | | #endif |
449 | 0 | { |
450 | 0 | if( !rGraphicFilter.ImportGraphic( aGraphic, aURL ) ) |
451 | 0 | { |
452 | 0 | sal_Int8 nTempAction = ( aIter == maDropFileVector.begin() ) ? mnAction : 0; |
453 | 0 | const bool bLink = ( ( nTempAction & DND_ACTION_LINK ) != 0 ); |
454 | 0 | SdrGrafObj* pGrafObj = InsertGraphic( aGraphic, nTempAction, maDropPos, nullptr, nullptr ); |
455 | 0 | if(pGrafObj && bLink) |
456 | 0 | { |
457 | 0 | pGrafObj->SetGraphicLink( aCurrentDropFile ); |
458 | 0 | } |
459 | | |
460 | | // return action from first inserted graphic |
461 | 0 | if( aIter == maDropFileVector.begin() ) |
462 | 0 | mnAction = nTempAction; |
463 | |
|
464 | 0 | bHandled = true; |
465 | 0 | } |
466 | 0 | if (!bHandled) |
467 | 0 | { |
468 | 0 | std::shared_ptr<const SfxFilter> pFoundFilter; |
469 | 0 | SfxMedium aSfxMedium( aCurrentDropFile, StreamMode::READ | StreamMode::SHARE_DENYNONE ); |
470 | 0 | ErrCode nErr = SfxGetpApp()->GetFilterMatcher().GuessFilter( aSfxMedium, pFoundFilter ); |
471 | |
|
472 | 0 | if( pFoundFilter && !nErr ) |
473 | 0 | { |
474 | 0 | ::std::vector< OUString > aFilterVector; |
475 | 0 | OUString aFilterName = pFoundFilter->GetFilterName(); |
476 | 0 | OUString aLowerAsciiFileName = aCurrentDropFile.toAsciiLowerCase(); |
477 | |
|
478 | 0 | FuInsertFile::GetSupportedFilterVector( aFilterVector ); |
479 | |
|
480 | 0 | if( ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFoundFilter->GetMimeType() ) != aFilterVector.end() ) || |
481 | 0 | aFilterName.indexOf( "Text" ) != -1 || |
482 | 0 | aFilterName.indexOf( "Rich" ) != -1 || |
483 | 0 | aFilterName.indexOf( "RTF" ) != -1 || |
484 | 0 | aFilterName.indexOf( "HTML" ) != -1 || |
485 | 0 | aLowerAsciiFileName.indexOf(".sdd") != -1 || |
486 | 0 | aLowerAsciiFileName.indexOf(".sda") != -1 || |
487 | 0 | aLowerAsciiFileName.indexOf(".sxd") != -1 || |
488 | 0 | aLowerAsciiFileName.indexOf(".sxi") != -1 || |
489 | 0 | aLowerAsciiFileName.indexOf(".std") != -1 || |
490 | 0 | aLowerAsciiFileName.indexOf(".sti") != -1 ) |
491 | 0 | { |
492 | 0 | ::sd::Window* pWin = mpViewSh->GetActiveWindow(); |
493 | 0 | SfxRequest aReq(SID_INSERTFILE, ::SfxCallMode::SLOT, mrDoc.GetItemPool()); |
494 | 0 | SfxStringItem aItem1( ID_VAL_DUMMY0, aCurrentDropFile ), aItem2( ID_VAL_DUMMY1, pFoundFilter->GetFilterName() ); |
495 | |
|
496 | 0 | aReq.AppendItem( aItem1 ); |
497 | 0 | aReq.AppendItem( aItem2 ); |
498 | 0 | FuInsertFile::Create( *mpViewSh, pWin, this, mrDoc, aReq ); |
499 | 0 | bHandled = true; |
500 | 0 | } |
501 | 0 | } |
502 | 0 | } |
503 | 0 | } |
504 | |
|
505 | 0 | #if HAVE_FEATURE_AVMEDIA |
506 | 0 | if (!bHandled) |
507 | 0 | { |
508 | 0 | bool bShallowDetect = ::avmedia::MediaWindow::isMediaURL(aCurrentDropFile, u""_ustr/*TODO?*/); |
509 | 0 | if (bShallowDetect) |
510 | 0 | { |
511 | 0 | mxDropMediaSizeListener.set(new avmedia::PlayerListener( |
512 | 0 | [this, aCurrentDropFile](const css::uno::Reference<css::media::XPlayer>& rPlayer){ |
513 | 0 | SolarMutexGuard g; |
514 | |
|
515 | 0 | css::awt::Size aSize = rPlayer->getPreferredPlayerWindowSize(); |
516 | 0 | Size aPrefSize(aSize.Width, aSize.Height); |
517 | |
|
518 | 0 | if (aPrefSize.Width() && aPrefSize.Height()) |
519 | 0 | { |
520 | 0 | ::sd::Window* pWin = mpViewSh->GetActiveWindow(); |
521 | |
|
522 | 0 | if( pWin ) |
523 | 0 | aPrefSize = pWin->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM)); |
524 | 0 | else |
525 | 0 | aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM)); |
526 | 0 | } |
527 | 0 | else |
528 | 0 | aPrefSize = Size( 5000, 5000 ); |
529 | |
|
530 | 0 | InsertMediaURL(aCurrentDropFile, mnAction, maDropPos, aPrefSize, true); |
531 | |
|
532 | 0 | mxDropMediaSizeListener.clear(); |
533 | 0 | })); |
534 | 0 | } |
535 | 0 | bHandled = bShallowDetect && ::avmedia::MediaWindow::isMediaURL(aCurrentDropFile, u""_ustr/*TODO?*/, true, mxDropMediaSizeListener); |
536 | 0 | } |
537 | 0 | #endif |
538 | |
|
539 | 0 | if (!bHandled) |
540 | 0 | { |
541 | 0 | if( mnAction & DND_ACTION_LINK ) |
542 | 0 | static_cast< DrawViewShell* >( mpViewSh )->InsertURLButton( aCurrentDropFile, aCurrentDropFile, OUString(), &maDropPos ); |
543 | 0 | else |
544 | 0 | { |
545 | 0 | if( mpViewSh ) |
546 | 0 | { |
547 | 0 | try |
548 | 0 | { |
549 | | //TODO/MBA: testing |
550 | 0 | OUString aName; |
551 | 0 | uno::Sequence < beans::PropertyValue > aMedium{ comphelper::makePropertyValue( |
552 | 0 | u"URL"_ustr, aCurrentDropFile) }; |
553 | |
|
554 | 0 | uno::Reference < embed::XEmbeddedObject > xObj = mpDocSh->GetEmbeddedObjectContainer(). |
555 | 0 | InsertEmbeddedObject( aMedium, aName ); |
556 | |
|
557 | 0 | uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY ); |
558 | 0 | if ( xPersist.is()) |
559 | 0 | { |
560 | | // TODO/LEAN: VisualArea access can switch the object to running state |
561 | 0 | sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; |
562 | |
|
563 | 0 | xPersist->storeOwn(); |
564 | |
|
565 | 0 | awt::Size aSz; |
566 | 0 | try |
567 | 0 | { |
568 | 0 | aSz = xObj->getVisualAreaSize( nAspect ); |
569 | 0 | } |
570 | 0 | catch( embed::NoVisualAreaSizeException& ) |
571 | 0 | { |
572 | | // the default size will be set later |
573 | 0 | } |
574 | |
|
575 | 0 | Size aSize( aSz.Width, aSz.Height ); |
576 | 0 | ::tools::Rectangle aRect; |
577 | |
|
578 | 0 | if (!aSize.Width() || !aSize.Height()) |
579 | 0 | { |
580 | 0 | aSize.setWidth( 1410 ); |
581 | 0 | aSize.setHeight( 1000 ); |
582 | 0 | } |
583 | |
|
584 | 0 | aRect = ::tools::Rectangle( maDropPos, aSize ); |
585 | |
|
586 | 0 | rtl::Reference<SdrOle2Obj> pOleObj = new SdrOle2Obj( |
587 | 0 | getSdrModelFromSdrView(), |
588 | 0 | svt::EmbeddedObjectRef(xObj, nAspect), |
589 | 0 | aName, |
590 | 0 | aRect); |
591 | 0 | SdrInsertFlags nOptions = SdrInsertFlags::SETDEFLAYER; |
592 | |
|
593 | 0 | if (mpViewSh != nullptr) |
594 | 0 | { |
595 | 0 | OSL_ASSERT (mpViewSh->GetViewShell()!=nullptr); |
596 | 0 | SfxInPlaceClient* pIpClient = |
597 | 0 | mpViewSh->GetViewShell()->GetIPClient(); |
598 | 0 | if (pIpClient!=nullptr && pIpClient->IsObjectInPlaceActive()) |
599 | 0 | nOptions |= SdrInsertFlags::DONTMARK; |
600 | 0 | } |
601 | |
|
602 | 0 | if (InsertObjectAtView( pOleObj.get(), *GetSdrPageView(), nOptions )) |
603 | 0 | pOleObj->SetLogicRect( aRect ); |
604 | 0 | aSz.Width = aRect.GetWidth(); |
605 | 0 | aSz.Height = aRect.GetHeight(); |
606 | 0 | xObj->setVisualAreaSize( nAspect,aSz ); |
607 | 0 | } |
608 | 0 | } |
609 | 0 | catch( uno::Exception& ) |
610 | 0 | { |
611 | 0 | nError = ERRCODE_IO_GENERAL; |
612 | | // TODO/LATER: better error handling |
613 | 0 | } |
614 | 0 | } |
615 | 0 | } |
616 | 0 | } |
617 | |
|
618 | 0 | ++aIter; |
619 | 0 | } |
620 | |
|
621 | 0 | if( nError ) |
622 | 0 | ErrorHandler::HandleError( nError ); |
623 | 0 | } |
624 | | |
625 | | /** |
626 | | * Timer handler for Errorhandling at Drop() |
627 | | */ |
628 | | IMPL_LINK_NOARG(View, DropErrorHdl, Timer *, void) |
629 | 0 | { |
630 | 0 | vcl::Window* pWin = mpViewSh ? mpViewSh->GetActiveWindow() : nullptr; |
631 | 0 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr, |
632 | 0 | VclMessageType::Info, VclButtonsType::Ok, |
633 | 0 | SdResId(STR_ACTION_NOTPOSSIBLE))); |
634 | 0 | xInfoBox->run(); |
635 | 0 | } |
636 | | |
637 | | /** |
638 | | * @returns StyleSheet from selection |
639 | | */ |
640 | | SfxStyleSheet* View::GetStyleSheet() const |
641 | 0 | { |
642 | 0 | return SdrView::GetStyleSheet(); |
643 | 0 | } |
644 | | |
645 | | } // end of namespace sd |
646 | | |
647 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |