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