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