bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / sdview2.cxx
blob29e388d34ea0f272c57993d8c95f255a5517912e
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 <tools/urlobj.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <svx/svdetc.hxx>
27 #include <svx/svdoole2.hxx>
28 #include <svx/svdograf.hxx>
29 #include <vcl/graph.hxx>
30 #include <svx/xexch.hxx>
31 #include <svx/svxdlg.hxx>
32 #include <svx/dialogs.hrc>
33 #include <sfx2/docfile.hxx>
34 #include <sfx2/childwin.hxx>
35 #include <svx/svdundo.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svl/urlbmk.hxx>
38 #include <editeng/outliner.hxx>
39 #include <svx/xflclit.hxx>
40 #include <sot/formats.hxx>
41 #include <editeng/editeng.hxx>
42 #include <svx/svditer.hxx>
43 #include <svx/obj3d.hxx>
44 #include <svx/scene3d.hxx>
46 #include <sfx2/objsh.hxx>
47 #include <svtools/embedtransfer.hxx>
49 #include "navigatr.hxx"
50 #include "anminfo.hxx"
51 #include "strings.hrc"
52 #include "glob.hrc"
53 #include "sdxfer.hxx"
54 #include "sdresid.hxx"
55 #include "sdmod.hxx"
56 #include "DrawViewShell.hxx"
57 #include "DrawDocShell.hxx"
58 #include "fudraw.hxx"
59 #include "drawdoc.hxx"
60 #include "Window.hxx"
61 #include "sdpage.hxx"
62 #include "unoaprms.hxx"
63 #include "drawview.hxx"
64 #include "helpids.h"
65 #include <vcl/svapp.hxx>
67 #include "slideshow.hxx"
68 #include <boost/scoped_ptr.hpp>
70 namespace sd {
72 using namespace ::com::sun::star;
74 // - SdNavigatorDropEvent -
76 struct SdNavigatorDropEvent : public ExecuteDropEvent
78 DropTargetHelper& mrTargetHelper;
79 VclPtr< ::sd::Window> mpTargetWindow;
80 sal_uInt16 mnPage;
81 sal_uInt16 mnLayer;
83 SdNavigatorDropEvent (
84 const ExecuteDropEvent& rEvt,
85 DropTargetHelper& rTargetHelper,
86 ::sd::Window* pTargetWindow,
87 sal_uInt16 nPage,
88 sal_uInt16 nLayer )
89 : ExecuteDropEvent( rEvt ),
90 mrTargetHelper( rTargetHelper ),
91 mpTargetWindow( pTargetWindow ),
92 mnPage( nPage ),
93 mnLayer( nLayer )
97 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateClipboardDataObject( View*, vcl::Window& )
99 // since SdTransferable::CopyToClipboard is called, this
100 // dynamically created object ist destroyed automatically
101 SdTransferable* pTransferable = new SdTransferable( &mrDoc, NULL, false );
102 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
104 SD_MOD()->pTransferClip = pTransferable;
106 mrDoc.CreatingDataObj( pTransferable );
107 pTransferable->SetWorkDocument( static_cast<SdDrawDocument*>(GetMarkedObjModel()) );
108 mrDoc.CreatingDataObj( NULL );
110 // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
111 // fat lines correctly
112 const Rectangle aMarkRect( GetAllMarkedBoundRect() );
113 TransferableObjectDescriptor aObjDesc;
114 SdrOle2Obj* pSdrOleObj = NULL;
115 SdrPageView* pPgView = GetSdrPageView();
116 SdPage* pOldPage = pPgView ? static_cast<SdPage*>( pPgView->GetPage() ) : NULL;
117 SdPage* pNewPage = const_cast<SdPage*>(static_cast<const SdPage*>( pTransferable->GetWorkDocument()->GetPage( 0 ) ));
119 if( pOldPage )
121 pNewPage->SetSize( pOldPage->GetSize() );
122 pNewPage->SetLayoutName( pOldPage->GetLayoutName() );
125 if( GetMarkedObjectCount() == 1 )
127 SdrObject* pObj = GetMarkedObjectByIndex(0);
129 if( pObj && pObj->ISA(SdrOle2Obj) && static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
131 // If object has no persistence it must be copied as part of the document
134 uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObj)->GetObjRef(), uno::UNO_QUERY );
135 if ( xPersObj.is() && xPersObj->hasEntry() )
136 pSdrOleObj = static_cast<SdrOle2Obj*>(pObj);
138 catch( uno::Exception& )
143 if( pSdrOleObj )
144 SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
145 else
146 pTransferable->GetWorkDocument()->GetDocSh()->FillTransferableObjectDescriptor( aObjDesc );
148 if( mpDocSh )
149 aObjDesc.maDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
151 aObjDesc.maSize = aMarkRect.GetSize();
153 pTransferable->SetStartPos( aMarkRect.TopLeft() );
154 pTransferable->SetObjectDescriptor( aObjDesc );
155 pTransferable->CopyToClipboard( mpViewSh->GetActiveWindow() );
157 return xRet;
160 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateDragDataObject( View* pWorkView, vcl::Window& rWindow, const Point& rDragPos )
162 SdTransferable* pTransferable = new SdTransferable( &mrDoc, pWorkView, false );
163 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
165 SD_MOD()->pTransferDrag = pTransferable;
167 TransferableObjectDescriptor aObjDesc;
168 OUString aDisplayName;
169 SdrOle2Obj* pSdrOleObj = NULL;
171 if( GetMarkedObjectCount() == 1 )
173 SdrObject* pObj = GetMarkedObjectByIndex( 0 );
175 if( pObj && pObj->ISA( SdrOle2Obj ) && static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
177 // If object has no persistence it must be copied as part of the document
180 uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObj)->GetObjRef(), uno::UNO_QUERY );
181 if ( xPersObj.is() && xPersObj->hasEntry() )
182 pSdrOleObj = static_cast<SdrOle2Obj*>(pObj);
184 catch( uno::Exception& )
189 if( mpDocSh )
190 aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
192 if( pSdrOleObj )
193 SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
194 else if (mpDocSh)
195 mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
197 aObjDesc.maSize = GetAllMarkedRect().GetSize();
198 aObjDesc.maDragStartPos = rDragPos;
199 aObjDesc.maDisplayName = aDisplayName;
200 aObjDesc.mbCanLink = false;
202 pTransferable->SetStartPos( rDragPos );
203 pTransferable->SetObjectDescriptor( aObjDesc );
204 pTransferable->StartDrag( &rWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
206 return xRet;
209 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateSelectionDataObject( View* pWorkView, vcl::Window& rWindow )
211 SdTransferable* pTransferable = new SdTransferable( &mrDoc, pWorkView, true );
212 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
213 TransferableObjectDescriptor aObjDesc;
214 const Rectangle aMarkRect( GetAllMarkedRect() );
215 OUString aDisplayName;
217 SD_MOD()->pTransferSelection = pTransferable;
219 if( mpDocSh )
221 aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
222 mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
225 aObjDesc.maSize = aMarkRect.GetSize();
227 pTransferable->SetStartPos( aMarkRect.TopLeft() );
228 pTransferable->SetObjectDescriptor( aObjDesc );
229 pTransferable->CopyToSelection( &rWindow );
231 return xRet;
234 void View::UpdateSelectionClipboard( bool bForceDeselect )
236 if( mpViewSh && mpViewSh->GetActiveWindow() )
238 if( !bForceDeselect && GetMarkedObjectList().GetMarkCount() )
239 CreateSelectionDataObject( this, *mpViewSh->GetActiveWindow() );
240 else if( SD_MOD()->pTransferSelection && ( SD_MOD()->pTransferSelection->GetView() == this ) )
242 TransferableHelper::ClearSelection( mpViewSh->GetActiveWindow() );
243 SD_MOD()->pTransferSelection = NULL;
248 void View::DoCut(vcl::Window* )
250 const OutlinerView* pOLV = GetTextEditOutlinerView();
252 if( pOLV )
253 const_cast<OutlinerView*>(pOLV)->Cut();
254 else if( AreObjectsMarked() )
256 OUString aStr(SD_RESSTR(STR_UNDO_CUT));
258 DoCopy();
259 BegUndo(aStr + " " + GetDescriptionOfMarkedObjects());
260 DeleteMarked();
261 EndUndo();
265 void View::DoCopy (vcl::Window* pWindow)
267 const OutlinerView* pOLV = GetTextEditOutlinerView();
269 if( pOLV )
270 const_cast<OutlinerView*>(pOLV)->Copy();
271 else if( AreObjectsMarked() )
273 BrkAction();
274 CreateClipboardDataObject( this, *pWindow );
278 void View::DoPaste (vcl::Window* pWindow)
280 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewSh->GetActiveWindow() ) );
281 if( !aDataHelper.GetTransferable().is() )
282 return; // empty clipboard?
284 const OutlinerView* pOLV = GetTextEditOutlinerView();
286 if( pOLV && EditEngine::HasValidData( aDataHelper.GetTransferable() ) )
288 const_cast< OutlinerView* >(pOLV)->PasteSpecial();
290 SdrObject* pObj = GetTextEditObject();
291 SdPage* pPage = static_cast<SdPage*>( pObj ? pObj->GetPage() : NULL );
292 ::Outliner* pOutliner = pOLV->GetOutliner();
294 if( pOutliner)
296 if( pObj && pPage && pPage->GetPresObjKind(pObj) == PRESOBJ_TITLE )
298 // remove all hard linebreaks from the title
299 if( pOutliner && pOutliner->GetParagraphCount() > 1 )
301 bool bOldUpdateMode = pOutliner->GetUpdateMode();
303 pOutliner->SetUpdateMode( false );
305 const EditEngine& rEdit = pOutliner->GetEditEngine();
306 const sal_Int32 nParaCount = rEdit.GetParagraphCount();
308 for( sal_Int32 nPara = nParaCount - 2; nPara >= 0; nPara-- )
310 const sal_Int32 nParaLen = rEdit.GetTextLen( nPara );
311 pOutliner->QuickDelete( ESelection( nPara, nParaLen, nPara+1, 0 ) );
312 pOutliner->QuickInsertLineBreak( ESelection( nPara, nParaLen, nPara, nParaLen ) );
315 DBG_ASSERT( rEdit.GetParagraphCount() <= 1, "Titleobject contains hard line breaks" );
316 pOutliner->SetUpdateMode(bOldUpdateMode);
320 if( !mrDoc.IsChanged() )
322 if( pOutliner && pOutliner->IsModified() )
323 mrDoc.SetChanged( true );
327 else
329 Point aPos;
330 sal_Int8 nDnDAction = DND_ACTION_COPY;
332 if( pWindow )
333 aPos = pWindow->PixelToLogic( Rectangle( aPos, pWindow->GetOutputSizePixel() ).Center() );
335 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>( mpDocSh->GetViewShell() );
337 if (pDrViewSh != NULL)
339 if( !InsertData( aDataHelper, aPos, nDnDAction, false ) )
341 INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
343 if( ( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
344 aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
345 ( aDataHelper.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ) &&
346 aDataHelper.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
347 ( aDataHelper.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) &&
348 aDataHelper.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
350 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
357 void View::StartDrag( const Point& rStartPos, vcl::Window* pWindow )
359 if( AreObjectsMarked() && IsAction() && mpViewSh && pWindow && !mpDragSrcMarkList )
361 BrkAction();
363 if( IsTextEdit() )
364 SdrEndTextEdit();
366 DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpDocSh ? mpDocSh->GetViewShell() : 0 );
368 if( pDrawViewShell )
370 rtl::Reference<FuPoor> xFunction( pDrawViewShell->GetCurrentFunction() );
372 if( xFunction.is() && xFunction->ISA( FuDraw ) )
373 static_cast<FuDraw*>(xFunction.get())->ForcePointer( NULL );
376 mpDragSrcMarkList = new SdrMarkList(GetMarkedObjectList());
377 mnDragSrcPgNum = GetSdrPageView()->GetPage()->GetPageNum();
379 if( IsUndoEnabled() )
381 OUString aStr(SD_RESSTR(STR_UNDO_DRAGDROP));
382 BegUndo(aStr + " " + mpDragSrcMarkList->GetMarkDescription());
384 CreateDragDataObject( this, *pWindow, rStartPos );
388 void View::DragFinished( sal_Int8 nDropAction )
390 const bool bUndo = IsUndoEnabled();
392 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
394 if( pDragTransferable )
395 pDragTransferable->SetView( NULL );
397 if( ( nDropAction & DND_ACTION_MOVE ) &&
398 pDragTransferable && !pDragTransferable->IsInternalMove() &&
399 mpDragSrcMarkList && mpDragSrcMarkList->GetMarkCount() &&
400 !IsPresObjSelected() )
402 mpDragSrcMarkList->ForceSort();
404 if( bUndo )
405 BegUndo();
407 const size_t nAnz = mpDragSrcMarkList->GetMarkCount();
409 for( size_t nm = nAnz; nm>0; )
411 --nm;
412 SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
413 if( bUndo )
414 AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoDeleteObject(*pM->GetMarkedSdrObj()));
417 mpDragSrcMarkList->GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
419 for (size_t nm = nAnz; nm>0;)
421 --nm;
422 SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
423 SdrObject* pObj=pM->GetMarkedSdrObj();
425 if( pObj && pObj->GetPage() )
427 const size_t nOrdNum = pObj->GetOrdNumDirect();
428 #ifdef DBG_UTIL
429 SdrObject* pChkObj =
430 #endif
431 pObj->GetPage()->RemoveObject(nOrdNum);
432 DBG_ASSERT(pChkObj==pObj,"pChkObj!=pObj in RemoveObject()");
436 if( bUndo )
437 EndUndo();
440 if( pDragTransferable )
441 pDragTransferable->SetInternalMove( false );
443 if( bUndo )
444 EndUndo();
445 mnDragSrcPgNum = SDRPAGE_NOTFOUND;
446 delete mpDragSrcMarkList;
447 mpDragSrcMarkList = NULL;
450 sal_Int8 View::AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
451 ::sd::Window*, sal_uInt16, sal_uInt16 nLayer )
453 OUString aLayerName = GetActiveLayer();
454 SdrPageView* pPV = GetSdrPageView();
455 sal_Int8 nDropAction = rEvt.mnAction;
456 sal_Int8 nRet = DND_ACTION_NONE;
458 if( nLayer != SDRLAYER_NOTFOUND )
460 SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
461 aLayerName = rLayerAdmin.GetLayerPerID(nLayer)->GetName();
464 if( mbIsDropAllowed && !pPV->IsLayerLocked( aLayerName ) && pPV->IsLayerVisible( aLayerName ) )
466 const OutlinerView* pOLV = GetTextEditOutlinerView();
467 bool bIsInsideOutlinerView = false;
469 if( pOLV )
471 Rectangle aRect( pOLV->GetOutputArea() );
473 if (GetMarkedObjectCount() == 1)
475 SdrMark* pMark = GetSdrMarkByIndex(0);
476 SdrObject* pObj = pMark->GetMarkedSdrObj();
477 aRect.Union( pObj->GetLogicRect() );
480 if( aRect.IsInside( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) ) )
482 bIsInsideOutlinerView = true;
486 if( !bIsInsideOutlinerView )
488 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
490 if(pDragTransferable && (nDropAction & DND_ACTION_LINK))
492 // suppress own data when it's intention is to use it as fill information
493 pDragTransferable = 0;
496 if( pDragTransferable )
498 const View* pSourceView = pDragTransferable->GetView();
500 if( pDragTransferable->IsPageTransferable() )
502 nRet = DND_ACTION_COPY;
504 else if( pSourceView )
506 if( !( nDropAction & DND_ACTION_LINK ) ||
507 !pSourceView->GetDocSh()->GetMedium()->GetName().isEmpty() )
509 nRet = nDropAction;
513 else
515 const bool bDrawing = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::DRAWING );
516 const bool bGraphic = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVXB );
517 const bool bMtf = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::GDIMETAFILE );
518 const bool bBitmap = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::BITMAP );
519 bool bBookmark = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK );
520 bool bXFillExchange = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::XFA );
522 // check handle insert
523 if( !nRet && ( (bXFillExchange && ( SDRDRAG_GRADIENT == GetDragMode() )) || ( SDRDRAG_TRANSPARENCE == GetDragMode() ) ) )
525 const SdrHdlList& rHdlList = GetHdlList();
527 for( size_t n = 0; n < rHdlList.GetHdlCount(); ++n )
529 SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
531 if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
533 if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
535 nRet = nDropAction;
536 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_SELECTED );
538 else
540 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_NORMAL );
546 // check object insert
547 if( !nRet && ( bXFillExchange || ( ( bDrawing || bGraphic || bMtf || bBitmap || bBookmark ) && ( nDropAction & DND_ACTION_LINK ) ) ) )
549 SdrObject* pPickObj = NULL;
550 SdrPageView* pPageView = NULL;
551 ::sd::Window* pWindow = mpViewSh->GetActiveWindow();
552 Point aPos( pWindow->PixelToLogic( rEvt.maPosPixel ) );
553 const bool bHasPickObj = PickObj( aPos, getHitTolLog(), pPickObj, pPageView );
554 bool bIsPresTarget = false;
556 if( bHasPickObj && pPickObj && ( pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall() ) )
558 SdPage* pPage = static_cast<SdPage*>( pPickObj->GetPage() );
560 if( pPage && pPage->IsMasterPage() )
561 bIsPresTarget = pPage->IsPresObj( pPickObj );
564 if( bHasPickObj && !bIsPresTarget &&
565 ( bGraphic || bMtf || bBitmap || bXFillExchange ) )
567 if( mpDropMarkerObj != pPickObj )
569 mpDropMarkerObj = pPickObj;
570 ImplClearDrawDropMarker();
572 if(mpDropMarkerObj)
574 mpDropMarker = new SdrDropMarkerOverlay(*this, *mpDropMarkerObj);
578 nRet = nDropAction;
580 else
581 bXFillExchange = false;
584 // check normal insert
585 if( !nRet )
587 const bool bSBAFormat = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVX_FORMFIELDEXCH );
588 const bool bEditEngine = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::EDITENGINE );
589 const bool bString = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::STRING );
590 const bool bRTF = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::RTF );
591 const bool bFile = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE );
592 const bool bFileList = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::FILE_LIST );
594 if( mpDropMarker )
596 ImplClearDrawDropMarker();
597 mpDropMarkerObj = NULL;
600 if( bBookmark && bFile && ( nDropAction & DND_ACTION_MOVE ) && mpViewSh && SlideShow::IsRunning(mpViewSh->GetViewShellBase()) )
601 bBookmark = false;
603 if( bDrawing || bGraphic || bMtf || bBitmap || bBookmark || bFile || bFileList || bXFillExchange || bSBAFormat || bEditEngine || bString || bRTF )
604 nRet = nDropAction;
606 // For entries from the navigator, change action copy.
607 if (bBookmark
608 && rTargetHelper.IsDropFormatSupported(
609 SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId())
610 && (nDropAction & DND_ACTION_MOVE)!=0)
612 nRet = DND_ACTION_COPY;
619 // destroy drop marker if this is a leaving event
620 if( rEvt.mbLeaving && mpDropMarker )
622 ImplClearDrawDropMarker();
623 mpDropMarkerObj = NULL;
626 return nRet;
629 sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
630 ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer )
632 SdrPageView* pPV = GetSdrPageView();
633 OUString aActiveLayer = GetActiveLayer();
634 sal_Int8 nDropAction = rEvt.mnAction;
635 sal_Int8 nRet = DND_ACTION_NONE;
637 // destroy drop marker if it is shown
638 if( mpDropMarker )
640 ImplClearDrawDropMarker();
641 mpDropMarkerObj = NULL;
644 if( !pPV->IsLayerLocked( aActiveLayer ) )
646 const OutlinerView* pOLV = GetTextEditOutlinerView();
647 bool bIsInsideOutlinerView = false;
649 if( pOLV )
651 Rectangle aRect( pOLV->GetOutputArea() );
653 if( GetMarkedObjectCount() == 1 )
655 SdrMark* pMark = GetSdrMarkByIndex(0);
656 SdrObject* pObj = pMark->GetMarkedSdrObj();
657 aRect.Union( pObj->GetLogicRect() );
660 Point aPos( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) );
662 if( aRect.IsInside( aPos ) )
664 bIsInsideOutlinerView = true;
668 if( !bIsInsideOutlinerView )
670 Point aPos;
671 TransferableDataHelper aDataHelper( rEvt.maDropEvent.Transferable );
673 if( pTargetWindow )
674 aPos = pTargetWindow->PixelToLogic( rEvt.maPosPixel );
676 // handle insert?
677 if( (!nRet && ( SDRDRAG_GRADIENT == GetDragMode() )) || (( SDRDRAG_TRANSPARENCE == GetDragMode() ) && aDataHelper.HasFormat( SotClipboardFormatId::XFA )) )
679 const SdrHdlList& rHdlList = GetHdlList();
681 for( size_t n = 0; !nRet && n < rHdlList.GetHdlCount(); ++n )
683 SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
685 if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
687 if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
689 ::tools::SvRef<SotStorageStream> xStm;
691 if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::XFA, xStm ) && xStm.Is() )
693 XFillExchangeData aFillData( XFillAttrSetItem( &mrDoc.GetPool() ) );
695 ReadXFillExchangeData( *xStm, aFillData );
696 const Color aColor( static_cast<const XFillColorItem&>( aFillData.GetXFillAttrSetItem()->GetItemSet().Get( XATTR_FILLCOLOR ) ).GetColorValue() );
697 static_cast< SdrHdlColor* >( pIAOHandle )->SetColor( aColor, true );
698 nRet = nDropAction;
705 // standard insert?
706 if( !nRet && InsertData( aDataHelper, aPos, nDropAction, true, SotClipboardFormatId::NONE, nPage, nLayer ) )
707 nRet = nDropAction;
709 // special insert?
710 if( !nRet && mpViewSh )
712 OUString aTmpString1, aTmpString2;
713 INetBookmark aINetBookmark( aTmpString1, aTmpString2 );
715 // insert bookmark
716 if( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
717 aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
719 SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
721 if( pPageObjsTransferable &&
722 ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ||
723 NAVIGATOR_DRAGTYPE_EMBEDDED == pPageObjsTransferable->GetDragType() ) )
725 // insert bookmark from own navigator (handled async. due to possible message box )
726 Application::PostUserEvent( LINK( this, View, ExecuteNavigatorDrop ),
727 new SdNavigatorDropEvent( rEvt, rTargetHelper, pTargetWindow,
728 nPage, nLayer ) );
729 nRet = nDropAction;
731 else
733 SdrObject* pPickObj = NULL;
734 SdrPageView* pPageView = NULL;
736 if( PickObj( aPos, getHitTolLog(), pPickObj, pPageView ) )
738 // insert as clip action => jump
739 OUString aBookmark( aINetBookmark.GetURL() );
740 SdAnimationInfo* pInfo = mrDoc.GetAnimationInfo( pPickObj );
742 if( !aBookmark.isEmpty() )
744 bool bCreated = false;
746 presentation::ClickAction eClickAction = presentation::ClickAction_DOCUMENT;
748 sal_Int32 nIndex = aBookmark.indexOf( (sal_Unicode)'#' );
749 if( nIndex != -1 )
751 const OUString aDocName( aBookmark.copy( 0, nIndex ) );
753 if (mpDocSh->GetMedium()->GetName() == aDocName || aDocName.equals(mpDocSh->GetName()))
755 // internal jump, only use the part after and including '#'
756 eClickAction = presentation::ClickAction_BOOKMARK;
757 aBookmark = aBookmark.copy( nIndex+1 );
761 if( !pInfo )
763 pInfo = SdDrawDocument::GetShapeUserData( *pPickObj, true );
764 bCreated = true;
767 // create undo action with old and new sizes
768 SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated);
769 pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
770 pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
771 pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
772 pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
773 pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
774 pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
775 pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
776 pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
777 pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
778 pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
779 pAction->SetPathObj(pInfo->mpPathObj, pInfo->mpPathObj);
780 pAction->SetClickAction(pInfo->meClickAction, eClickAction);
781 pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
782 pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
783 pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
784 pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
785 pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
786 pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
788 OUString aString(SdResId(STR_UNDO_ANIMATION));
789 pAction->SetComment(aString);
790 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
791 pInfo->meClickAction = eClickAction;
792 pInfo->SetBookmark( aBookmark );
793 mrDoc.SetChanged();
795 nRet = nDropAction;
798 else if( mpViewSh->ISA( DrawViewShell ) )
800 // insert as normal URL button
801 static_cast<DrawViewShell*>( mpViewSh )->InsertURLButton( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), OUString(), &aPos );
802 nRet = nDropAction;
810 return nRet;
813 IMPL_LINK( View, ExecuteNavigatorDrop, SdNavigatorDropEvent*, pSdNavigatorDropEvent )
815 TransferableDataHelper aDataHelper( pSdNavigatorDropEvent->maDropEvent.Transferable );
816 SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
817 INetBookmark aINetBookmark;
819 if( pPageObjsTransferable && aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
821 Point aPos;
822 OUString aBookmark;
823 SdPage* pPage = static_cast<SdPage*>( GetSdrPageView()->GetPage() );
824 sal_uInt16 nPgPos = 0xFFFF;
826 if( pSdNavigatorDropEvent->mpTargetWindow )
827 aPos = pSdNavigatorDropEvent->mpTargetWindow->PixelToLogic( pSdNavigatorDropEvent->maPosPixel );
829 const OUString aURL( aINetBookmark.GetURL() );
830 sal_Int32 nIndex = aURL.indexOf( (sal_Unicode)'#' );
831 if( nIndex != -1 )
832 aBookmark = aURL.copy( nIndex+1 );
834 std::vector<OUString> aExchangeList;
835 std::vector<OUString> aBookmarkList(1,aBookmark);
837 if( !pPage->IsMasterPage() )
839 if( pPage->GetPageKind() == PK_STANDARD )
840 nPgPos = pPage->GetPageNum() + 2;
841 else if( pPage->GetPageKind() == PK_NOTES )
842 nPgPos = pPage->GetPageNum() + 1;
845 /* In order t ensure unique page names, we test the ones we want to
846 insert. If necessary. we put them into and replacement list (bNameOK
847 == sal_False -> User canceled). */
848 bool bLink = pPageObjsTransferable->GetDragType() == NAVIGATOR_DRAGTYPE_LINK;
849 bool bNameOK = GetExchangeList( aExchangeList, aBookmarkList, 2 );
850 bool bReplace = false;
852 /* Since we don't know the type (page or object), we fill a list with
853 pages and objects.
854 Of course we have problems if there are pages and objects with the
855 same name!!! */
856 if( bNameOK )
858 mrDoc.InsertBookmark( aBookmarkList, aExchangeList,
859 bLink, bReplace, nPgPos, false,
860 &pPageObjsTransferable->GetDocShell(),
861 true, &aPos );
865 delete pSdNavigatorDropEvent;
867 return 0;
870 bool View::GetExchangeList (std::vector<OUString> &rExchangeList,
871 std::vector<OUString> &rBookmarkList,
872 const sal_uInt16 nType)
874 assert(rExchangeList.empty());
876 bool bListIdentical = true; ///< Bookmark list and exchange list are identical
877 bool bNameOK = true; ///< name is unique
879 std::vector<OUString>::const_iterator pIter;
880 for ( pIter = rBookmarkList.begin(); bNameOK && pIter != rBookmarkList.end(); ++pIter )
882 OUString aNewName = *pIter;
884 if( nType == 0 || nType == 2 )
885 bNameOK = mpDocSh->CheckPageName(mpViewSh->GetActiveWindow(), aNewName);
887 if( bNameOK && ( nType == 1 || nType == 2 ) )
889 if( mrDoc.GetObj( aNewName ) )
891 OUString aTitle(SD_RESSTR(STR_TITLE_NAMEGROUP));
892 OUString aDesc(SD_RESSTR(STR_DESC_NAMEGROUP));
894 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
895 boost::scoped_ptr<AbstractSvxNameDialog> pDlg;
897 if (pFact)
898 pDlg.reset(pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), aNewName, aDesc ));
900 if( pDlg )
902 pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_OBJECT );
904 bNameOK = false;
905 pDlg->SetText( aTitle );
907 while( !bNameOK && pDlg->Execute() == RET_OK )
909 pDlg->GetName( aNewName );
911 if( !mrDoc.GetObj( aNewName ) )
912 bNameOK = true;
918 bListIdentical = pIter->equals(aNewName);
920 rExchangeList.push_back(aNewName);
923 // Exchange list is identical to bookmark list
924 if( !rExchangeList.empty() && bListIdentical )
925 rExchangeList.clear();
927 return bNameOK;
930 typedef std::vector< SdrObject* > SdrObjectVector;
932 void ImplProcessObjectList(SdrObject* pObj, SdrObjectVector& rVector )
934 bool bIsGroup(pObj->IsGroupObject());
935 if(bIsGroup && pObj->ISA(E3dObject) && !pObj->ISA(E3dScene))
936 bIsGroup = false;
938 rVector.push_back( pObj );
940 if(bIsGroup)
942 SdrObjList* pObjList = pObj->GetSubList();
943 for( size_t a = 0; a < pObjList->GetObjCount(); ++a)
944 ImplProcessObjectList(pObjList->GetObj(a), rVector);
948 SdrModel* View::GetMarkedObjModel() const
950 return FmFormView::GetMarkedObjModel();;
953 bool View::Paste(
954 const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, SdrInsertFlags nOptions,
955 const OUString& rSrcShellID, const OUString& rDestShellID )
957 return FmFormView::Paste(rMod, rPos, pLst, nOptions, rSrcShellID, rDestShellID);
960 } // end of namespace sd
962 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */