android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / sdview2.cxx
blobaf76e39afd4ba38a0edbe2308e2f74d6950266f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <View.hxx>
22 #include <vector>
23 #include <com/sun/star/embed/XEmbedPersist.hpp>
24 #include <com/sun/star/embed/XEmbeddedObject.hpp>
25 #include <comphelper/sequenceashashmap.hxx>
26 #include <tools/urlobj.hxx>
27 #include <svx/svdoole2.hxx>
28 #include <svx/svxdlg.hxx>
29 #include <sfx2/docfile.hxx>
30 #include <svx/svdundo.hxx>
31 #include <svx/svdpagv.hxx>
32 #include <svl/urlbmk.hxx>
33 #include <editeng/outliner.hxx>
34 #include <svx/xflclit.hxx>
35 #include <sot/formats.hxx>
36 #include <editeng/editeng.hxx>
38 #include <svtools/embedtransfer.hxx>
39 #include <tools/debug.hxx>
41 #include <anminfo.hxx>
42 #include <strings.hrc>
43 #include <sdxfer.hxx>
44 #include <sdresid.hxx>
45 #include <sdmod.hxx>
46 #include <sdtreelb.hxx>
47 #include <DrawViewShell.hxx>
48 #include <DrawDocShell.hxx>
49 #include <fudraw.hxx>
50 #include <drawdoc.hxx>
51 #include <Window.hxx>
52 #include <sdpage.hxx>
53 #include <unoaprms.hxx>
54 #include <helpids.h>
55 #include <vcl/svapp.hxx>
57 #include <slideshow.hxx>
58 #include <memory>
60 namespace sd {
62 using namespace ::com::sun::star;
64 namespace {
66 struct SdNavigatorDropEvent : public ExecuteDropEvent
68 VclPtr< ::sd::Window> mpTargetWindow;
70 SdNavigatorDropEvent (
71 const ExecuteDropEvent& rEvt,
72 ::sd::Window* pTargetWindow )
73 : ExecuteDropEvent( rEvt ),
74 mpTargetWindow( pTargetWindow )
80 css::uno::Reference< css::datatransfer::XTransferable > View::CreateClipboardDataObject()
82 // since SdTransferable::CopyToClipboard is called, this
83 // dynamically created object is destroyed automatically
84 rtl::Reference<SdTransferable> pTransferable = new SdTransferable( &mrDoc, nullptr, false );
86 SD_MOD()->pTransferClip = pTransferable.get();
88 mrDoc.CreatingDataObj( pTransferable.get() );
89 pTransferable->SetWorkDocument( static_cast<SdDrawDocument*>(CreateMarkedObjModel().release()) );
90 mrDoc.CreatingDataObj( nullptr );
92 // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
93 // fat lines correctly
94 const ::tools::Rectangle aMarkRect( GetAllMarkedBoundRect() );
95 std::unique_ptr<TransferableObjectDescriptor> pObjDesc(new TransferableObjectDescriptor);
96 SdrOle2Obj* pSdrOleObj = nullptr;
97 SdrPageView* pPgView = GetSdrPageView();
98 SdPage* pOldPage = pPgView ? static_cast<SdPage*>( pPgView->GetPage() ) : nullptr;
99 SdPage* pNewPage = const_cast<SdPage*>(static_cast<const SdPage*>( pTransferable->GetWorkDocument()->GetPage( 0 ) ));
101 if( pOldPage )
103 pNewPage->SetSize( pOldPage->GetSize() );
104 pNewPage->SetLayoutName( pOldPage->GetLayoutName() );
107 if( GetMarkedObjectCount() == 1 )
109 SdrObject* pObj = GetMarkedObjectByIndex(0);
111 if( auto pOle2Obj = dynamic_cast<SdrOle2Obj *>( pObj ) )
112 if( pOle2Obj->GetObjRef() )
114 // If object has no persistence it must be copied as part of the document
117 uno::Reference< embed::XEmbedPersist > xPersObj( pOle2Obj->GetObjRef(), uno::UNO_QUERY );
118 if ( xPersObj.is() && xPersObj->hasEntry() )
119 pSdrOleObj = pOle2Obj;
121 catch( uno::Exception& )
126 if( pSdrOleObj )
127 SvEmbedTransferHelper::FillTransferableObjectDescriptor( *pObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
128 else
129 pTransferable->GetWorkDocument()->GetDocSh()->FillTransferableObjectDescriptor( *pObjDesc );
131 if( mpDocSh )
132 pObjDesc->maDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
134 pObjDesc->maSize = aMarkRect.GetSize();
136 pTransferable->SetStartPos( aMarkRect.TopLeft() );
137 pTransferable->SetObjectDescriptor( std::move(pObjDesc) );
138 pTransferable->CopyToClipboard( mpViewSh->GetActiveWindow() );
140 return pTransferable;
143 css::uno::Reference< css::datatransfer::XTransferable > View::CreateDragDataObject( View* pWorkView, vcl::Window& rWindow, const Point& rDragPos )
145 rtl::Reference<SdTransferable> pTransferable = new SdTransferable( &mrDoc, pWorkView, false );
147 SD_MOD()->pTransferDrag = pTransferable.get();
149 std::unique_ptr<TransferableObjectDescriptor> pObjDesc(new TransferableObjectDescriptor);
150 OUString aDisplayName;
151 SdrOle2Obj* pSdrOleObj = nullptr;
153 if( GetMarkedObjectCount() == 1 )
155 SdrObject* pObj = GetMarkedObjectByIndex( 0 );
157 if( auto pOle2Obj = dynamic_cast<SdrOle2Obj *>( pObj ) )
158 if( pOle2Obj->GetObjRef() )
160 // If object has no persistence it must be copied as part of the document
163 uno::Reference< embed::XEmbedPersist > xPersObj( pOle2Obj->GetObjRef(), uno::UNO_QUERY );
164 if ( xPersObj.is() && xPersObj->hasEntry() )
165 pSdrOleObj = pOle2Obj;
167 catch( uno::Exception& )
172 if( mpDocSh )
173 aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
175 if( pSdrOleObj )
176 SvEmbedTransferHelper::FillTransferableObjectDescriptor( *pObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
177 else if (mpDocSh)
178 mpDocSh->FillTransferableObjectDescriptor( *pObjDesc );
180 pObjDesc->maSize = GetAllMarkedRect().GetSize();
181 pObjDesc->maDragStartPos = rDragPos;
182 pObjDesc->maDisplayName = aDisplayName;
184 pTransferable->SetStartPos( rDragPos );
185 pTransferable->SetObjectDescriptor( std::move(pObjDesc) );
186 pTransferable->StartDrag( &rWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
188 return pTransferable;
191 css::uno::Reference< css::datatransfer::XTransferable > View::CreateSelectionDataObject( View* pWorkView )
193 rtl::Reference<SdTransferable> pTransferable = new SdTransferable( &mrDoc, pWorkView, true );
194 std::unique_ptr<TransferableObjectDescriptor> pObjDesc(new TransferableObjectDescriptor);
195 const ::tools::Rectangle aMarkRect( GetAllMarkedRect() );
197 SD_MOD()->pTransferSelection = pTransferable.get();
199 if( mpDocSh )
201 mpDocSh->FillTransferableObjectDescriptor( *pObjDesc );
202 pObjDesc->maDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
205 pObjDesc->maSize = aMarkRect.GetSize();
207 pTransferable->SetStartPos( aMarkRect.TopLeft() );
208 pTransferable->SetObjectDescriptor( std::move(pObjDesc) );
209 pTransferable->CopyToPrimarySelection();
211 return pTransferable;
214 void View::UpdateSelectionClipboard() // false case
216 if (!mpViewSh)
217 return;
218 if (!mpViewSh->GetActiveWindow())
219 return;
220 if (GetMarkedObjectList().GetMarkCount())
221 CreateSelectionDataObject( this );
222 else
223 ClearSelectionClipboard();
226 void View::ClearSelectionClipboard() // true case
228 if (!mpViewSh)
229 return;
230 if (!mpViewSh->GetActiveWindow())
231 return;
232 if (SD_MOD()->pTransferSelection && SD_MOD()->pTransferSelection->GetView() == this)
234 TransferableHelper::ClearPrimarySelection();
235 SD_MOD()->pTransferSelection = nullptr;
239 void View::DoCut()
241 const OutlinerView* pOLV = GetTextEditOutlinerView();
243 if( pOLV )
244 const_cast<OutlinerView*>(pOLV)->Cut();
245 else if( AreObjectsMarked() )
247 OUString aStr(SdResId(STR_UNDO_CUT));
249 DoCopy();
250 BegUndo(aStr + " " + GetDescriptionOfMarkedObjects());
251 DeleteMarked();
252 EndUndo();
256 void View::DoCopy()
258 const OutlinerView* pOLV = GetTextEditOutlinerView();
260 if( pOLV )
261 const_cast<OutlinerView*>(pOLV)->Copy();
262 else if( AreObjectsMarked() )
264 BrkAction();
265 CreateClipboardDataObject();
269 void View::DoPaste (::sd::Window* pWindow)
271 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewSh->GetActiveWindow() ) );
272 if( !aDataHelper.GetTransferable().is() )
273 return; // empty clipboard?
275 const OutlinerView* pOLV = GetTextEditOutlinerView();
277 if( pOLV && EditEngine::HasValidData( aDataHelper.GetTransferable() ) )
279 const_cast< OutlinerView* >(pOLV)->PasteSpecial();
281 SdrObject* pObj = GetTextEditObject();
282 SdPage* pPage = static_cast<SdPage*>( pObj ? pObj->getSdrPageFromSdrObject() : nullptr );
283 ::Outliner* pOutliner = pOLV->GetOutliner();
285 if( pOutliner)
287 if( pObj && pPage && pPage->GetPresObjKind(pObj) == PresObjKind::Title )
289 // remove all hard linebreaks from the title
290 if (pOutliner->GetParagraphCount() > 1)
292 bool bOldUpdateMode = pOutliner->SetUpdateLayout( false );
294 const EditEngine& rEdit = pOutliner->GetEditEngine();
295 const sal_Int32 nParaCount = rEdit.GetParagraphCount();
297 for( sal_Int32 nPara = nParaCount - 2; nPara >= 0; nPara-- )
299 const sal_Int32 nParaLen = rEdit.GetTextLen( nPara );
300 pOutliner->QuickDelete( ESelection( nPara, nParaLen, nPara+1, 0 ) );
301 pOutliner->QuickInsertLineBreak( ESelection( nPara, nParaLen, nPara, nParaLen ) );
304 DBG_ASSERT( rEdit.GetParagraphCount() <= 1, "Titleobject contains hard line breaks" );
305 pOutliner->SetUpdateLayout(bOldUpdateMode);
309 if( !mrDoc.IsChanged() )
311 if (pOutliner->IsModified())
312 mrDoc.SetChanged();
316 else
318 Point aPos = pWindow->GetVisibleCenter();
319 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>( mpDocSh->GetViewShell() );
321 if (pDrViewSh != nullptr)
323 sal_Int8 nDnDAction = DND_ACTION_COPY;
324 if( !InsertData( aDataHelper, aPos, nDnDAction, false ) )
326 INetBookmark aINetBookmark( "", "" );
328 if( ( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
329 aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
330 ( aDataHelper.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ) &&
331 aDataHelper.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
332 ( aDataHelper.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) &&
333 aDataHelper.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
335 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), "" );
342 void View::StartDrag( const Point& rStartPos, vcl::Window* pWindow )
344 if (!AreObjectsMarked() || !IsAction() || !mpViewSh || !pWindow)
345 return;
347 BrkAction();
349 if( IsTextEdit() )
350 SdrEndTextEdit();
352 if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(mpDocSh ? mpDocSh->GetViewShell() : nullptr))
354 const rtl::Reference<FuPoor>& xFunction(pDrawViewShell->GetCurrentFunction());
355 if (FuDraw* pFunction = dynamic_cast<FuDraw*>(xFunction.get()))
356 pFunction->ForcePointer();
359 mpDragSrcMarkList.reset( new SdrMarkList(GetMarkedObjectList()) );
360 mnDragSrcPgNum = GetSdrPageView()->GetPage()->GetPageNum();
362 CreateDragDataObject( this, *pWindow, rStartPos );
365 void View::DragFinished( sal_Int8 nDropAction )
367 const bool bUndo = IsUndoEnabled();
368 const bool bGroupUndo = bUndo && mpDragSrcMarkList;
369 if (bGroupUndo)
371 OUString aStr(SdResId(STR_UNDO_DRAGDROP));
372 BegUndo(aStr + " " + mpDragSrcMarkList->GetMarkDescription());
375 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
377 if( pDragTransferable )
378 pDragTransferable->SetView( nullptr );
380 if( ( nDropAction & DND_ACTION_MOVE ) &&
381 pDragTransferable && !pDragTransferable->IsInternalMove() &&
382 mpDragSrcMarkList && mpDragSrcMarkList->GetMarkCount() &&
383 !IsPresObjSelected() )
385 mpDragSrcMarkList->ForceSort();
387 if( bUndo )
388 BegUndo();
390 const size_t nCnt = mpDragSrcMarkList->GetMarkCount();
392 for( size_t nm = nCnt; nm>0; )
394 --nm;
395 SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
396 if( bUndo )
397 AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoDeleteObject(*pM->GetMarkedSdrObj()));
400 mpDragSrcMarkList->GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
402 for (size_t nm = nCnt; nm>0;)
404 --nm;
405 SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
406 SdrObject* pObj=pM->GetMarkedSdrObj();
408 if( pObj && pObj->getSdrPageFromSdrObject() )
410 const size_t nOrdNum = pObj->GetOrdNumDirect();
411 rtl::Reference<SdrObject> pChkObj = pObj->getSdrPageFromSdrObject()->RemoveObject(nOrdNum);
412 DBG_ASSERT(pChkObj.get()==pObj,"pChkObj!=pObj in RemoveObject()");
416 if( bUndo )
417 EndUndo();
420 if( pDragTransferable )
421 pDragTransferable->SetInternalMove( false );
423 if (bGroupUndo)
424 EndUndo();
425 mnDragSrcPgNum = SDRPAGE_NOTFOUND;
426 mpDragSrcMarkList.reset();
429 sal_Int8 View::AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
430 SdrLayerID nLayer )
432 OUString aLayerName = GetActiveLayer();
433 SdrPageView* pPV = GetSdrPageView();
434 sal_Int8 nDropAction = rEvt.mnAction;
435 sal_Int8 nRet = DND_ACTION_NONE;
437 if( nLayer != SDRLAYER_NOTFOUND )
439 SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
440 SdrLayer* pLayer = rLayerAdmin.GetLayerPerID(nLayer);
441 assert(pLayer && "layer missing");
442 aLayerName = pLayer->GetName();
445 if( mbIsDropAllowed && !pPV->IsLayerLocked( aLayerName ) && pPV->IsLayerVisible( aLayerName ) )
447 const OutlinerView* pOLV = GetTextEditOutlinerView();
448 bool bIsInsideOutlinerView = false;
450 if( pOLV )
452 ::tools::Rectangle aRect( pOLV->GetOutputArea() );
454 if (GetMarkedObjectCount() == 1)
456 SdrMark* pMark = GetSdrMarkByIndex(0);
457 SdrObject* pObj = pMark->GetMarkedSdrObj();
458 aRect.Union( pObj->GetLogicRect() );
461 if( aRect.Contains( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) ) )
463 bIsInsideOutlinerView = true;
467 if( !bIsInsideOutlinerView )
469 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
471 if(pDragTransferable && (nDropAction & DND_ACTION_LINK))
473 // suppress own data when it's intention is to use it as fill information
474 pDragTransferable = nullptr;
477 if( pDragTransferable )
479 const View* pSourceView = pDragTransferable->GetView();
481 if( pDragTransferable->IsPageTransferable() )
483 nRet = DND_ACTION_COPY;
485 else if( pSourceView )
487 if( !( nDropAction & DND_ACTION_LINK ) ||
488 !pSourceView->GetDocSh()->GetMedium()->GetName().isEmpty() )
490 nRet = nDropAction;
494 else
496 const bool bDrawing = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::DRAWING );
497 const bool bGraphic = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVXB );
498 const bool bMtf = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::GDIMETAFILE );
499 const bool bBitmap = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::BITMAP );
500 bool bBookmark = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK );
501 bool bXFillExchange = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::XFA );
503 // check handle insert
504 if ((bXFillExchange && (SdrDragMode::Gradient == GetDragMode()))
505 || (SdrDragMode::Transparence == GetDragMode()))
507 const SdrHdlList& rHdlList = GetHdlList();
509 for( size_t n = 0; n < rHdlList.GetHdlCount(); ++n )
511 SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
513 if( pIAOHandle && ( SdrHdlKind::Color == pIAOHandle->GetKind() ) )
515 if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
517 nRet = nDropAction;
518 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_SELECTED );
520 else
522 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_NORMAL );
528 // check object insert
529 if( !nRet && ( bXFillExchange || ( ( bDrawing || bGraphic || bMtf || bBitmap || bBookmark ) && ( nDropAction & DND_ACTION_LINK ) ) ) )
531 SdrPageView* pPageView = nullptr;
532 ::sd::Window* pWindow = mpViewSh->GetActiveWindow();
533 Point aPos( pWindow->PixelToLogic( rEvt.maPosPixel ) );
534 SdrObject* pPickObj = PickObj(aPos, getHitTolLog(), pPageView);
535 bool bIsPresTarget = false;
537 if (pPickObj && (pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall()))
539 SdPage* pPage = static_cast<SdPage*>( pPickObj->getSdrPageFromSdrObject() );
541 if( pPage && pPage->IsMasterPage() )
542 bIsPresTarget = pPage->IsPresObj( pPickObj );
545 if (pPickObj && !bIsPresTarget && (bGraphic || bMtf || bBitmap || bXFillExchange))
547 if( mpDropMarkerObj != pPickObj )
549 mpDropMarkerObj = pPickObj;
550 ImplClearDrawDropMarker();
552 if(mpDropMarkerObj)
554 mpDropMarker.reset( new SdrDropMarkerOverlay(*this, *mpDropMarkerObj) );
558 nRet = nDropAction;
560 else
561 bXFillExchange = false;
564 // check normal insert
565 if( !nRet )
567 const bool bSBAFormat = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVX_FORMFIELDEXCH );
568 const bool bEditEngineODF = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT );
569 const bool bString = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::STRING );
570 const bool bRTF = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::RTF );
571 const bool bFile = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE );
572 const bool bFileList = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::FILE_LIST );
574 if( mpDropMarker )
576 ImplClearDrawDropMarker();
577 mpDropMarkerObj = nullptr;
580 if( bBookmark && bFile && ( nDropAction & DND_ACTION_MOVE ) && mpViewSh && SlideShow::IsRunning(mpViewSh->GetViewShellBase()) )
581 bBookmark = false;
583 if( bDrawing || bGraphic || bMtf || bBitmap || bBookmark || bFile || bFileList || bXFillExchange || bSBAFormat || bEditEngineODF || bString || bRTF )
584 nRet = nDropAction;
586 // For entries from the navigator, change action copy.
587 if (bBookmark
588 && rTargetHelper.IsDropFormatSupported(
589 SdPageObjsTLV::SdPageObjsTransferable::GetListBoxDropFormatId())
590 && (nDropAction & DND_ACTION_MOVE)!=0)
592 nRet = DND_ACTION_COPY;
599 // destroy drop marker if this is a leaving event
600 if( rEvt.mbLeaving && mpDropMarker )
602 ImplClearDrawDropMarker();
603 mpDropMarkerObj = nullptr;
606 return nRet;
609 sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt,
610 ::sd::Window* pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer )
612 SdrPageView* pPV = GetSdrPageView();
613 OUString aActiveLayer = GetActiveLayer();
614 sal_Int8 nDropAction = rEvt.mnAction;
615 sal_Int8 nRet = DND_ACTION_NONE;
617 // destroy drop marker if it is shown
618 if( mpDropMarker )
620 ImplClearDrawDropMarker();
621 mpDropMarkerObj = nullptr;
624 if( !pPV->IsLayerLocked( aActiveLayer ) )
626 const OutlinerView* pOLV = GetTextEditOutlinerView();
627 bool bIsInsideOutlinerView = false;
629 if( pOLV )
631 ::tools::Rectangle aRect( pOLV->GetOutputArea() );
633 if( GetMarkedObjectCount() == 1 )
635 SdrMark* pMark = GetSdrMarkByIndex(0);
636 SdrObject* pObj = pMark->GetMarkedSdrObj();
637 aRect.Union( pObj->GetLogicRect() );
640 Point aPos( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) );
642 if( aRect.Contains( aPos ) )
644 bIsInsideOutlinerView = true;
648 if( !bIsInsideOutlinerView )
650 Point aPos;
651 TransferableDataHelper aDataHelper( rEvt.maDropEvent.Transferable );
653 if( pTargetWindow )
654 aPos = pTargetWindow->PixelToLogic( rEvt.maPosPixel );
656 // handle insert?
657 if ((SdrDragMode::Gradient == GetDragMode())
658 || ((SdrDragMode::Transparence == GetDragMode())
659 && aDataHelper.HasFormat(SotClipboardFormatId::XFA)))
661 const SdrHdlList& rHdlList = GetHdlList();
663 for( size_t n = 0; !nRet && n < rHdlList.GetHdlCount(); ++n )
665 SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
667 if( pIAOHandle && ( SdrHdlKind::Color == pIAOHandle->GetKind() ) )
669 if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
671 uno::Any const data(aDataHelper.GetAny(SotClipboardFormatId::XFA, ""));
672 uno::Sequence<beans::NamedValue> props;
673 if (data >>= props)
675 ::comphelper::SequenceAsHashMap const map(props);
676 Color aColor(COL_BLACK);
677 auto const it = map.find("FillColor");
678 if (it != map.end())
680 XFillColorItem color;
681 color.PutValue(it->second, 0);
682 aColor = color.GetColorValue();
684 static_cast< SdrHdlColor* >( pIAOHandle )->SetColor( aColor, true );
685 nRet = nDropAction;
692 // standard insert?
693 if( !nRet && InsertData( aDataHelper, aPos, nDropAction, true, SotClipboardFormatId::NONE, nPage, nLayer ) )
694 nRet = nDropAction;
696 // special insert?
697 if( !nRet && mpViewSh )
699 INetBookmark aINetBookmark( (OUString()), (OUString()) );
701 // insert bookmark
702 if( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
703 aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
705 SdPageObjsTLV::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLV::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
707 if( pPageObjsTransferable &&
708 ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ||
709 NAVIGATOR_DRAGTYPE_EMBEDDED == pPageObjsTransferable->GetDragType() ) )
711 // insert bookmark from own navigator (handled async. due to possible message box )
712 Application::PostUserEvent( LINK( this, View, ExecuteNavigatorDrop ),
713 new SdNavigatorDropEvent( rEvt, pTargetWindow ) );
714 nRet = nDropAction;
716 else
718 SdrPageView* pPageView = nullptr;
720 SdrObject* pPickObj = PickObj(aPos, getHitTolLog(), pPageView);
721 if (pPickObj)
723 // insert as clip action => jump
724 OUString aBookmark( aINetBookmark.GetURL() );
725 SdAnimationInfo* pInfo = SdDrawDocument::GetAnimationInfo( pPickObj );
727 if( !aBookmark.isEmpty() )
729 bool bCreated = false;
731 presentation::ClickAction eClickAction = presentation::ClickAction_DOCUMENT;
733 sal_Int32 nIndex = aBookmark.indexOf( '#' );
734 if( nIndex != -1 )
736 const std::u16string_view aDocName( aBookmark.subView( 0, nIndex ) );
738 if (mpDocSh->GetMedium()->GetName() == aDocName || aDocName == mpDocSh->GetName())
740 // internal jump, only use the part after and including '#'
741 eClickAction = presentation::ClickAction_BOOKMARK;
742 aBookmark = aBookmark.copy( nIndex+1 );
746 if( !pInfo )
748 pInfo = SdDrawDocument::GetShapeUserData( *pPickObj, true );
749 bCreated = true;
752 // create undo action with old and new sizes
753 std::unique_ptr<SdAnimationPrmsUndoAction> pAction(new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated));
754 pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
755 pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
756 pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
757 pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
758 pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
759 pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
760 pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
761 pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
762 pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
763 pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
764 pAction->SetClickAction(pInfo->meClickAction, eClickAction);
765 pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
766 pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
767 pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
768 pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
769 pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
770 pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
772 OUString aString(SdResId(STR_UNDO_ANIMATION));
773 pAction->SetComment(aString);
774 mpDocSh->GetUndoManager()->AddUndoAction(std::move(pAction));
775 pInfo->meClickAction = eClickAction;
776 pInfo->SetBookmark( aBookmark );
777 mrDoc.SetChanged();
779 nRet = nDropAction;
782 else if( auto pDrawViewShell = dynamic_cast< DrawViewShell *>( mpViewSh ) )
784 // insert as normal URL button
785 pDrawViewShell->InsertURLButton( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), OUString(), &aPos );
786 nRet = nDropAction;
794 return nRet;
797 IMPL_LINK( View, ExecuteNavigatorDrop, void*, p, void )
799 SdNavigatorDropEvent* pSdNavigatorDropEvent = static_cast<SdNavigatorDropEvent*>(p);
800 TransferableDataHelper aDataHelper( pSdNavigatorDropEvent->maDropEvent.Transferable );
801 SdPageObjsTLV::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLV::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
802 INetBookmark aINetBookmark;
804 if( pPageObjsTransferable && aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
806 Point aPos;
807 OUString aBookmark;
808 SdPage* pPage = static_cast<SdPage*>( GetSdrPageView()->GetPage() );
809 sal_uInt16 nPgPos = 0xFFFF;
811 if( pSdNavigatorDropEvent->mpTargetWindow )
812 aPos = pSdNavigatorDropEvent->mpTargetWindow->PixelToLogic( pSdNavigatorDropEvent->maPosPixel );
814 const OUString& aURL( aINetBookmark.GetURL() );
815 sal_Int32 nIndex = aURL.indexOf( '#' );
816 if( nIndex != -1 )
817 aBookmark = aURL.copy( nIndex+1 );
819 std::vector<OUString> aExchangeList;
820 std::vector<OUString> aBookmarkList(1,aBookmark);
822 if( !pPage->IsMasterPage() )
824 if( pPage->GetPageKind() == PageKind::Standard )
825 nPgPos = pPage->GetPageNum() + 2;
826 else if( pPage->GetPageKind() == PageKind::Notes )
827 nPgPos = pPage->GetPageNum() + 1;
830 /* In order t ensure unique page names, we test the ones we want to
831 insert. If necessary. we put them into and replacement list (bNameOK
832 == sal_False -> User canceled). */
833 bool bLink = pPageObjsTransferable->GetDragType() == NAVIGATOR_DRAGTYPE_LINK;
834 bool bNameOK = GetExchangeList( aExchangeList, aBookmarkList, 2 );
836 /* Since we don't know the type (page or object), we fill a list with
837 pages and objects.
838 Of course we have problems if there are pages and objects with the
839 same name!!! */
840 if( bNameOK )
842 mrDoc.InsertBookmark( aBookmarkList, aExchangeList,
843 bLink, nPgPos,
844 &pPageObjsTransferable->GetDocShell(),
845 &aPos );
849 delete pSdNavigatorDropEvent;
852 bool View::GetExchangeList (std::vector<OUString> &rExchangeList,
853 std::vector<OUString> &rBookmarkList,
854 const sal_uInt16 nType)
856 assert(rExchangeList.empty());
858 bool bListIdentical = true; ///< Bookmark list and exchange list are identical
859 bool bNameOK = true; ///< name is unique
861 for ( const auto& rBookmark : rBookmarkList )
863 OUString aNewName = rBookmark;
865 if( nType == 0 || nType == 2 )
866 bNameOK = mpDocSh->CheckPageName(mpViewSh->GetFrameWeld(), aNewName);
868 if( bNameOK && ( nType == 1 || nType == 2 ) )
870 if( mrDoc.GetObj( aNewName ) )
872 OUString aTitle(SdResId(STR_TITLE_NAMEGROUP));
873 OUString aDesc(SdResId(STR_DESC_NAMEGROUP));
875 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
876 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(mpViewSh->GetFrameWeld(), aNewName, aDesc));
878 pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_OBJECT );
880 bNameOK = false;
881 pDlg->SetText( aTitle );
883 while( !bNameOK && pDlg->Execute() == RET_OK )
885 pDlg->GetName( aNewName );
887 if( !mrDoc.GetObj( aNewName ) )
888 bNameOK = true;
893 bListIdentical = rBookmark == aNewName;
895 rExchangeList.push_back(aNewName);
897 if (!bNameOK)
898 break;
901 // Exchange list is identical to bookmark list
902 if( !rExchangeList.empty() && bListIdentical )
903 rExchangeList.clear();
905 return bNameOK;
908 } // end of namespace sd
910 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */