xref: /trunk/main/sd/source/ui/view/sdview2.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "View.hxx"
33 
34 #include <vector>
35 #include <com/sun/star/embed/XEmbedPersist.hpp>
36 #include <tools/ref.hxx>
37 #include <tools/urlobj.hxx>
38 #ifndef _MSGBOX_HXX //autogen
39 #include <vcl/msgbox.hxx>
40 #endif
41 #include <svx/svdetc.hxx>
42 #include <svx/svdoole2.hxx>
43 #include <svx/svdograf.hxx>
44 #include <vcl/graph.hxx>
45 #include <svx/xexch.hxx>
46 #include <svx/svxdlg.hxx>
47 #include <svx/dialogs.hrc>
48 #include <sfx2/docfile.hxx>
49 #include <sfx2/childwin.hxx>
50 #include <svx/svdundo.hxx>
51 #include <svx/svdpagv.hxx>
52 #include <svl/urlbmk.hxx>
53 #include <svl/urlbmk.hxx>
54 #include <editeng/outliner.hxx>
55 #include <svx/xflclit.hxx>
56 #include <svx/dbexch.hrc>
57 #include <sot/formats.hxx>
58 #include <editeng/editeng.hxx>
59 #include <svx/svditer.hxx>
60 #include <svx/obj3d.hxx>
61 #include <svx/scene3d.hxx>
62 
63 #include <sfx2/objsh.hxx>
64 #include <svtools/embedtransfer.hxx>
65 
66 #include "navigatr.hxx"
67 #include "anminfo.hxx"
68 #include "strings.hrc"
69 #include "glob.hrc"
70 #include "sdxfer.hxx"
71 #include "sdresid.hxx"
72 #include "sdmod.hxx"
73 #include "DrawViewShell.hxx"
74 #include "DrawDocShell.hxx"
75 #include "fudraw.hxx"
76 #include "drawdoc.hxx"
77 #include "Window.hxx"
78 #include "sdpage.hxx"
79 #include "unoaprms.hxx"
80 #include "drawview.hxx"
81 #include "helpids.h"
82 #include <vcl/svapp.hxx>
83 
84 #include "slideshow.hxx"
85 
86 namespace sd {
87 
88 #ifndef SO2_DECL_SVINPLACEOBJECT_DEFINED
89 #define SO2_DECL_SVINPLACEOBJECT_DEFINED
90 SO2_DECL_REF(SvInPlaceObject)
91 #endif
92 #ifndef SO2_DECL_SVSTORAGE_DEFINED
93 #define SO2_DECL_SVSTORAGE_DEFINED
94 SO2_DECL_REF(SvStorage)
95 #endif
96 
97 using namespace ::com::sun::star;
98 
99 // ------------------------
100 // - SdNavigatorDropEvent -
101 // ------------------------
102 
103 struct SdNavigatorDropEvent : public ExecuteDropEvent
104 {
105     DropTargetHelper&       mrTargetHelper;
106     ::sd::Window* mpTargetWindow;
107     sal_uInt16                  mnPage;
108     sal_uInt16                  mnLayer;
109 
110     SdNavigatorDropEvent (
111         const ExecuteDropEvent& rEvt,
112         DropTargetHelper& rTargetHelper,
113         ::sd::Window* pTargetWindow,
114         sal_uInt16 nPage,
115         sal_uInt16 nLayer )
116         : ExecuteDropEvent( rEvt ),
117           mrTargetHelper( rTargetHelper ),
118           mpTargetWindow( pTargetWindow ),
119           mnPage( nPage ),
120           mnLayer( nLayer )
121     {}
122 };
123 
124 // -----------------------------------------------------------------------------
125 
126 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateClipboardDataObject( View*, ::Window& )
127 {
128     // since SdTransferable::CopyToClipboard is called, this
129     // dynamically created object ist destroyed automatically
130     SdTransferable* pTransferable = new SdTransferable( mpDoc, NULL, sal_False );
131     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
132 
133     SD_MOD()->pTransferClip = pTransferable;
134 
135     mpDoc->CreatingDataObj( pTransferable );
136     pTransferable->SetWorkDocument( (SdDrawDocument*) GetAllMarkedModel() );
137     mpDoc->CreatingDataObj( NULL );
138 
139     // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
140     // fat lines correctly
141     const Rectangle                 aMarkRect( GetAllMarkedBoundRect() );
142     TransferableObjectDescriptor    aObjDesc;
143     String                          aDisplayName;
144     SdrOle2Obj*                     pSdrOleObj = NULL;
145     SdrPageView*                    pPgView = GetSdrPageView();
146     SdPage*                         pOldPage = pPgView ? ( (SdPage*) pPgView->GetPage() ) : NULL;
147     SdPage*                         pNewPage = (SdPage*) pTransferable->GetWorkDocument()->GetPage( 0 );
148 
149     if( pOldPage )
150     {
151         pNewPage->SetSize( pOldPage->GetSize() );
152         pNewPage->SetLayoutName( pOldPage->GetLayoutName() );
153     }
154 
155     if( GetMarkedObjectCount() == 1 )
156     {
157         SdrObject* pObj = GetMarkedObjectByIndex(0);
158 
159         if( pObj && pObj->ISA(SdrOle2Obj) && ((SdrOle2Obj*) pObj)->GetObjRef().is() )
160         {
161             // If object has no persistence it must be copied as part of the document
162             try
163             {
164                 uno::Reference< embed::XEmbedPersist > xPersObj( ((SdrOle2Obj*)pObj)->GetObjRef(), uno::UNO_QUERY );
165                 if ( xPersObj.is() && xPersObj->hasEntry() )
166                     pSdrOleObj = (SdrOle2Obj*) pObj;
167             }
168             catch( uno::Exception& )
169             {}
170         }
171     }
172 
173     if( pSdrOleObj )
174         SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
175     else
176         pTransferable->GetWorkDocument()->GetDocSh()->FillTransferableObjectDescriptor( aObjDesc );
177 
178     if( mpDocSh )
179         aObjDesc.maDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
180 
181     aObjDesc.maSize = aMarkRect.GetSize();
182 
183     pTransferable->SetStartPos( aMarkRect.TopLeft() );
184     pTransferable->SetObjectDescriptor( aObjDesc );
185     pTransferable->CopyToClipboard( mpViewSh->GetActiveWindow() );
186 
187     return xRet;
188 }
189 
190 // -----------------------------------------------------------------------------
191 
192 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateDragDataObject( View* pWorkView, ::Window& rWindow, const Point& rDragPos )
193 {
194     SdTransferable* pTransferable = new SdTransferable( mpDoc, pWorkView, sal_False );
195     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
196 
197     SD_MOD()->pTransferDrag = pTransferable;
198 
199     TransferableObjectDescriptor    aObjDesc;
200     String                          aDisplayName;
201     SdrOle2Obj*                     pSdrOleObj = NULL;
202 
203     if( GetMarkedObjectCount() == 1 )
204     {
205         SdrObject* pObj = GetMarkedObjectByIndex( 0 );
206 
207         if( pObj && pObj->ISA( SdrOle2Obj ) && ( (SdrOle2Obj*) pObj )->GetObjRef().is() )
208         {
209             // If object has no persistence it must be copied as part of the document
210             try
211             {
212                 uno::Reference< embed::XEmbedPersist > xPersObj( ((SdrOle2Obj*)pObj)->GetObjRef(), uno::UNO_QUERY );
213                 if ( xPersObj.is() && xPersObj->hasEntry() )
214                     pSdrOleObj = (SdrOle2Obj*) pObj;
215             }
216             catch( uno::Exception& )
217             {}
218         }
219     }
220 
221     if( mpDocSh )
222         aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
223 
224     if( pSdrOleObj )
225         SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
226     else
227         mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
228 
229     aObjDesc.maSize = GetAllMarkedRect().GetSize();
230     aObjDesc.maDragStartPos = rDragPos;
231     aObjDesc.maDisplayName = aDisplayName;
232     aObjDesc.mbCanLink = sal_False;
233 
234     pTransferable->SetStartPos( rDragPos );
235     pTransferable->SetObjectDescriptor( aObjDesc );
236     pTransferable->StartDrag( &rWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
237 
238     return xRet;
239 }
240 
241 // -----------------------------------------------------------------------------
242 
243 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateSelectionDataObject( View* pWorkView, ::Window& rWindow )
244 {
245     SdTransferable*                 pTransferable = new SdTransferable( mpDoc, pWorkView, sal_True );
246     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
247     TransferableObjectDescriptor    aObjDesc;
248     const Rectangle                 aMarkRect( GetAllMarkedRect() );
249     String                          aDisplayName;
250 
251     SD_MOD()->pTransferSelection = pTransferable;
252 
253     if( mpDocSh )
254     {
255         aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
256         mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
257     }
258 
259     aObjDesc.maSize = aMarkRect.GetSize();
260 
261     pTransferable->SetStartPos( aMarkRect.TopLeft() );
262     pTransferable->SetObjectDescriptor( aObjDesc );
263     pTransferable->CopyToSelection( &rWindow );
264 
265     return xRet;
266 }
267 
268 // -----------------------------------------------------------------------------
269 
270 void View::UpdateSelectionClipboard( sal_Bool bForceDeselect )
271 {
272     if( mpViewSh && mpViewSh->GetActiveWindow() )
273     {
274         if( !bForceDeselect && GetMarkedObjectList().GetMarkCount() )
275             CreateSelectionDataObject( this, *mpViewSh->GetActiveWindow() );
276         else if( SD_MOD()->pTransferSelection && ( SD_MOD()->pTransferSelection->GetView() == this ) )
277         {
278             TransferableHelper::ClearSelection( mpViewSh->GetActiveWindow() );
279             SD_MOD()->pTransferSelection = NULL;
280         }
281     }
282 }
283 
284 // -----------------------------------------------------------------------------
285 
286 void View::DoCut(::Window* )
287 {
288     const OutlinerView* pOLV = GetTextEditOutlinerView();
289 
290     if( pOLV )
291         ( (OutlinerView*) pOLV)->Cut();
292     else if( AreObjectsMarked() )
293     {
294         String aStr( SdResId(STR_UNDO_CUT) );
295 
296         DoCopy();
297         BegUndo( ( aStr += sal_Unicode(' ') ) += GetDescriptionOfMarkedObjects() );
298         DeleteMarked();
299         EndUndo();
300     }
301 }
302 
303 // -----------------------------------------------------------------------------
304 
305 void View::DoCopy (::Window* pWindow)
306 {
307     const OutlinerView* pOLV = GetTextEditOutlinerView();
308 
309     if( pOLV )
310         ( (OutlinerView*) pOLV)->Copy();
311     else if( AreObjectsMarked() )
312     {
313         BrkAction();
314         CreateClipboardDataObject( this, *pWindow );
315     }
316 }
317 
318 // -----------------------------------------------------------------------------
319 
320 void View::DoPaste (::Window* pWindow)
321 {
322     TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewSh->GetActiveWindow() ) );
323     if( !aDataHelper.GetTransferable().is() )
324         return; // empty clipboard?
325 
326     const OutlinerView* pOLV = GetTextEditOutlinerView();
327 
328     if( pOLV && EditEngine::HasValidData( aDataHelper.GetTransferable() ) )
329     {
330         const_cast< OutlinerView* >(pOLV)->PasteSpecial();
331 
332         SdrObject*  pObj = GetTextEditObject();
333         SdPage*     pPage = (SdPage*)( pObj ? pObj->GetPage() : NULL );
334         ::Outliner* pOutliner = pOLV->GetOutliner();
335 
336         if( pOutliner)
337         {
338             if( pObj && pPage && pPage->GetPresObjKind(pObj) == PRESOBJ_TITLE )
339             {
340                 // remove all hard linebreaks from the title
341                 if( pOutliner && pOutliner->GetParagraphCount() > 1 )
342                 {
343                     sal_Bool bOldUpdateMode = pOutliner->GetUpdateMode();
344 
345                     pOutliner->SetUpdateMode( sal_False );
346 
347                     const EditEngine& rEdit = pOutliner->GetEditEngine();
348                     const int nParaCount = rEdit.GetParagraphCount();
349 
350                     for( int nPara = nParaCount - 2; nPara >= 0; nPara-- )
351                     {
352                         const sal_uInt16 nParaLen = (sal_uInt16)rEdit.GetTextLen( (sal_uInt16)nPara );
353                         pOutliner->QuickDelete( ESelection( (sal_uInt16)nPara, nParaLen, (sal_uInt16)nPara+1, 0 ) );
354                         pOutliner->QuickInsertLineBreak( ESelection( (sal_uInt16)nPara, nParaLen, (sal_uInt16)nPara, nParaLen ) );
355                     }
356 
357                     DBG_ASSERT( rEdit.GetParagraphCount() <= 1, "Titelobjekt contains hard line breaks" );
358                     pOutliner->SetUpdateMode(bOldUpdateMode);
359                 }
360             }
361 
362             if( !mpDoc->IsChanged() )
363             {
364                 if( pOutliner && pOutliner->IsModified() )
365                     mpDoc->SetChanged( sal_True );
366             }
367         }
368     }
369     else
370     {
371         Point       aPos;
372         sal_Int8    nDnDAction = DND_ACTION_COPY;
373 
374         if( pWindow )
375             aPos = pWindow->PixelToLogic( Rectangle( aPos, pWindow->GetOutputSizePixel() ).Center() );
376 
377         DrawViewShell* pDrViewSh = (DrawViewShell*) mpDocSh->GetViewShell();
378 
379         if (pDrViewSh != NULL)
380         {
381             if( !InsertData( aDataHelper, aPos, nDnDAction, sal_False ) )
382             {
383                 INetBookmark    aINetBookmark( aEmptyStr, aEmptyStr );
384 
385                 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
386                       aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
387                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
388                       aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
389                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
390                       aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
391                 {
392                     pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
393                 }
394             }
395         }
396     }
397 }
398 
399 // -----------------------------------------------------------------------------
400 
401 void View::StartDrag( const Point& rStartPos, ::Window* pWindow )
402 {
403     if( AreObjectsMarked() && IsAction() && mpViewSh && pWindow && !mpDragSrcMarkList )
404     {
405         BrkAction();
406 
407         if( IsTextEdit() )
408             SdrEndTextEdit();
409 
410         DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpDocSh ? mpDocSh->GetViewShell() : 0 );
411 
412         if( pDrawViewShell )
413         {
414             FunctionReference xFunction( pDrawViewShell->GetCurrentFunction() );
415 
416             if( xFunction.is() && xFunction->ISA( FuDraw ) )
417                 static_cast<FuDraw*>(xFunction.get())->ForcePointer( NULL );
418         }
419 
420         mpDragSrcMarkList = new SdrMarkList(GetMarkedObjectList());
421         mnDragSrcPgNum = GetSdrPageView()->GetPage()->GetPageNum();
422 
423         if( IsUndoEnabled() )
424         {
425             String aStr( SdResId(STR_UNDO_DRAGDROP) );
426             aStr += sal_Unicode(' ');
427             aStr += mpDragSrcMarkList->GetMarkDescription();
428             BegUndo(aStr);
429         }
430         CreateDragDataObject( this, *pWindow, rStartPos );
431     }
432 }
433 
434 // -----------------------------------------------------------------------------
435 
436 void View::DragFinished( sal_Int8 nDropAction )
437 {
438     const bool bUndo = IsUndoEnabled();
439 
440     SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
441 
442     if( pDragTransferable )
443         pDragTransferable->SetView( NULL );
444 
445     if( ( nDropAction & DND_ACTION_MOVE ) &&
446         pDragTransferable && !pDragTransferable->IsInternalMove() &&
447         mpDragSrcMarkList && mpDragSrcMarkList->GetMarkCount() &&
448         !IsPresObjSelected() )
449     {
450         mpDragSrcMarkList->ForceSort();
451 
452         if( bUndo )
453             BegUndo();
454 
455         sal_uLong nm, nAnz = mpDragSrcMarkList->GetMarkCount();
456 
457         for( nm = nAnz; nm>0; )
458         {
459             nm--;
460             SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
461             if( bUndo )
462                 AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pM->GetMarkedSdrObj()));
463         }
464 
465         mpDragSrcMarkList->GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
466 
467         for (nm=nAnz; nm>0;)
468         {
469             nm--;
470             SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
471             SdrObject* pObj=pM->GetMarkedSdrObj();
472             sal_uInt32 nOrdNum=pObj->GetOrdNumDirect();
473 
474             if( pObj && pObj->GetPage() )
475             {
476 #ifdef DBG_UTIL
477                 SdrObject* pChkObj =
478 #endif
479                     pObj->GetPage()->RemoveObject(nOrdNum);
480                 DBG_ASSERT(pChkObj==pObj,"pChkObj!=pObj beim RemoveObject()");
481             }
482         }
483 
484         if( bUndo )
485             EndUndo();
486     }
487 
488     if( pDragTransferable )
489         pDragTransferable->SetInternalMove( sal_False );
490 
491     if( bUndo )
492         EndUndo();
493     mnDragSrcPgNum = SDRPAGE_NOTFOUND;
494     delete mpDragSrcMarkList;
495     mpDragSrcMarkList = NULL;
496 }
497 
498 // -----------------------------------------------------------------------------
499 
500 sal_Int8 View::AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
501                              ::sd::Window*, sal_uInt16, sal_uInt16 nLayer )
502 {
503     String          aLayerName( GetActiveLayer() );
504     SdrPageView*    pPV = GetSdrPageView();
505     sal_Int8        nDropAction = rEvt.mnAction;
506     sal_Int8        nRet = DND_ACTION_NONE;
507 
508     if( nLayer != SDRLAYER_NOTFOUND )
509     {
510         SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
511         aLayerName = rLayerAdmin.GetLayerPerID(nLayer)->GetName();
512     }
513 
514     if( mbIsDropAllowed && !pPV->IsLayerLocked( aLayerName ) && pPV->IsLayerVisible( aLayerName ) )
515     {
516         const OutlinerView* pOLV = GetTextEditOutlinerView();
517         sal_Bool                bIsInsideOutlinerView = sal_False;
518 
519         if( pOLV )
520         {
521             Rectangle aRect( pOLV->GetOutputArea() );
522 
523             if (GetMarkedObjectCount() == 1)
524             {
525                 SdrMark* pMark = GetSdrMarkByIndex(0);
526                 SdrObject* pObj = pMark->GetMarkedSdrObj();
527                 aRect.Union( pObj->GetLogicRect() );
528             }
529 
530             if( aRect.IsInside( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) ) )
531             {
532                 bIsInsideOutlinerView = sal_True;
533             }
534         }
535 
536         if( !bIsInsideOutlinerView )
537         {
538             SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
539 
540             if( pDragTransferable )
541             {
542                 const View* pSourceView = pDragTransferable->GetView();
543 
544                 if( pDragTransferable->IsPageTransferable() )
545                 {
546                     nRet = DND_ACTION_COPY;
547                 }
548                 else if( pSourceView )
549                 {
550                     if( !( nDropAction & DND_ACTION_LINK ) ||
551                         pSourceView->GetDocSh()->GetMedium()->GetName().Len() )
552                     {
553                         nRet = nDropAction;
554                     }
555                 }
556             }
557             else
558             {
559                 const sal_Bool  bDrawing = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING );
560                 const sal_Bool  bGraphic = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB );
561                 const sal_Bool  bMtf = rTargetHelper.IsDropFormatSupported( FORMAT_GDIMETAFILE );
562                 const sal_Bool  bBitmap = rTargetHelper.IsDropFormatSupported( FORMAT_BITMAP );
563                 sal_Bool        bBookmark = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
564                 sal_Bool        bXFillExchange = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_XFA );
565 
566                 // check handle insert
567                 if( !nRet && ( (bXFillExchange && ( SDRDRAG_GRADIENT == GetDragMode() )) || ( SDRDRAG_TRANSPARENCE == GetDragMode() ) ) )
568                 {
569                     const SdrHdlList& rHdlList = GetHdlList();
570 
571                     for( sal_uInt32 n = 0; n < rHdlList.GetHdlCount(); n++ )
572                     {
573                         SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
574 
575                         if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
576                         {
577                             if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
578                             {
579                                 nRet = nDropAction;
580                                 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_SELECTED );
581                             }
582                             else
583                             {
584                                 static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_NORMAL );
585                             }
586                         }
587                     }
588                 }
589 
590                 // check object insert
591                 if( !nRet && ( bXFillExchange || ( ( bDrawing || bGraphic || bMtf || bBitmap || bBookmark ) && ( nDropAction & DND_ACTION_LINK ) ) ) )
592                 {
593                     SdrObject*      pPickObj = NULL;
594                     SdrPageView*    pPageView = NULL;
595                     ::sd::Window* pWindow = mpViewSh->GetActiveWindow();
596                     Point           aPos( pWindow->PixelToLogic( rEvt.maPosPixel ) );
597                     const sal_Bool      bHasPickObj = PickObj( aPos, getHitTolLog(), pPickObj, pPageView );
598                     sal_Bool            bIsPresTarget = sal_False;
599 
600                     if( bHasPickObj && pPickObj && ( pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall() ) )
601                     {
602                         SdPage* pPage = (SdPage*) pPickObj->GetPage();
603 
604                         if( pPage && pPage->IsMasterPage() )
605                             bIsPresTarget = pPage->IsPresObj( pPickObj );
606                     }
607 
608                     if( bHasPickObj && !bIsPresTarget &&
609                         ( !pPickObj->ISA( SdrGrafObj ) || bGraphic || bMtf || bBitmap || ( bXFillExchange && !pPickObj->ISA( SdrGrafObj ) && !pPickObj->ISA( SdrOle2Obj ) ) ) )
610                     {
611                         if( mpDropMarkerObj != pPickObj )
612                         {
613                             mpDropMarkerObj = pPickObj;
614                             ImplClearDrawDropMarker();
615 
616                             if(mpDropMarkerObj)
617                             {
618                                 mpDropMarker = new SdrDropMarkerOverlay(*this, *mpDropMarkerObj);
619                             }
620                         }
621 
622                         nRet = nDropAction;
623                     }
624                     else
625                         bXFillExchange = sal_False;
626                 }
627 
628                 // check normal insert
629                 if( !nRet )
630                 {
631                     const sal_Bool  bSBAFormat = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_SVX_FORMFIELDEXCH );
632                     const sal_Bool  bEditEngine = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_EDITENGINE );
633                     const sal_Bool  bString = rTargetHelper.IsDropFormatSupported( FORMAT_STRING );
634                     const sal_Bool  bRTF = rTargetHelper.IsDropFormatSupported( FORMAT_RTF );
635                     const sal_Bool  bFile = rTargetHelper.IsDropFormatSupported( FORMAT_FILE );
636                     const sal_Bool  bFileList = rTargetHelper.IsDropFormatSupported( FORMAT_FILE_LIST );
637 
638                     if( mpDropMarker )
639                     {
640                         ImplClearDrawDropMarker();
641                         mpDropMarkerObj = NULL;
642                     }
643 
644                     if( bBookmark && bFile && ( nDropAction & DND_ACTION_MOVE ) && mpViewSh && SlideShow::IsRunning(mpViewSh->GetViewShellBase()) )
645                         bBookmark = sal_False;
646 
647                     if( bDrawing || bGraphic || bMtf || bBitmap || bBookmark || bFile || bFileList || bXFillExchange || bSBAFormat || bEditEngine || bString || bRTF )
648                         nRet = nDropAction;
649 
650                     // For entries from the navigator, change action copy.
651                     if (bBookmark
652                         && rTargetHelper.IsDropFormatSupported(
653                             SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId())
654                         && (nDropAction & DND_ACTION_MOVE)!=0)
655                     {
656                         nRet = DND_ACTION_COPY;
657                     }
658                 }
659             }
660         }
661     }
662 
663     // destroy drop marker if this is a leaving event
664     if( rEvt.mbLeaving && mpDropMarker )
665     {
666         ImplClearDrawDropMarker();
667         mpDropMarkerObj = NULL;
668     }
669 
670     return nRet;
671 }
672 
673 // -----------------------------------------------------------------------------
674 
675 sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
676                               ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer )
677 {
678     SdrPageView*    pPV = GetSdrPageView();
679     String          aActiveLayer = GetActiveLayer();
680     sal_Int8        nDropAction = rEvt.mnAction;
681     sal_Int8        nRet = DND_ACTION_NONE;
682 
683     // destroy drop marker if it is shown
684     if( mpDropMarker )
685     {
686         ImplClearDrawDropMarker();
687         mpDropMarkerObj = NULL;
688     }
689 
690     if( !pPV->IsLayerLocked( aActiveLayer ) )
691     {
692         const OutlinerView* pOLV = GetTextEditOutlinerView();
693         sal_Bool                bIsInsideOutlinerView = sal_False;
694 
695         if( pOLV )
696         {
697             Rectangle aRect( pOLV->GetOutputArea() );
698 
699             if( GetMarkedObjectCount() == 1 )
700             {
701                 SdrMark* pMark = GetSdrMarkByIndex(0);
702                 SdrObject* pObj = pMark->GetMarkedSdrObj();
703                 aRect.Union( pObj->GetLogicRect() );
704             }
705 
706             Point aPos( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) );
707 
708             if( aRect.IsInside( aPos ) )
709             {
710                 bIsInsideOutlinerView = sal_True;
711             }
712         }
713 
714         if( !bIsInsideOutlinerView )
715         {
716             Point                   aPos;
717             TransferableDataHelper  aDataHelper( rEvt.maDropEvent.Transferable );
718 
719             if( pTargetWindow )
720                 aPos = pTargetWindow->PixelToLogic( rEvt.maPosPixel );
721 
722             // handle insert?
723             if( (!nRet && ( SDRDRAG_GRADIENT == GetDragMode() )) || (( SDRDRAG_TRANSPARENCE == GetDragMode() ) && aDataHelper.HasFormat( SOT_FORMATSTR_ID_XFA )) )
724             {
725                 const SdrHdlList& rHdlList = GetHdlList();
726 
727                 for( sal_uInt32 n = 0; !nRet && n < rHdlList.GetHdlCount(); n++ )
728                 {
729                     SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
730 
731                     if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
732                     {
733                         if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
734                         {
735                             SotStorageStreamRef xStm;
736 
737                             if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_XFA, xStm ) && xStm.Is() )
738                             {
739                                 XFillExchangeData aFillData( XFillAttrSetItem( &mpDoc->GetPool() ) );
740 
741                                 *xStm >> aFillData;
742                                 const Color aColor( ( (XFillColorItem&) aFillData.GetXFillAttrSetItem()->GetItemSet().Get( XATTR_FILLCOLOR ) ).GetColorValue() );
743                                 static_cast< SdrHdlColor* >( pIAOHandle )->SetColor( aColor, sal_True );
744                                 nRet = nDropAction;
745                             }
746                         }
747                     }
748                 }
749             }
750 
751             // standard insert?
752             if( !nRet && InsertData( aDataHelper, aPos, nDropAction, sal_True, 0, nPage, nLayer ) )
753                 nRet = nDropAction;
754 
755             // special insert?
756             if( !nRet && mpViewSh )
757             {
758                 String          aTmpString1, aTmpString2;
759                 INetBookmark    aINetBookmark( aTmpString1, aTmpString2 );
760 
761                 // insert bookmark
762                 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
763                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) )
764                 {
765                     SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
766 
767                     if( pPageObjsTransferable &&
768                         ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ||
769                           NAVIGATOR_DRAGTYPE_EMBEDDED == pPageObjsTransferable->GetDragType() ) )
770                     {
771                         // insert bookmark from own navigator (handled async. due to possible message box )
772                         Application::PostUserEvent( LINK( this, View, ExecuteNavigatorDrop ),
773                                                     new SdNavigatorDropEvent( rEvt, rTargetHelper, pTargetWindow,
774                                                                               nPage, nLayer ) );
775                         nRet = nDropAction;
776                     }
777                     else
778                     {
779                         SdrObject*      pPickObj = NULL;
780                         SdrPageView*    pPageView = NULL;
781 
782                         if( PickObj( aPos, getHitTolLog(), pPickObj, pPageView ) )
783                         {
784                             // insert as clip action => jump
785                             rtl::OUString       aBookmark( aINetBookmark.GetURL() );
786                             SdAnimationInfo*    pInfo = mpDoc->GetAnimationInfo( pPickObj );
787                             sal_Bool                bCreated = sal_False;
788 
789                             if( aBookmark.getLength() )
790                             {
791                                 presentation::ClickAction eClickAction = presentation::ClickAction_DOCUMENT;
792 
793                                 sal_Int32 nIndex = aBookmark.indexOf( (sal_Unicode)'#' );
794                                 if( nIndex != -1 )
795                                 {
796                                     const String aDocName( aBookmark.copy( 0, nIndex ) );
797 
798                                     if( mpDocSh->GetMedium()->GetName() == aDocName || mpDocSh->GetName() == aDocName )
799                                     {
800                                         // internal jump, only use the part after and including '#'
801                                         eClickAction = presentation::ClickAction_BOOKMARK;
802                                         aBookmark = aBookmark.copy( nIndex+1 );
803                                     }
804                                 }
805 
806                                 if( !pInfo )
807                                 {
808                                     pInfo = SdDrawDocument::GetShapeUserData( *pPickObj, true );
809                                     bCreated = sal_True;
810                                 }
811 
812                                 // Undo-Action mit alten und neuen Groessen erzeugen
813                                 SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction(mpDoc, pPickObj, bCreated);
814                                 pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
815                                 pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
816                                 pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
817                                 pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
818                                 pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
819                                 pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
820                                 pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
821                                 pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
822                                 pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
823                                 pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
824                                 pAction->SetPathObj(pInfo->mpPathObj, pInfo->mpPathObj);
825                                 pAction->SetClickAction(pInfo->meClickAction, eClickAction);
826                                 pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
827 //                              pAction->SetInvisibleInPres(pInfo->mbInvisibleInPresentation, sal_True);
828                                 pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
829                                 pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
830                                 pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
831                                 pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
832                                 pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
833 
834                                 String aString(SdResId(STR_UNDO_ANIMATION));
835                                 pAction->SetComment(aString);
836                                 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
837                                 pInfo->meClickAction = eClickAction;
838                                 pInfo->SetBookmark( aBookmark );
839                                 mpDoc->SetChanged();
840 
841                                 nRet = nDropAction;
842                             }
843                         }
844                         else if( mpViewSh->ISA( DrawViewShell ) )
845                         {
846                             // insert as normal URL button
847                             ( (DrawViewShell*) mpViewSh )->InsertURLButton( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), String(), &aPos );
848                             nRet = nDropAction;
849                         }
850                     }
851                 }
852             }
853         }
854     }
855 
856     return nRet;
857 }
858 
859 // -----------------------------------------------------------------------------
860 
861 IMPL_LINK( View, ExecuteNavigatorDrop, SdNavigatorDropEvent*, pSdNavigatorDropEvent )
862 {
863     TransferableDataHelper                  aDataHelper( pSdNavigatorDropEvent->maDropEvent.Transferable );
864     SdPageObjsTLB::SdPageObjsTransferable*  pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
865     INetBookmark                            aINetBookmark;
866 
867     if( pPageObjsTransferable && aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) )
868     {
869         Point   aPos;
870         List    aBookmarkList;
871         String  aBookmark;
872         SdPage* pPage = (SdPage*) GetSdrPageView()->GetPage();
873         sal_uInt16  nPgPos = 0xFFFF;
874 
875         if( pSdNavigatorDropEvent->mpTargetWindow )
876             aPos = pSdNavigatorDropEvent->mpTargetWindow->PixelToLogic( pSdNavigatorDropEvent->maPosPixel );
877 
878         const rtl::OUString aURL( aINetBookmark.GetURL() );
879         sal_Int32 nIndex = aURL.indexOf( (sal_Unicode)'#' );
880         if( nIndex != -1 )
881             aBookmark = aURL.copy( nIndex+1 );
882         aBookmarkList.Insert( &aBookmark );
883 
884         if( !pPage->IsMasterPage() )
885         {
886             if( pPage->GetPageKind() == PK_STANDARD )
887                 nPgPos = pPage->GetPageNum() + 2;
888             else if( pPage->GetPageKind() == PK_NOTES )
889                 nPgPos = pPage->GetPageNum() + 1;
890         }
891 
892         // Um zu gewaehrleisten, dass alle Seitennamen eindeutig sind, werden
893         // die einzufuegenden geprueft und gegebenenfalls in einer Ersatzliste
894         // aufgenommen (bNameOK == sal_False -> Benutzer hat abgebrochen)
895         List*   pExchangeList = NULL;
896         sal_Bool    bLink = ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType()  ? sal_True : sal_False );
897         sal_Bool    bNameOK = GetExchangeList( pExchangeList, &aBookmarkList, 2 );
898         sal_Bool    bReplace = sal_False;
899 
900         // Da man hier nicht weiss, ob es sich um eine Seite oder ein Objekt handelt,
901         // wird eine Liste sowohl mit Seiten, als auch mit Objekten gefuellt.
902         // Sollten Seitennamen und Objektnamen identisch sein gibt es hier natuerlich Probleme !!!
903         if( bNameOK )
904         {
905             mpDoc->InsertBookmark( &aBookmarkList, pExchangeList,
906                                   bLink, bReplace, nPgPos, sal_False,
907                                   &pPageObjsTransferable->GetDocShell(),
908                                   sal_True, &aPos );
909         }
910 
911         // Loeschen der ExchangeList
912         if( pExchangeList )
913         {
914             for( void* p = pExchangeList->First(); p; p = pExchangeList->Next() )
915                 delete (String*) p;
916 
917             delete pExchangeList;
918         }
919     }
920 
921     delete pSdNavigatorDropEvent;
922 
923     return 0;
924 }
925 
926 /*************************************************************************
927 |*
928 |* Rueckgabeparameter:
929 |* pExchangeList == NULL -> Namen sind alle eindeutig
930 |* bNameOK == sal_False -> Benutzer hat abgebrochen
931 |* nType == 0 -> Seiten
932 |* nType == 1 -> Objekte
933 |* nType == 2 -> Seiten + Objekte
934 |*
935 \************************************************************************/
936 
937 sal_Bool View::GetExchangeList( List*& rpExchangeList, List* pBookmarkList, sal_uInt16 nType )
938 {
939     DBG_ASSERT( !rpExchangeList, "ExchangeList muss NULL sein!");
940 
941     sal_Bool bListIdentical = sal_True; // BookmarkList und ExchangeList sind gleich
942     sal_Bool bNameOK = sal_True;        // Name ist eindeutig
943 
944     rpExchangeList = new List();
945 
946     if( pBookmarkList )
947     {
948         String* pString = (String*) pBookmarkList->First();
949 
950         while( pString && bNameOK )
951         {
952             String* pNewName = new String( *pString );
953 
954             if( nType == 0  || nType == 2 )
955                 bNameOK = mpDocSh->CheckPageName (
956                     mpViewSh->GetActiveWindow(), *pNewName);
957 
958             if( bNameOK && ( nType == 1  || nType == 2 ) )
959             {
960                 if( mpDoc->GetObj( *pNewName ) )
961                 {
962                     String          aTitle( SdResId( STR_TITLE_NAMEGROUP ) );
963                     String          aDesc( SdResId( STR_DESC_NAMEGROUP ) );
964                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
965                     AbstractSvxNameDialog* pDlg = pFact ? pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), *pNewName, aDesc ) : 0;
966                     if( pDlg )
967                     {
968                         pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_OBJECT );
969 
970                         bNameOK = sal_False;
971                         pDlg->SetText( aTitle );
972 
973                         while( !bNameOK && pDlg->Execute() == RET_OK )
974                         {
975                             pDlg->GetName( *pNewName );
976 
977                             if( !mpDoc->GetObj( *pNewName ) )
978                                 bNameOK = sal_True;
979                         }
980 
981                         delete pDlg;
982                     }
983                 }
984             }
985 
986             if( bListIdentical )
987                 bListIdentical = ( *pString == *pNewName );
988 
989             rpExchangeList->Insert( pNewName, LIST_APPEND );
990             pString = (String*) pBookmarkList->Next();
991         }
992     }
993 
994     // ExchangeList ist mit BookmarkList identisch
995     if( rpExchangeList && bListIdentical )
996     {
997         String* pString = (String*) rpExchangeList->First();
998         while( pString )
999         {
1000             delete pString;
1001             pString = (String*) rpExchangeList->Next();
1002         }
1003         delete rpExchangeList;
1004         rpExchangeList = NULL;
1005     }
1006 
1007     return( bNameOK );
1008 }
1009 
1010 typedef std::vector< std::pair< sal_uInt32, sal_uInt32 > > PathSurrogateVector;
1011 typedef std::vector< SdrObject* > SdrObjectVector;
1012 
1013 void ImplProcessObjectList(SdrObject* pObj, SdrObjectVector& rVector )
1014 {
1015     sal_Bool bIsGroup(pObj->IsGroupObject());
1016     if(bIsGroup && pObj->ISA(E3dObject) && !pObj->ISA(E3dScene))
1017         bIsGroup = sal_False;
1018 
1019     rVector.push_back( pObj );
1020 
1021     if(bIsGroup)
1022     {
1023         SdrObjList* pObjList = pObj->GetSubList();
1024         sal_uInt32 a;
1025         for( a = 0; a < pObjList->GetObjCount(); a++)
1026             ImplProcessObjectList(pObjList->GetObj(a), rVector);
1027     }
1028 }
1029 
1030 SdrModel* View::GetMarkedObjModel() const
1031 {
1032     return FmFormView::GetMarkedObjModel();;
1033 }
1034 
1035 sal_Bool View::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst /* =NULL */, sal_uInt32 nOptions /* =0 */)
1036 {
1037     return FmFormView::Paste( rMod, rPos, pLst,nOptions );;
1038 }
1039 
1040 } // end of namespace sd
1041