Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "View.hxx"
21 :
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>
45 :
46 : #include <sfx2/objsh.hxx>
47 : #include <svtools/embedtransfer.hxx>
48 :
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>
66 :
67 : #include "slideshow.hxx"
68 : #include <boost/scoped_ptr.hpp>
69 :
70 : namespace sd {
71 :
72 : using namespace ::com::sun::star;
73 :
74 : // - SdNavigatorDropEvent -
75 :
76 0 : struct SdNavigatorDropEvent : public ExecuteDropEvent
77 : {
78 : DropTargetHelper& mrTargetHelper;
79 : VclPtr< ::sd::Window> mpTargetWindow;
80 : sal_uInt16 mnPage;
81 : sal_uInt16 mnLayer;
82 :
83 0 : 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 0 : mnLayer( nLayer )
94 0 : {}
95 : };
96 :
97 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateClipboardDataObject( View*, vcl::Window& )
98 : {
99 : // since SdTransferable::CopyToClipboard is called, this
100 : // dynamically created object ist destroyed automatically
101 0 : SdTransferable* pTransferable = new SdTransferable( &mrDoc, NULL, false );
102 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
103 :
104 0 : SD_MOD()->pTransferClip = pTransferable;
105 :
106 0 : mrDoc.CreatingDataObj( pTransferable );
107 0 : pTransferable->SetWorkDocument( static_cast<SdDrawDocument*>(GetMarkedObjModel()) );
108 0 : mrDoc.CreatingDataObj( NULL );
109 :
110 : // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
111 : // fat lines correctly
112 0 : const Rectangle aMarkRect( GetAllMarkedBoundRect() );
113 0 : TransferableObjectDescriptor aObjDesc;
114 0 : SdrOle2Obj* pSdrOleObj = NULL;
115 0 : SdrPageView* pPgView = GetSdrPageView();
116 0 : SdPage* pOldPage = pPgView ? static_cast<SdPage*>( pPgView->GetPage() ) : NULL;
117 0 : SdPage* pNewPage = const_cast<SdPage*>(static_cast<const SdPage*>( pTransferable->GetWorkDocument()->GetPage( 0 ) ));
118 :
119 0 : if( pOldPage )
120 : {
121 0 : pNewPage->SetSize( pOldPage->GetSize() );
122 0 : pNewPage->SetLayoutName( pOldPage->GetLayoutName() );
123 : }
124 :
125 0 : if( GetMarkedObjectCount() == 1 )
126 : {
127 0 : SdrObject* pObj = GetMarkedObjectByIndex(0);
128 :
129 0 : if( pObj && pObj->ISA(SdrOle2Obj) && static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
130 : {
131 : // If object has no persistence it must be copied as part of the document
132 : try
133 : {
134 0 : uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObj)->GetObjRef(), uno::UNO_QUERY );
135 0 : if ( xPersObj.is() && xPersObj->hasEntry() )
136 0 : pSdrOleObj = static_cast<SdrOle2Obj*>(pObj);
137 : }
138 0 : catch( uno::Exception& )
139 : {}
140 : }
141 : }
142 :
143 0 : if( pSdrOleObj )
144 0 : SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
145 : else
146 0 : pTransferable->GetWorkDocument()->GetDocSh()->FillTransferableObjectDescriptor( aObjDesc );
147 :
148 0 : if( mpDocSh )
149 0 : aObjDesc.maDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
150 :
151 0 : aObjDesc.maSize = aMarkRect.GetSize();
152 :
153 0 : pTransferable->SetStartPos( aMarkRect.TopLeft() );
154 0 : pTransferable->SetObjectDescriptor( aObjDesc );
155 0 : pTransferable->CopyToClipboard( mpViewSh->GetActiveWindow() );
156 :
157 0 : return xRet;
158 : }
159 :
160 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateDragDataObject( View* pWorkView, vcl::Window& rWindow, const Point& rDragPos )
161 : {
162 0 : SdTransferable* pTransferable = new SdTransferable( &mrDoc, pWorkView, false );
163 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
164 :
165 0 : SD_MOD()->pTransferDrag = pTransferable;
166 :
167 0 : TransferableObjectDescriptor aObjDesc;
168 0 : OUString aDisplayName;
169 0 : SdrOle2Obj* pSdrOleObj = NULL;
170 :
171 0 : if( GetMarkedObjectCount() == 1 )
172 : {
173 0 : SdrObject* pObj = GetMarkedObjectByIndex( 0 );
174 :
175 0 : if( pObj && pObj->ISA( SdrOle2Obj ) && static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
176 : {
177 : // If object has no persistence it must be copied as part of the document
178 : try
179 : {
180 0 : uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObj)->GetObjRef(), uno::UNO_QUERY );
181 0 : if ( xPersObj.is() && xPersObj->hasEntry() )
182 0 : pSdrOleObj = static_cast<SdrOle2Obj*>(pObj);
183 : }
184 0 : catch( uno::Exception& )
185 : {}
186 : }
187 : }
188 :
189 0 : if( mpDocSh )
190 0 : aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
191 :
192 0 : if( pSdrOleObj )
193 0 : SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pSdrOleObj->GetObjRef(), pSdrOleObj->GetGraphic(), pSdrOleObj->GetAspect() );
194 0 : else if (mpDocSh)
195 0 : mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
196 :
197 0 : aObjDesc.maSize = GetAllMarkedRect().GetSize();
198 0 : aObjDesc.maDragStartPos = rDragPos;
199 0 : aObjDesc.maDisplayName = aDisplayName;
200 0 : aObjDesc.mbCanLink = false;
201 :
202 0 : pTransferable->SetStartPos( rDragPos );
203 0 : pTransferable->SetObjectDescriptor( aObjDesc );
204 0 : pTransferable->StartDrag( &rWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
205 :
206 0 : return xRet;
207 : }
208 :
209 6 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateSelectionDataObject( View* pWorkView, vcl::Window& rWindow )
210 : {
211 6 : SdTransferable* pTransferable = new SdTransferable( &mrDoc, pWorkView, true );
212 6 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
213 12 : TransferableObjectDescriptor aObjDesc;
214 6 : const Rectangle aMarkRect( GetAllMarkedRect() );
215 12 : OUString aDisplayName;
216 :
217 6 : SD_MOD()->pTransferSelection = pTransferable;
218 :
219 6 : if( mpDocSh )
220 : {
221 6 : aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
222 6 : mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
223 : }
224 :
225 6 : aObjDesc.maSize = aMarkRect.GetSize();
226 :
227 6 : pTransferable->SetStartPos( aMarkRect.TopLeft() );
228 6 : pTransferable->SetObjectDescriptor( aObjDesc );
229 6 : pTransferable->CopyToSelection( &rWindow );
230 :
231 12 : return xRet;
232 : }
233 :
234 464 : void View::UpdateSelectionClipboard( bool bForceDeselect )
235 : {
236 464 : if( mpViewSh && mpViewSh->GetActiveWindow() )
237 : {
238 338 : if( !bForceDeselect && GetMarkedObjectList().GetMarkCount() )
239 6 : CreateSelectionDataObject( this, *mpViewSh->GetActiveWindow() );
240 332 : else if( SD_MOD()->pTransferSelection && ( SD_MOD()->pTransferSelection->GetView() == this ) )
241 : {
242 6 : TransferableHelper::ClearSelection( mpViewSh->GetActiveWindow() );
243 6 : SD_MOD()->pTransferSelection = NULL;
244 : }
245 : }
246 464 : }
247 :
248 0 : void View::DoCut(vcl::Window* )
249 : {
250 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
251 :
252 0 : if( pOLV )
253 0 : const_cast<OutlinerView*>(pOLV)->Cut();
254 0 : else if( AreObjectsMarked() )
255 : {
256 0 : OUString aStr(SD_RESSTR(STR_UNDO_CUT));
257 :
258 0 : DoCopy();
259 0 : BegUndo(aStr + " " + GetDescriptionOfMarkedObjects());
260 0 : DeleteMarked();
261 0 : EndUndo();
262 : }
263 0 : }
264 :
265 0 : void View::DoCopy (vcl::Window* pWindow)
266 : {
267 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
268 :
269 0 : if( pOLV )
270 0 : const_cast<OutlinerView*>(pOLV)->Copy();
271 0 : else if( AreObjectsMarked() )
272 : {
273 0 : BrkAction();
274 0 : CreateClipboardDataObject( this, *pWindow );
275 : }
276 0 : }
277 :
278 0 : void View::DoPaste (vcl::Window* pWindow)
279 : {
280 0 : TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewSh->GetActiveWindow() ) );
281 0 : if( !aDataHelper.GetTransferable().is() )
282 0 : return; // empty clipboard?
283 :
284 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
285 :
286 0 : if( pOLV && EditEngine::HasValidData( aDataHelper.GetTransferable() ) )
287 : {
288 0 : const_cast< OutlinerView* >(pOLV)->PasteSpecial();
289 :
290 0 : SdrObject* pObj = GetTextEditObject();
291 0 : SdPage* pPage = static_cast<SdPage*>( pObj ? pObj->GetPage() : NULL );
292 0 : ::Outliner* pOutliner = pOLV->GetOutliner();
293 :
294 0 : if( pOutliner)
295 : {
296 0 : if( pObj && pPage && pPage->GetPresObjKind(pObj) == PRESOBJ_TITLE )
297 : {
298 : // remove all hard linebreaks from the title
299 0 : if( pOutliner && pOutliner->GetParagraphCount() > 1 )
300 : {
301 0 : bool bOldUpdateMode = pOutliner->GetUpdateMode();
302 :
303 0 : pOutliner->SetUpdateMode( false );
304 :
305 0 : const EditEngine& rEdit = pOutliner->GetEditEngine();
306 0 : const sal_Int32 nParaCount = rEdit.GetParagraphCount();
307 :
308 0 : for( sal_Int32 nPara = nParaCount - 2; nPara >= 0; nPara-- )
309 : {
310 0 : const sal_Int32 nParaLen = rEdit.GetTextLen( nPara );
311 0 : pOutliner->QuickDelete( ESelection( nPara, nParaLen, nPara+1, 0 ) );
312 0 : pOutliner->QuickInsertLineBreak( ESelection( nPara, nParaLen, nPara, nParaLen ) );
313 : }
314 :
315 : DBG_ASSERT( rEdit.GetParagraphCount() <= 1, "Titleobject contains hard line breaks" );
316 0 : pOutliner->SetUpdateMode(bOldUpdateMode);
317 : }
318 : }
319 :
320 0 : if( !mrDoc.IsChanged() )
321 : {
322 0 : if( pOutliner && pOutliner->IsModified() )
323 0 : mrDoc.SetChanged( true );
324 : }
325 : }
326 : }
327 : else
328 : {
329 0 : Point aPos;
330 0 : sal_Int8 nDnDAction = DND_ACTION_COPY;
331 :
332 0 : if( pWindow )
333 0 : aPos = pWindow->PixelToLogic( Rectangle( aPos, pWindow->GetOutputSizePixel() ).Center() );
334 :
335 0 : DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>( mpDocSh->GetViewShell() );
336 :
337 0 : if (pDrViewSh != NULL)
338 : {
339 0 : if( !InsertData( aDataHelper, aPos, nDnDAction, false ) )
340 : {
341 0 : INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
342 :
343 0 : if( ( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
344 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
345 0 : ( aDataHelper.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ) &&
346 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
347 0 : ( aDataHelper.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) &&
348 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
349 : {
350 0 : pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
351 0 : }
352 : }
353 : }
354 0 : }
355 : }
356 :
357 0 : void View::StartDrag( const Point& rStartPos, vcl::Window* pWindow )
358 : {
359 0 : if( AreObjectsMarked() && IsAction() && mpViewSh && pWindow && !mpDragSrcMarkList )
360 : {
361 0 : BrkAction();
362 :
363 0 : if( IsTextEdit() )
364 0 : SdrEndTextEdit();
365 :
366 0 : DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpDocSh ? mpDocSh->GetViewShell() : 0 );
367 :
368 0 : if( pDrawViewShell )
369 : {
370 0 : rtl::Reference<FuPoor> xFunction( pDrawViewShell->GetCurrentFunction() );
371 :
372 0 : if( xFunction.is() && xFunction->ISA( FuDraw ) )
373 0 : static_cast<FuDraw*>(xFunction.get())->ForcePointer( NULL );
374 : }
375 :
376 0 : mpDragSrcMarkList = new SdrMarkList(GetMarkedObjectList());
377 0 : mnDragSrcPgNum = GetSdrPageView()->GetPage()->GetPageNum();
378 :
379 0 : if( IsUndoEnabled() )
380 : {
381 0 : OUString aStr(SD_RESSTR(STR_UNDO_DRAGDROP));
382 0 : BegUndo(aStr + " " + mpDragSrcMarkList->GetMarkDescription());
383 : }
384 0 : CreateDragDataObject( this, *pWindow, rStartPos );
385 : }
386 0 : }
387 :
388 0 : void View::DragFinished( sal_Int8 nDropAction )
389 : {
390 0 : const bool bUndo = IsUndoEnabled();
391 :
392 0 : SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
393 :
394 0 : if( pDragTransferable )
395 0 : pDragTransferable->SetView( NULL );
396 :
397 0 : if( ( nDropAction & DND_ACTION_MOVE ) &&
398 0 : pDragTransferable && !pDragTransferable->IsInternalMove() &&
399 0 : mpDragSrcMarkList && mpDragSrcMarkList->GetMarkCount() &&
400 0 : !IsPresObjSelected() )
401 : {
402 0 : mpDragSrcMarkList->ForceSort();
403 :
404 0 : if( bUndo )
405 0 : BegUndo();
406 :
407 0 : const size_t nAnz = mpDragSrcMarkList->GetMarkCount();
408 :
409 0 : for( size_t nm = nAnz; nm>0; )
410 : {
411 0 : --nm;
412 0 : SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
413 0 : if( bUndo )
414 0 : AddUndo(mrDoc.GetSdrUndoFactory().CreateUndoDeleteObject(*pM->GetMarkedSdrObj()));
415 : }
416 :
417 0 : mpDragSrcMarkList->GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
418 :
419 0 : for (size_t nm = nAnz; nm>0;)
420 : {
421 0 : --nm;
422 0 : SdrMark* pM=mpDragSrcMarkList->GetMark(nm);
423 0 : SdrObject* pObj=pM->GetMarkedSdrObj();
424 :
425 0 : if( pObj && pObj->GetPage() )
426 : {
427 0 : const size_t nOrdNum = pObj->GetOrdNumDirect();
428 : #ifdef DBG_UTIL
429 : SdrObject* pChkObj =
430 : #endif
431 0 : pObj->GetPage()->RemoveObject(nOrdNum);
432 : DBG_ASSERT(pChkObj==pObj,"pChkObj!=pObj in RemoveObject()");
433 : }
434 : }
435 :
436 0 : if( bUndo )
437 0 : EndUndo();
438 : }
439 :
440 0 : if( pDragTransferable )
441 0 : pDragTransferable->SetInternalMove( false );
442 :
443 0 : if( bUndo )
444 0 : EndUndo();
445 0 : mnDragSrcPgNum = SDRPAGE_NOTFOUND;
446 0 : delete mpDragSrcMarkList;
447 0 : mpDragSrcMarkList = NULL;
448 0 : }
449 :
450 0 : sal_Int8 View::AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
451 : ::sd::Window*, sal_uInt16, sal_uInt16 nLayer )
452 : {
453 0 : OUString aLayerName = GetActiveLayer();
454 0 : SdrPageView* pPV = GetSdrPageView();
455 0 : sal_Int8 nDropAction = rEvt.mnAction;
456 0 : sal_Int8 nRet = DND_ACTION_NONE;
457 :
458 0 : if( nLayer != SDRLAYER_NOTFOUND )
459 : {
460 0 : SdrLayerAdmin& rLayerAdmin = mrDoc.GetLayerAdmin();
461 0 : aLayerName = rLayerAdmin.GetLayerPerID(nLayer)->GetName();
462 : }
463 :
464 0 : if( mbIsDropAllowed && !pPV->IsLayerLocked( aLayerName ) && pPV->IsLayerVisible( aLayerName ) )
465 : {
466 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
467 0 : bool bIsInsideOutlinerView = false;
468 :
469 0 : if( pOLV )
470 : {
471 0 : Rectangle aRect( pOLV->GetOutputArea() );
472 :
473 0 : if (GetMarkedObjectCount() == 1)
474 : {
475 0 : SdrMark* pMark = GetSdrMarkByIndex(0);
476 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
477 0 : aRect.Union( pObj->GetLogicRect() );
478 : }
479 :
480 0 : if( aRect.IsInside( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) ) )
481 : {
482 0 : bIsInsideOutlinerView = true;
483 : }
484 : }
485 :
486 0 : if( !bIsInsideOutlinerView )
487 : {
488 0 : SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
489 :
490 0 : if(pDragTransferable && (nDropAction & DND_ACTION_LINK))
491 : {
492 : // suppress own data when it's intention is to use it as fill information
493 0 : pDragTransferable = 0;
494 : }
495 :
496 0 : if( pDragTransferable )
497 : {
498 0 : const View* pSourceView = pDragTransferable->GetView();
499 :
500 0 : if( pDragTransferable->IsPageTransferable() )
501 : {
502 0 : nRet = DND_ACTION_COPY;
503 : }
504 0 : else if( pSourceView )
505 : {
506 0 : if( !( nDropAction & DND_ACTION_LINK ) ||
507 0 : !pSourceView->GetDocSh()->GetMedium()->GetName().isEmpty() )
508 : {
509 0 : nRet = nDropAction;
510 : }
511 : }
512 : }
513 : else
514 : {
515 0 : const bool bDrawing = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::DRAWING );
516 0 : const bool bGraphic = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVXB );
517 0 : const bool bMtf = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::GDIMETAFILE );
518 0 : const bool bBitmap = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::BITMAP );
519 0 : bool bBookmark = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK );
520 0 : bool bXFillExchange = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::XFA );
521 :
522 : // check handle insert
523 0 : if( !nRet && ( (bXFillExchange && ( SDRDRAG_GRADIENT == GetDragMode() )) || ( SDRDRAG_TRANSPARENCE == GetDragMode() ) ) )
524 : {
525 0 : const SdrHdlList& rHdlList = GetHdlList();
526 :
527 0 : for( size_t n = 0; n < rHdlList.GetHdlCount(); ++n )
528 : {
529 0 : SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
530 :
531 0 : if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
532 : {
533 0 : if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
534 : {
535 0 : nRet = nDropAction;
536 0 : static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_SELECTED );
537 : }
538 : else
539 : {
540 0 : static_cast< SdrHdlColor* >( pIAOHandle )->SetSize( SDR_HANDLE_COLOR_SIZE_NORMAL );
541 : }
542 : }
543 : }
544 : }
545 :
546 : // check object insert
547 0 : if( !nRet && ( bXFillExchange || ( ( bDrawing || bGraphic || bMtf || bBitmap || bBookmark ) && ( nDropAction & DND_ACTION_LINK ) ) ) )
548 : {
549 0 : SdrObject* pPickObj = NULL;
550 0 : SdrPageView* pPageView = NULL;
551 0 : ::sd::Window* pWindow = mpViewSh->GetActiveWindow();
552 0 : Point aPos( pWindow->PixelToLogic( rEvt.maPosPixel ) );
553 0 : const bool bHasPickObj = PickObj( aPos, getHitTolLog(), pPickObj, pPageView );
554 0 : bool bIsPresTarget = false;
555 :
556 0 : if( bHasPickObj && pPickObj && ( pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall() ) )
557 : {
558 0 : SdPage* pPage = static_cast<SdPage*>( pPickObj->GetPage() );
559 :
560 0 : if( pPage && pPage->IsMasterPage() )
561 0 : bIsPresTarget = pPage->IsPresObj( pPickObj );
562 : }
563 :
564 0 : if( bHasPickObj && !bIsPresTarget &&
565 0 : ( bGraphic || bMtf || bBitmap || bXFillExchange ) )
566 : {
567 0 : if( mpDropMarkerObj != pPickObj )
568 : {
569 0 : mpDropMarkerObj = pPickObj;
570 0 : ImplClearDrawDropMarker();
571 :
572 0 : if(mpDropMarkerObj)
573 : {
574 0 : mpDropMarker = new SdrDropMarkerOverlay(*this, *mpDropMarkerObj);
575 : }
576 : }
577 :
578 0 : nRet = nDropAction;
579 : }
580 : else
581 0 : bXFillExchange = false;
582 : }
583 :
584 : // check normal insert
585 0 : if( !nRet )
586 : {
587 0 : const bool bSBAFormat = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SVX_FORMFIELDEXCH );
588 0 : const bool bEditEngine = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::EDITENGINE );
589 0 : const bool bString = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::STRING );
590 0 : const bool bRTF = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::RTF );
591 0 : const bool bFile = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE );
592 0 : const bool bFileList = rTargetHelper.IsDropFormatSupported( SotClipboardFormatId::FILE_LIST );
593 :
594 0 : if( mpDropMarker )
595 : {
596 0 : ImplClearDrawDropMarker();
597 0 : mpDropMarkerObj = NULL;
598 : }
599 :
600 0 : if( bBookmark && bFile && ( nDropAction & DND_ACTION_MOVE ) && mpViewSh && SlideShow::IsRunning(mpViewSh->GetViewShellBase()) )
601 0 : bBookmark = false;
602 :
603 0 : if( bDrawing || bGraphic || bMtf || bBitmap || bBookmark || bFile || bFileList || bXFillExchange || bSBAFormat || bEditEngine || bString || bRTF )
604 0 : nRet = nDropAction;
605 :
606 : // For entries from the navigator, change action copy.
607 0 : if (bBookmark
608 0 : && rTargetHelper.IsDropFormatSupported(
609 0 : SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId())
610 0 : && (nDropAction & DND_ACTION_MOVE)!=0)
611 : {
612 0 : nRet = DND_ACTION_COPY;
613 : }
614 : }
615 : }
616 : }
617 : }
618 :
619 : // destroy drop marker if this is a leaving event
620 0 : if( rEvt.mbLeaving && mpDropMarker )
621 : {
622 0 : ImplClearDrawDropMarker();
623 0 : mpDropMarkerObj = NULL;
624 : }
625 :
626 0 : return nRet;
627 : }
628 :
629 0 : sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
630 : ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer )
631 : {
632 0 : SdrPageView* pPV = GetSdrPageView();
633 0 : OUString aActiveLayer = GetActiveLayer();
634 0 : sal_Int8 nDropAction = rEvt.mnAction;
635 0 : sal_Int8 nRet = DND_ACTION_NONE;
636 :
637 : // destroy drop marker if it is shown
638 0 : if( mpDropMarker )
639 : {
640 0 : ImplClearDrawDropMarker();
641 0 : mpDropMarkerObj = NULL;
642 : }
643 :
644 0 : if( !pPV->IsLayerLocked( aActiveLayer ) )
645 : {
646 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
647 0 : bool bIsInsideOutlinerView = false;
648 :
649 0 : if( pOLV )
650 : {
651 0 : Rectangle aRect( pOLV->GetOutputArea() );
652 :
653 0 : if( GetMarkedObjectCount() == 1 )
654 : {
655 0 : SdrMark* pMark = GetSdrMarkByIndex(0);
656 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
657 0 : aRect.Union( pObj->GetLogicRect() );
658 : }
659 :
660 0 : Point aPos( pOLV->GetWindow()->PixelToLogic( rEvt.maPosPixel ) );
661 :
662 0 : if( aRect.IsInside( aPos ) )
663 : {
664 0 : bIsInsideOutlinerView = true;
665 : }
666 : }
667 :
668 0 : if( !bIsInsideOutlinerView )
669 : {
670 0 : Point aPos;
671 0 : TransferableDataHelper aDataHelper( rEvt.maDropEvent.Transferable );
672 :
673 0 : if( pTargetWindow )
674 0 : aPos = pTargetWindow->PixelToLogic( rEvt.maPosPixel );
675 :
676 : // handle insert?
677 0 : if( (!nRet && ( SDRDRAG_GRADIENT == GetDragMode() )) || (( SDRDRAG_TRANSPARENCE == GetDragMode() ) && aDataHelper.HasFormat( SotClipboardFormatId::XFA )) )
678 : {
679 0 : const SdrHdlList& rHdlList = GetHdlList();
680 :
681 0 : for( size_t n = 0; !nRet && n < rHdlList.GetHdlCount(); ++n )
682 : {
683 0 : SdrHdl* pIAOHandle = rHdlList.GetHdl( n );
684 :
685 0 : if( pIAOHandle && ( HDL_COLR == pIAOHandle->GetKind() ) )
686 : {
687 0 : if(pIAOHandle->getOverlayObjectList().isHitPixel(rEvt.maPosPixel))
688 : {
689 0 : ::tools::SvRef<SotStorageStream> xStm;
690 :
691 0 : if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::XFA, xStm ) && xStm.Is() )
692 : {
693 0 : XFillExchangeData aFillData( XFillAttrSetItem( &mrDoc.GetPool() ) );
694 :
695 0 : ReadXFillExchangeData( *xStm, aFillData );
696 0 : const Color aColor( static_cast<const XFillColorItem&>( aFillData.GetXFillAttrSetItem()->GetItemSet().Get( XATTR_FILLCOLOR ) ).GetColorValue() );
697 0 : static_cast< SdrHdlColor* >( pIAOHandle )->SetColor( aColor, true );
698 0 : nRet = nDropAction;
699 0 : }
700 : }
701 : }
702 : }
703 : }
704 :
705 : // standard insert?
706 0 : if( !nRet && InsertData( aDataHelper, aPos, nDropAction, true, SotClipboardFormatId::NONE, nPage, nLayer ) )
707 0 : nRet = nDropAction;
708 :
709 : // special insert?
710 0 : if( !nRet && mpViewSh )
711 : {
712 0 : OUString aTmpString1, aTmpString2;
713 0 : INetBookmark aINetBookmark( aTmpString1, aTmpString2 );
714 :
715 : // insert bookmark
716 0 : if( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
717 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
718 : {
719 0 : SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
720 :
721 0 : if( pPageObjsTransferable &&
722 0 : ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ||
723 0 : NAVIGATOR_DRAGTYPE_EMBEDDED == pPageObjsTransferable->GetDragType() ) )
724 : {
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 0 : nPage, nLayer ) );
729 0 : nRet = nDropAction;
730 : }
731 : else
732 : {
733 0 : SdrObject* pPickObj = NULL;
734 0 : SdrPageView* pPageView = NULL;
735 :
736 0 : if( PickObj( aPos, getHitTolLog(), pPickObj, pPageView ) )
737 : {
738 : // insert as clip action => jump
739 0 : OUString aBookmark( aINetBookmark.GetURL() );
740 0 : SdAnimationInfo* pInfo = mrDoc.GetAnimationInfo( pPickObj );
741 :
742 0 : if( !aBookmark.isEmpty() )
743 : {
744 0 : bool bCreated = false;
745 :
746 0 : presentation::ClickAction eClickAction = presentation::ClickAction_DOCUMENT;
747 :
748 0 : sal_Int32 nIndex = aBookmark.indexOf( (sal_Unicode)'#' );
749 0 : if( nIndex != -1 )
750 : {
751 0 : const OUString aDocName( aBookmark.copy( 0, nIndex ) );
752 :
753 0 : if (mpDocSh->GetMedium()->GetName() == aDocName || aDocName.equals(mpDocSh->GetName()))
754 : {
755 : // internal jump, only use the part after and including '#'
756 0 : eClickAction = presentation::ClickAction_BOOKMARK;
757 0 : aBookmark = aBookmark.copy( nIndex+1 );
758 0 : }
759 : }
760 :
761 0 : if( !pInfo )
762 : {
763 0 : pInfo = SdDrawDocument::GetShapeUserData( *pPickObj, true );
764 0 : bCreated = true;
765 : }
766 :
767 : // create undo action with old and new sizes
768 0 : SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated);
769 0 : pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
770 0 : pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
771 0 : pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
772 0 : pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
773 0 : pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
774 0 : pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
775 0 : pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
776 0 : pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
777 0 : pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
778 0 : pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
779 0 : pAction->SetPathObj(pInfo->mpPathObj, pInfo->mpPathObj);
780 0 : pAction->SetClickAction(pInfo->meClickAction, eClickAction);
781 0 : pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
782 0 : pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
783 0 : pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
784 0 : pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
785 0 : pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
786 0 : pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
787 :
788 0 : OUString aString(SdResId(STR_UNDO_ANIMATION));
789 0 : pAction->SetComment(aString);
790 0 : mpDocSh->GetUndoManager()->AddUndoAction(pAction);
791 0 : pInfo->meClickAction = eClickAction;
792 0 : pInfo->SetBookmark( aBookmark );
793 0 : mrDoc.SetChanged();
794 :
795 0 : nRet = nDropAction;
796 0 : }
797 : }
798 0 : else if( mpViewSh->ISA( DrawViewShell ) )
799 : {
800 : // insert as normal URL button
801 0 : static_cast<DrawViewShell*>( mpViewSh )->InsertURLButton( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), OUString(), &aPos );
802 0 : nRet = nDropAction;
803 : }
804 : }
805 0 : }
806 0 : }
807 : }
808 : }
809 :
810 0 : return nRet;
811 : }
812 :
813 0 : IMPL_LINK( View, ExecuteNavigatorDrop, SdNavigatorDropEvent*, pSdNavigatorDropEvent )
814 : {
815 0 : TransferableDataHelper aDataHelper( pSdNavigatorDropEvent->maDropEvent.Transferable );
816 0 : SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
817 0 : INetBookmark aINetBookmark;
818 :
819 0 : if( pPageObjsTransferable && aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) )
820 : {
821 0 : Point aPos;
822 0 : OUString aBookmark;
823 0 : SdPage* pPage = static_cast<SdPage*>( GetSdrPageView()->GetPage() );
824 0 : sal_uInt16 nPgPos = 0xFFFF;
825 :
826 0 : if( pSdNavigatorDropEvent->mpTargetWindow )
827 0 : aPos = pSdNavigatorDropEvent->mpTargetWindow->PixelToLogic( pSdNavigatorDropEvent->maPosPixel );
828 :
829 0 : const OUString aURL( aINetBookmark.GetURL() );
830 0 : sal_Int32 nIndex = aURL.indexOf( (sal_Unicode)'#' );
831 0 : if( nIndex != -1 )
832 0 : aBookmark = aURL.copy( nIndex+1 );
833 :
834 0 : std::vector<OUString> aExchangeList;
835 0 : std::vector<OUString> aBookmarkList(1,aBookmark);
836 :
837 0 : if( !pPage->IsMasterPage() )
838 : {
839 0 : if( pPage->GetPageKind() == PK_STANDARD )
840 0 : nPgPos = pPage->GetPageNum() + 2;
841 0 : else if( pPage->GetPageKind() == PK_NOTES )
842 0 : nPgPos = pPage->GetPageNum() + 1;
843 : }
844 :
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 0 : bool bLink = pPageObjsTransferable->GetDragType() == NAVIGATOR_DRAGTYPE_LINK;
849 0 : bool bNameOK = GetExchangeList( aExchangeList, aBookmarkList, 2 );
850 0 : bool bReplace = false;
851 :
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 0 : if( bNameOK )
857 : {
858 : mrDoc.InsertBookmark( aBookmarkList, aExchangeList,
859 : bLink, bReplace, nPgPos, false,
860 0 : &pPageObjsTransferable->GetDocShell(),
861 0 : true, &aPos );
862 0 : }
863 : }
864 :
865 0 : delete pSdNavigatorDropEvent;
866 :
867 0 : return 0;
868 : }
869 :
870 0 : bool View::GetExchangeList (std::vector<OUString> &rExchangeList,
871 : std::vector<OUString> &rBookmarkList,
872 : const sal_uInt16 nType)
873 : {
874 : assert(rExchangeList.empty());
875 :
876 0 : bool bListIdentical = true; ///< Bookmark list and exchange list are identical
877 0 : bool bNameOK = true; ///< name is unique
878 :
879 0 : std::vector<OUString>::const_iterator pIter;
880 0 : for ( pIter = rBookmarkList.begin(); bNameOK && pIter != rBookmarkList.end(); ++pIter )
881 : {
882 0 : OUString aNewName = *pIter;
883 :
884 0 : if( nType == 0 || nType == 2 )
885 0 : bNameOK = mpDocSh->CheckPageName(mpViewSh->GetActiveWindow(), aNewName);
886 :
887 0 : if( bNameOK && ( nType == 1 || nType == 2 ) )
888 : {
889 0 : if( mrDoc.GetObj( aNewName ) )
890 : {
891 0 : OUString aTitle(SD_RESSTR(STR_TITLE_NAMEGROUP));
892 0 : OUString aDesc(SD_RESSTR(STR_DESC_NAMEGROUP));
893 :
894 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
895 0 : boost::scoped_ptr<AbstractSvxNameDialog> pDlg;
896 :
897 0 : if (pFact)
898 0 : pDlg.reset(pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), aNewName, aDesc ));
899 :
900 0 : if( pDlg )
901 : {
902 0 : pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_OBJECT );
903 :
904 0 : bNameOK = false;
905 0 : pDlg->SetText( aTitle );
906 :
907 0 : while( !bNameOK && pDlg->Execute() == RET_OK )
908 : {
909 0 : pDlg->GetName( aNewName );
910 :
911 0 : if( !mrDoc.GetObj( aNewName ) )
912 0 : bNameOK = true;
913 : }
914 0 : }
915 : }
916 : }
917 :
918 0 : bListIdentical = pIter->equals(aNewName);
919 :
920 0 : rExchangeList.push_back(aNewName);
921 0 : }
922 :
923 : // Exchange list is identical to bookmark list
924 0 : if( !rExchangeList.empty() && bListIdentical )
925 0 : rExchangeList.clear();
926 :
927 0 : return bNameOK;
928 : }
929 :
930 : typedef std::vector< SdrObject* > SdrObjectVector;
931 :
932 0 : void ImplProcessObjectList(SdrObject* pObj, SdrObjectVector& rVector )
933 : {
934 0 : bool bIsGroup(pObj->IsGroupObject());
935 0 : if(bIsGroup && pObj->ISA(E3dObject) && !pObj->ISA(E3dScene))
936 0 : bIsGroup = false;
937 :
938 0 : rVector.push_back( pObj );
939 :
940 0 : if(bIsGroup)
941 : {
942 0 : SdrObjList* pObjList = pObj->GetSubList();
943 0 : for( size_t a = 0; a < pObjList->GetObjCount(); ++a)
944 0 : ImplProcessObjectList(pObjList->GetObj(a), rVector);
945 : }
946 0 : }
947 :
948 0 : SdrModel* View::GetMarkedObjModel() const
949 : {
950 0 : return FmFormView::GetMarkedObjModel();;
951 : }
952 :
953 0 : bool View::Paste(
954 : const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, SdrInsertFlags nOptions,
955 : const OUString& rSrcShellID, const OUString& rDestShellID )
956 : {
957 0 : return FmFormView::Paste(rMod, rPos, pLst, nOptions, rSrcShellID, rDestShellID);
958 : }
959 :
960 66 : } // end of namespace sd
961 :
962 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|