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