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 : ::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( (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 ? ( (SdPage*) pPgView->GetPage() ) : NULL;
117 0 : SdPage* pNewPage = (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) && ((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( ((SdrOle2Obj*)pObj)->GetObjRef(), uno::UNO_QUERY );
135 0 : if ( xPersObj.is() && xPersObj->hasEntry() )
136 0 : pSdrOleObj = (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 ) && ( (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( ((SdrOle2Obj*)pObj)->GetObjRef(), uno::UNO_QUERY );
181 0 : if ( xPersObj.is() && xPersObj->hasEntry() )
182 0 : pSdrOleObj = (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 2 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > View::CreateSelectionDataObject( View* pWorkView, vcl::Window& rWindow )
210 : {
211 2 : SdTransferable* pTransferable = new SdTransferable( &mrDoc, pWorkView, true );
212 2 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRet( pTransferable );
213 4 : TransferableObjectDescriptor aObjDesc;
214 2 : const Rectangle aMarkRect( GetAllMarkedRect() );
215 4 : OUString aDisplayName;
216 :
217 2 : SD_MOD()->pTransferSelection = pTransferable;
218 :
219 2 : if( mpDocSh )
220 : {
221 2 : aDisplayName = mpDocSh->GetMedium()->GetURLObject().GetURLNoPass();
222 2 : mpDocSh->FillTransferableObjectDescriptor( aObjDesc );
223 : }
224 :
225 2 : aObjDesc.maSize = aMarkRect.GetSize();
226 :
227 2 : pTransferable->SetStartPos( aMarkRect.TopLeft() );
228 2 : pTransferable->SetObjectDescriptor( aObjDesc );
229 2 : pTransferable->CopyToSelection( &rWindow );
230 :
231 4 : return xRet;
232 : }
233 :
234 782 : void View::UpdateSelectionClipboard( bool bForceDeselect )
235 : {
236 782 : if( mpViewSh && mpViewSh->GetActiveWindow() )
237 : {
238 552 : if( !bForceDeselect && GetMarkedObjectList().GetMarkCount() )
239 2 : CreateSelectionDataObject( this, *mpViewSh->GetActiveWindow() );
240 550 : else if( SD_MOD()->pTransferSelection && ( SD_MOD()->pTransferSelection->GetView() == this ) )
241 : {
242 2 : TransferableHelper::ClearSelection( mpViewSh->GetActiveWindow() );
243 2 : SD_MOD()->pTransferSelection = NULL;
244 : }
245 : }
246 782 : }
247 :
248 0 : void View::DoCut(vcl::Window* )
249 : {
250 0 : const OutlinerView* pOLV = GetTextEditOutlinerView();
251 :
252 0 : if( pOLV )
253 0 : ( (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 : ( (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 = (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 = (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( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
344 0 : aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
345 0 : ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
346 0 : aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
347 0 : ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
348 0 : aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_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( SOT_FORMATSTR_ID_DRAWING );
516 0 : const bool bGraphic = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB );
517 0 : const bool bMtf = rTargetHelper.IsDropFormatSupported( FORMAT_GDIMETAFILE );
518 0 : const bool bBitmap = rTargetHelper.IsDropFormatSupported( FORMAT_BITMAP );
519 0 : bool bBookmark = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
520 0 : bool bXFillExchange = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_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 = (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( SOT_FORMATSTR_ID_SVX_FORMFIELDEXCH );
588 0 : const bool bEditEngine = rTargetHelper.IsDropFormatSupported( SOT_FORMATSTR_ID_EDITENGINE );
589 0 : const bool bString = rTargetHelper.IsDropFormatSupported( FORMAT_STRING );
590 0 : const bool bRTF = rTargetHelper.IsDropFormatSupported( FORMAT_RTF );
591 0 : const bool bFile = rTargetHelper.IsDropFormatSupported( FORMAT_FILE );
592 0 : const bool bFileList = rTargetHelper.IsDropFormatSupported( FORMAT_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( SOT_FORMATSTR_ID_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 : SotStorageStreamRef xStm;
690 :
691 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_XFA, xStm ) && xStm.Is() )
692 : {
693 0 : XFillExchangeData aFillData( XFillAttrSetItem( &mrDoc.GetPool() ) );
694 :
695 0 : ReadXFillExchangeData( *xStm, aFillData );
696 0 : const Color aColor( ( (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, 0, 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( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
717 0 : aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_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 0 : bool bCreated = false;
742 :
743 0 : if( !aBookmark.isEmpty() )
744 : {
745 0 : presentation::ClickAction eClickAction = presentation::ClickAction_DOCUMENT;
746 :
747 0 : sal_Int32 nIndex = aBookmark.indexOf( (sal_Unicode)'#' );
748 0 : if( nIndex != -1 )
749 : {
750 0 : const OUString aDocName( aBookmark.copy( 0, nIndex ) );
751 :
752 0 : if (mpDocSh->GetMedium()->GetName() == aDocName || aDocName.equals(mpDocSh->GetName()))
753 : {
754 : // internal jump, only use the part after and including '#'
755 0 : eClickAction = presentation::ClickAction_BOOKMARK;
756 0 : aBookmark = aBookmark.copy( nIndex+1 );
757 0 : }
758 : }
759 :
760 0 : if( !pInfo )
761 : {
762 0 : pInfo = SdDrawDocument::GetShapeUserData( *pPickObj, true );
763 0 : bCreated = true;
764 : }
765 :
766 : // create undo action with old and new sizes
767 0 : SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction(&mrDoc, pPickObj, bCreated);
768 0 : pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
769 0 : pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
770 0 : pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
771 0 : pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
772 0 : pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
773 0 : pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
774 0 : pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
775 0 : pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
776 0 : pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
777 0 : pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
778 0 : pAction->SetPathObj(pInfo->mpPathObj, pInfo->mpPathObj);
779 0 : pAction->SetClickAction(pInfo->meClickAction, eClickAction);
780 0 : pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
781 0 : pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
782 0 : pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
783 0 : pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
784 0 : pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
785 0 : pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
786 :
787 0 : OUString aString(SdResId(STR_UNDO_ANIMATION));
788 0 : pAction->SetComment(aString);
789 0 : mpDocSh->GetUndoManager()->AddUndoAction(pAction);
790 0 : pInfo->meClickAction = eClickAction;
791 0 : pInfo->SetBookmark( aBookmark );
792 0 : mrDoc.SetChanged();
793 :
794 0 : nRet = nDropAction;
795 0 : }
796 : }
797 0 : else if( mpViewSh->ISA( DrawViewShell ) )
798 : {
799 : // insert as normal URL button
800 0 : ( (DrawViewShell*) mpViewSh )->InsertURLButton( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), OUString(), &aPos );
801 0 : nRet = nDropAction;
802 : }
803 : }
804 0 : }
805 0 : }
806 : }
807 : }
808 :
809 0 : return nRet;
810 : }
811 :
812 0 : IMPL_LINK( View, ExecuteNavigatorDrop, SdNavigatorDropEvent*, pSdNavigatorDropEvent )
813 : {
814 0 : TransferableDataHelper aDataHelper( pSdNavigatorDropEvent->maDropEvent.Transferable );
815 0 : SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
816 0 : INetBookmark aINetBookmark;
817 :
818 0 : if( pPageObjsTransferable && aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) )
819 : {
820 0 : Point aPos;
821 0 : OUString aBookmark;
822 0 : SdPage* pPage = (SdPage*) GetSdrPageView()->GetPage();
823 0 : sal_uInt16 nPgPos = 0xFFFF;
824 :
825 0 : if( pSdNavigatorDropEvent->mpTargetWindow )
826 0 : aPos = pSdNavigatorDropEvent->mpTargetWindow->PixelToLogic( pSdNavigatorDropEvent->maPosPixel );
827 :
828 0 : const OUString aURL( aINetBookmark.GetURL() );
829 0 : sal_Int32 nIndex = aURL.indexOf( (sal_Unicode)'#' );
830 0 : if( nIndex != -1 )
831 0 : aBookmark = aURL.copy( nIndex+1 );
832 :
833 0 : std::vector<OUString> aExchangeList;
834 0 : std::vector<OUString> aBookmarkList(1,aBookmark);
835 :
836 0 : if( !pPage->IsMasterPage() )
837 : {
838 0 : if( pPage->GetPageKind() == PK_STANDARD )
839 0 : nPgPos = pPage->GetPageNum() + 2;
840 0 : else if( pPage->GetPageKind() == PK_NOTES )
841 0 : nPgPos = pPage->GetPageNum() + 1;
842 : }
843 :
844 : /* In order t ensure unique page names, we test the ones we want to
845 : insert. If necessary. we put them into and replacement list (bNameOK
846 : == sal_False -> User canceled). */
847 0 : bool bLink = ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ? sal_True : sal_False );
848 0 : bool bNameOK = GetExchangeList( aExchangeList, aBookmarkList, 2 );
849 0 : bool bReplace = false;
850 :
851 : /* Since we don't know the type (page or object), we fill a list with
852 : pages and objects.
853 : Of course we have problems if there are pages and objects with the
854 : same name!!! */
855 0 : if( bNameOK )
856 : {
857 : mrDoc.InsertBookmark( aBookmarkList, aExchangeList,
858 : bLink, bReplace, nPgPos, false,
859 0 : &pPageObjsTransferable->GetDocShell(),
860 0 : true, &aPos );
861 0 : }
862 : }
863 :
864 0 : delete pSdNavigatorDropEvent;
865 :
866 0 : return 0;
867 : }
868 :
869 0 : bool View::GetExchangeList (std::vector<OUString> &rExchangeList,
870 : std::vector<OUString> &rBookmarkList,
871 : const sal_uInt16 nType)
872 : {
873 : assert(rExchangeList.empty());
874 :
875 0 : bool bListIdentical = true; ///< Bookmark list and exchange list are identical
876 0 : bool bNameOK = true; ///< name is unique
877 :
878 0 : std::vector<OUString>::const_iterator pIter;
879 0 : for ( pIter = rBookmarkList.begin(); bNameOK && pIter != rBookmarkList.end(); ++pIter )
880 : {
881 0 : OUString aNewName = *pIter;
882 :
883 0 : if( nType == 0 || nType == 2 )
884 0 : bNameOK = mpDocSh->CheckPageName(mpViewSh->GetActiveWindow(), aNewName);
885 :
886 0 : if( bNameOK && ( nType == 1 || nType == 2 ) )
887 : {
888 0 : if( mrDoc.GetObj( aNewName ) )
889 : {
890 0 : OUString aTitle(SD_RESSTR(STR_TITLE_NAMEGROUP));
891 0 : OUString aDesc(SD_RESSTR(STR_DESC_NAMEGROUP));
892 :
893 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
894 0 : boost::scoped_ptr<AbstractSvxNameDialog> pDlg;
895 :
896 0 : if (pFact)
897 0 : pDlg.reset(pFact->CreateSvxNameDialog( mpViewSh->GetActiveWindow(), aNewName, aDesc ));
898 :
899 0 : if( pDlg )
900 : {
901 0 : pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_OBJECT );
902 :
903 0 : bNameOK = false;
904 0 : pDlg->SetText( aTitle );
905 :
906 0 : while( !bNameOK && pDlg->Execute() == RET_OK )
907 : {
908 0 : pDlg->GetName( aNewName );
909 :
910 0 : if( !mrDoc.GetObj( aNewName ) )
911 0 : bNameOK = true;
912 : }
913 0 : }
914 : }
915 : }
916 :
917 0 : bListIdentical = pIter->equals(aNewName);
918 :
919 0 : rExchangeList.push_back(aNewName);
920 0 : }
921 :
922 : // Exchange list is identical to bookmark list
923 0 : if( !rExchangeList.empty() && bListIdentical )
924 0 : rExchangeList.clear();
925 :
926 0 : return bNameOK;
927 : }
928 :
929 : typedef std::vector< SdrObject* > SdrObjectVector;
930 :
931 0 : void ImplProcessObjectList(SdrObject* pObj, SdrObjectVector& rVector )
932 : {
933 0 : bool bIsGroup(pObj->IsGroupObject());
934 0 : if(bIsGroup && pObj->ISA(E3dObject) && !pObj->ISA(E3dScene))
935 0 : bIsGroup = false;
936 :
937 0 : rVector.push_back( pObj );
938 :
939 0 : if(bIsGroup)
940 : {
941 0 : SdrObjList* pObjList = pObj->GetSubList();
942 0 : for( size_t a = 0; a < pObjList->GetObjCount(); ++a)
943 0 : ImplProcessObjectList(pObjList->GetObj(a), rVector);
944 : }
945 0 : }
946 :
947 0 : SdrModel* View::GetMarkedObjModel() const
948 : {
949 0 : return FmFormView::GetMarkedObjModel();;
950 : }
951 :
952 0 : bool View::Paste(
953 : const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions,
954 : const OUString& rSrcShellID, const OUString& rDestShellID )
955 : {
956 0 : return FmFormView::Paste(rMod, rPos, pLst, nOptions, rSrcShellID, rDestShellID);
957 : }
958 :
959 114 : } // end of namespace sd
960 :
961 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|