2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-30 12:23:25 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2012-11-30 12:23:25 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2012-11-30 12:23:25 +00:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2012-11-30 12:23:25 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2005-03-15 10:44:26 +00:00
|
|
|
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <svx/svditer.hxx>
|
|
|
|
#include <svx/svdograf.hxx>
|
|
|
|
#include <svx/svdoole2.hxx>
|
|
|
|
#include <svx/svdouno.hxx>
|
|
|
|
#include <svx/svdpage.hxx>
|
|
|
|
#include <svx/svdpagv.hxx>
|
|
|
|
#include <svx/svdundo.hxx>
|
|
|
|
#include <svx/xbtmpit.hxx>
|
|
|
|
#include <svx/xoutbmp.hxx>
|
2014-07-10 13:33:32 -04:00
|
|
|
#include <svtools/embedhlp.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <sfx2/objsh.hxx>
|
|
|
|
#include <sfx2/viewfrm.hxx>
|
2004-10-04 19:28:15 +00:00
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
|
|
|
#include <com/sun/star/embed/Aspects.hpp>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-10-22 15:58:57 +03:00
|
|
|
#include "document.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "viewfunc.hxx"
|
|
|
|
#include "tabvwsh.hxx"
|
|
|
|
#include "drawview.hxx"
|
|
|
|
#include "scmod.hxx"
|
|
|
|
#include "drwlayer.hxx"
|
2001-03-30 18:14:44 +00:00
|
|
|
#include "drwtrans.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "globstr.hrc"
|
2010-08-03 20:18:36 +02:00
|
|
|
#include "chartlis.hxx"
|
|
|
|
#include "docuno.hxx"
|
|
|
|
#include "docsh.hxx"
|
|
|
|
#include "convuno.hxx"
|
2011-08-29 20:40:42 -04:00
|
|
|
#include "dragdata.hxx"
|
2014-05-19 16:00:39 -04:00
|
|
|
#include <gridwin.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
extern Point aDragStartDiff;
|
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool bPasteIsMove = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-10-04 19:28:15 +00:00
|
|
|
using namespace com::sun::star;
|
|
|
|
|
2012-10-12 13:26:46 +02:00
|
|
|
static void lcl_AdjustInsertPos( ScViewData* pData, Point& rPos, Size& rSize )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2004-06-04 11:11:03 +00:00
|
|
|
SdrPage* pPage = pData->GetScDrawView()->GetModel()->GetPage( static_cast<sal_uInt16>(pData->GetTabNo()) );
|
2011-05-21 15:04:26 +02:00
|
|
|
OSL_ENSURE(pPage,"pPage ???");
|
2000-09-18 16:07:07 +00:00
|
|
|
Size aPgSize( pPage->GetSize() );
|
2004-02-03 12:08:03 +00:00
|
|
|
if (aPgSize.Width() < 0)
|
|
|
|
aPgSize.Width() = -aPgSize.Width();
|
2000-09-18 16:07:07 +00:00
|
|
|
long x = aPgSize.Width() - rPos.X() - rSize.Width();
|
|
|
|
long y = aPgSize.Height() - rPos.Y() - rSize.Height();
|
2013-02-21 02:36:00 +01:00
|
|
|
// if necessary: adjustments (80/200) for pixel approx. errors
|
2000-09-18 16:07:07 +00:00
|
|
|
if( x < 0 )
|
|
|
|
rPos.X() += x + 80;
|
|
|
|
if( y < 0 )
|
|
|
|
rPos.Y() += y + 200;
|
2013-03-03 17:11:39 +01:00
|
|
|
rPos.X() += rSize.Width() / 2; // position at paste is center
|
2000-09-18 16:07:07 +00:00
|
|
|
rPos.Y() += rSize.Height() / 2;
|
|
|
|
}
|
|
|
|
|
2001-10-25 16:46:44 +00:00
|
|
|
void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel,
|
2014-06-13 11:12:50 -04:00
|
|
|
bool bGroup, const OUString& rSrcShellID, const OUString& rDestShellID )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2014-06-13 11:12:50 -04:00
|
|
|
bool bSameDocClipboard = rSrcShellID == rDestShellID;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
MakeDrawLayer();
|
|
|
|
Point aPos( rLogicPos );
|
|
|
|
|
2013-02-21 02:36:00 +01:00
|
|
|
// MapMode at Outliner-RefDevice has to be right (as in FuText::MakeOutliner)
|
|
|
|
//! merge with FuText::MakeOutliner?
|
2000-09-18 16:07:07 +00:00
|
|
|
MapMode aOldMapMode;
|
2014-06-18 12:14:29 +02:00
|
|
|
OutputDevice* pRef = GetViewData().GetDocument()->GetDrawLayer()->GetRefDevice();
|
2000-09-18 16:07:07 +00:00
|
|
|
if (pRef)
|
|
|
|
{
|
|
|
|
aOldMapMode = pRef->GetMapMode();
|
|
|
|
pRef->SetMapMode( MapMode(MAP_100TH_MM) );
|
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
bool bNegativePage = GetViewData().GetDocument()->IsNegativePage( GetViewData().GetTabNo() );
|
2004-02-03 12:08:03 +00:00
|
|
|
|
2001-03-30 18:14:44 +00:00
|
|
|
SdrView* pDragEditView = NULL;
|
|
|
|
ScModule* pScMod = SC_MOD();
|
|
|
|
const ScDragData& rData = pScMod->GetDragData();
|
|
|
|
ScDrawTransferObj* pDrawTrans = rData.pDrawTransfer;
|
|
|
|
if (pDrawTrans)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-03-30 18:14:44 +00:00
|
|
|
pDragEditView = pDrawTrans->GetDragSourceView();
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
aPos -= aDragStartDiff;
|
2004-02-03 12:08:03 +00:00
|
|
|
if ( bNegativePage )
|
|
|
|
{
|
|
|
|
if (aPos.X() > 0) aPos.X() = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (aPos.X() < 0) aPos.X() = 0;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
if (aPos.Y() < 0) aPos.Y() = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-27 13:01:33 +00:00
|
|
|
ScDrawView* pScDrawView = GetScDrawView();
|
2000-09-18 16:07:07 +00:00
|
|
|
if (bGroup)
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->BegUndo( ScGlobal::GetRscString( STR_UNDO_PASTE ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool bSameDoc = ( pDragEditView && pDragEditView->GetModel() == pScDrawView->GetModel() );
|
2000-09-18 16:07:07 +00:00
|
|
|
if (bSameDoc)
|
|
|
|
{
|
2013-02-21 02:36:00 +01:00
|
|
|
// copy locally - incl. charts
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
Point aSourceStart = pDragEditView->GetAllMarkedRect().TopLeft();
|
|
|
|
long nDiffX = aPos.X() - aSourceStart.X();
|
|
|
|
long nDiffY = aPos.Y() - aSourceStart.Y();
|
|
|
|
|
2013-02-21 02:36:00 +01:00
|
|
|
// move within a page?
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if ( bPasteIsMove &&
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->GetSdrPageView()->GetPage() ==
|
2006-11-14 15:00:57 +00:00
|
|
|
pDragEditView->GetSdrPageView()->GetPage() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-12-12 20:32:40 +00:00
|
|
|
if ( nDiffX != 0 || nDiffY != 0 )
|
2011-03-10 16:55:21 -05:00
|
|
|
pDragEditView->MoveAllMarked(Size(nDiffX,nDiffY), false);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-27 13:01:33 +00:00
|
|
|
SdrModel* pDrawModel = pDragEditView->GetModel();
|
2014-06-18 12:14:29 +02:00
|
|
|
SCTAB nTab = GetViewData().GetTabNo();
|
2010-08-03 20:18:36 +02:00
|
|
|
SdrPage* pDestPage = pDrawModel->GetPage( static_cast< sal_uInt16 >( nTab ) );
|
2013-02-21 02:36:00 +01:00
|
|
|
OSL_ENSURE(pDestPage,"who is this, Page?");
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString > aExcludedChartNames;
|
2010-08-03 20:18:36 +02:00
|
|
|
if ( pDestPage )
|
|
|
|
{
|
|
|
|
ScChartHelper::GetChartNames( aExcludedChartNames, pDestPage );
|
|
|
|
}
|
|
|
|
|
2004-07-12 14:33:25 +00:00
|
|
|
SdrMarkList aMark = pDragEditView->GetMarkedObjectList();
|
2000-09-18 16:07:07 +00:00
|
|
|
aMark.ForceSort();
|
2014-08-05 22:30:24 +02:00
|
|
|
const size_t nMarkAnz=aMark.GetMarkCount();
|
|
|
|
for (size_t nm=0; nm<nMarkAnz; ++nm) {
|
2000-09-18 16:07:07 +00:00
|
|
|
const SdrMark* pM=aMark.GetMark(nm);
|
2006-07-25 11:28:04 +00:00
|
|
|
const SdrObject* pObj=pM->GetMarkedSdrObj();
|
2004-05-10 13:39:17 +00:00
|
|
|
|
|
|
|
SdrObject* pNeuObj=pObj->Clone();
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
if (pNeuObj!=NULL)
|
|
|
|
{
|
2007-02-27 13:01:33 +00:00
|
|
|
pNeuObj->SetModel(pDrawModel);
|
2004-05-10 13:39:17 +00:00
|
|
|
pNeuObj->SetPage(pDestPage);
|
|
|
|
|
2011-03-02 21:32:00 +01:00
|
|
|
// copy graphics within the same model - always needs new name
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( pNeuObj->ISA(SdrGrafObj) && !bPasteIsMove )
|
2014-10-27 14:18:59 +02:00
|
|
|
pNeuObj->SetName(static_cast<ScDrawLayer*>(pDrawModel)->GetNewGraphicName());
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if (nDiffX!=0 || nDiffY!=0)
|
|
|
|
pNeuObj->NbcMove(Size(nDiffX,nDiffY));
|
2014-03-02 09:36:46 +00:00
|
|
|
if (pDestPage)
|
|
|
|
pDestPage->InsertObject( pNeuObj );
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->AddUndo(new SdrUndoInsertObj( *pNeuObj ));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-01-25 12:57:14 -05:00
|
|
|
if (ScDrawLayer::IsCellAnchored(*pNeuObj))
|
2014-06-18 12:14:29 +02:00
|
|
|
ScDrawLayer::SetCellAnchoredFromPosition(*pNeuObj, *GetViewData().GetDocument(), nTab);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bPasteIsMove)
|
|
|
|
pDragEditView->DeleteMarked();
|
2010-08-03 20:18:36 +02:00
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
ScDocument* pDocument = GetViewData().GetDocument();
|
|
|
|
ScDocShell* pDocShell = GetViewData().GetDocShell();
|
2010-08-03 20:18:36 +02:00
|
|
|
ScModelObj* pModelObj = ( pDocShell ? ScModelObj::getImplementation( pDocShell->GetModel() ) : NULL );
|
|
|
|
if ( pDocument && pDestPage && pModelObj && pDrawTrans )
|
|
|
|
{
|
|
|
|
const ScRangeListVector& rProtectedChartRangesVector( pDrawTrans->GetProtectedChartRangesVector() );
|
|
|
|
ScChartHelper::CreateProtectedChartListenersAndNotify( pDocument, pDestPage, pModelObj, nTab,
|
2010-08-16 13:06:52 +02:00
|
|
|
rProtectedChartRangesVector, aExcludedChartNames, bSameDoc );
|
2010-08-03 20:18:36 +02:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-03 17:11:39 +01:00
|
|
|
bPasteIsMove = false; // no internal move happened
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-11-22 10:52:38 +00:00
|
|
|
SdrView aView(pModel); // #i71529# never create a base class of SdrView directly!
|
2006-11-14 15:00:57 +00:00
|
|
|
SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
|
2006-06-19 20:34:48 +00:00
|
|
|
aView.MarkAllObj(pPv);
|
2000-09-18 16:07:07 +00:00
|
|
|
Size aSize = aView.GetAllMarkedRect().GetSize();
|
2014-06-18 12:14:29 +02:00
|
|
|
lcl_AdjustInsertPos( &GetViewData(), aPos, aSize );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-02-21 02:36:00 +01:00
|
|
|
// don't change marking if OLE object is active
|
|
|
|
// (at Drop from OLE object it would be deactivated in the middle of ExecuteDrag!)
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2015-04-23 15:00:26 +02:00
|
|
|
SdrInsertFlags nOptions = SdrInsertFlags::NONE;
|
2014-06-18 12:14:29 +02:00
|
|
|
SfxInPlaceClient* pClient = GetViewData().GetViewShell()->GetIPClient();
|
2004-10-04 19:28:15 +00:00
|
|
|
if ( pClient && pClient->IsObjectInPlaceActive() )
|
2015-04-23 15:00:26 +02:00
|
|
|
nOptions |= SdrInsertFlags::DONTMARK;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString > aExcludedChartNames;
|
2014-06-18 12:14:29 +02:00
|
|
|
SCTAB nTab = GetViewData().GetTabNo();
|
2011-03-14 16:24:03 -04:00
|
|
|
SdrPage* pPage = pScDrawView->GetModel()->GetPage( static_cast< sal_uInt16 >( nTab ) );
|
2011-05-21 15:04:26 +02:00
|
|
|
OSL_ENSURE( pPage, "Page?" );
|
2011-03-14 16:24:03 -04:00
|
|
|
if ( pPage )
|
|
|
|
{
|
|
|
|
ScChartHelper::GetChartNames( aExcludedChartNames, pPage );
|
|
|
|
}
|
|
|
|
|
|
|
|
// #89247# Set flag for ScDocument::UpdateChartListeners() which is
|
2001-10-25 16:46:44 +00:00
|
|
|
// called during paste.
|
|
|
|
if ( !bSameDocClipboard )
|
2014-06-18 12:14:29 +02:00
|
|
|
GetViewData().GetDocument()->SetPastingDrawFromOtherDoc( true );
|
2001-10-25 16:46:44 +00:00
|
|
|
|
2014-06-13 11:12:50 -04:00
|
|
|
pScDrawView->Paste(*pModel, aPos, NULL, nOptions, rSrcShellID, rDestShellID);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-10-25 16:46:44 +00:00
|
|
|
if ( !bSameDocClipboard )
|
2014-06-18 12:14:29 +02:00
|
|
|
GetViewData().GetDocument()->SetPastingDrawFromOtherDoc( false );
|
2001-10-25 16:46:44 +00:00
|
|
|
|
2011-03-02 21:32:00 +01:00
|
|
|
// Paste puts all objects on the active (front) layer
|
2000-09-18 16:07:07 +00:00
|
|
|
// controls must be on SC_LAYER_CONTROLS
|
|
|
|
if (pPage)
|
|
|
|
{
|
|
|
|
SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
|
|
|
|
SdrObject* pObject = aIter.Next();
|
|
|
|
while (pObject)
|
|
|
|
{
|
|
|
|
if ( pObject->ISA(SdrUnoObj) && pObject->GetLayer() != SC_LAYER_CONTROLS )
|
|
|
|
pObject->NbcSetLayer(SC_LAYER_CONTROLS);
|
2013-01-25 12:57:14 -05:00
|
|
|
|
|
|
|
if (ScDrawLayer::IsCellAnchored(*pObject))
|
2014-06-18 12:14:29 +02:00
|
|
|
ScDrawLayer::SetCellAnchoredFromPosition(*pObject, *GetViewData().GetDocument(), nTab);
|
2013-01-25 12:57:14 -05:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
pObject = aIter.Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 21:32:00 +01:00
|
|
|
// all graphics objects must have names
|
2014-06-18 12:14:29 +02:00
|
|
|
GetViewData().GetDocument()->EnsureGraphicNames();
|
2010-08-03 20:18:36 +02:00
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
ScDocument* pDocument = GetViewData().GetDocument();
|
|
|
|
ScDocShell* pDocShell = GetViewData().GetDocShell();
|
2010-08-03 20:18:36 +02:00
|
|
|
ScModelObj* pModelObj = ( pDocShell ? ScModelObj::getImplementation( pDocShell->GetModel() ) : NULL );
|
|
|
|
ScDrawTransferObj* pTransferObj = ScDrawTransferObj::GetOwnClipboard( NULL );
|
2010-08-16 13:06:52 +02:00
|
|
|
if ( pDocument && pPage && pModelObj && ( pTransferObj || pDrawTrans ) )
|
2010-08-03 20:18:36 +02:00
|
|
|
{
|
2010-08-16 13:06:52 +02:00
|
|
|
const ScRangeListVector& rProtectedChartRangesVector(
|
|
|
|
pTransferObj ? pTransferObj->GetProtectedChartRangesVector() : pDrawTrans->GetProtectedChartRangesVector() );
|
2010-08-03 20:18:36 +02:00
|
|
|
ScChartHelper::CreateProtectedChartListenersAndNotify( pDocument, pPage, pModelObj, nTab,
|
2010-08-16 13:06:52 +02:00
|
|
|
rProtectedChartRangesVector, aExcludedChartNames, bSameDocClipboard );
|
2010-08-03 20:18:36 +02:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bGroup)
|
|
|
|
{
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->GroupMarked();
|
|
|
|
pScDrawView->EndUndo();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pRef)
|
|
|
|
pRef->SetMapMode( aOldMapMode );
|
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
// GetViewData().GetViewShell()->SetDrawShell( true );
|
2011-03-02 21:32:00 +01:00
|
|
|
// It is not sufficient to just set the DrawShell if we pasted, for
|
2002-07-12 16:01:07 +00:00
|
|
|
// example, a chart. SetDrawShellOrSub() would only work for D&D in the
|
|
|
|
// same document but not if inserting from the clipboard, therefore
|
|
|
|
// MarkListHasChanged() is what we need.
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->MarkListHasChanged();
|
2002-07-12 16:01:07 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool ScViewFunc::PasteObject( const Point& rPos, const uno::Reference < embed::XEmbeddedObject >& xObj,
|
2013-04-07 12:06:47 +02:00
|
|
|
const Size* pDescSize, const Graphic* pReplGraph, const OUString& aMediaType, sal_Int64 nAspect )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
MakeDrawLayer();
|
2004-10-04 19:28:15 +00:00
|
|
|
if ( xObj.is() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aName;
|
2004-10-04 19:28:15 +00:00
|
|
|
//TODO/MBA: is that OK?
|
2014-06-18 12:14:29 +02:00
|
|
|
comphelper::EmbeddedObjectContainer& aCnt = GetViewData().GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer();
|
2004-10-04 19:28:15 +00:00
|
|
|
if ( !aCnt.HasEmbeddedObject( xObj ) )
|
|
|
|
aCnt.InsertEmbeddedObject( xObj, aName );
|
|
|
|
else
|
|
|
|
aName = aCnt.GetEmbeddedObjectName( xObj );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-10-13 10:37:44 +00:00
|
|
|
svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
|
|
|
|
if ( pReplGraph )
|
|
|
|
aObjRef.SetGraphic( *pReplGraph, aMediaType );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-10-13 10:37:44 +00:00
|
|
|
Size aSize;
|
|
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
2005-03-15 10:44:26 +00:00
|
|
|
{
|
2006-10-13 10:37:44 +00:00
|
|
|
MapMode aMapMode( MAP_100TH_MM );
|
|
|
|
aSize = aObjRef.GetSize( &aMapMode );
|
2005-03-15 10:44:26 +00:00
|
|
|
}
|
2006-10-13 10:37:44 +00:00
|
|
|
else
|
2005-03-15 10:44:26 +00:00
|
|
|
{
|
2006-10-13 10:37:44 +00:00
|
|
|
// working with visual area can switch object to running state
|
|
|
|
MapUnit aMapObj = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
|
|
|
|
MapUnit aMap100 = MAP_100TH_MM;
|
2005-03-15 10:44:26 +00:00
|
|
|
|
2006-10-13 10:37:44 +00:00
|
|
|
if ( pDescSize && pDescSize->Width() && pDescSize->Height() )
|
|
|
|
{
|
|
|
|
// use size from object descriptor if given
|
|
|
|
aSize = OutputDevice::LogicToLogic( *pDescSize, aMap100, aMapObj );
|
|
|
|
awt::Size aSz;
|
|
|
|
aSz.Width = aSize.Width();
|
|
|
|
aSz.Height = aSize.Height();
|
|
|
|
xObj->setVisualAreaSize( nAspect, aSz );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2006-10-13 10:37:44 +00:00
|
|
|
awt::Size aSz;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
aSz = xObj->getVisualAreaSize( nAspect );
|
|
|
|
}
|
|
|
|
catch ( embed::NoVisualAreaSizeException& )
|
|
|
|
{
|
|
|
|
// the default size will be set later
|
|
|
|
}
|
|
|
|
|
|
|
|
aSize = Size( aSz.Width, aSz.Height );
|
2013-02-21 02:36:00 +01:00
|
|
|
aSize = OutputDevice::LogicToLogic( aSize, aMapObj, aMap100 ); // for SdrOle2Obj
|
2006-10-13 10:37:44 +00:00
|
|
|
|
|
|
|
if( aSize.Height() == 0 || aSize.Width() == 0 )
|
|
|
|
{
|
2011-03-01 19:05:02 +01:00
|
|
|
OSL_FAIL("SvObjectDescriptor::GetSize == 0");
|
2006-10-13 10:37:44 +00:00
|
|
|
aSize.Width() = 5000;
|
|
|
|
aSize.Height() = 5000;
|
|
|
|
aSize = OutputDevice::LogicToLogic( aSize, aMap100, aMapObj );
|
|
|
|
aSz.Width = aSize.Width();
|
|
|
|
aSz.Height = aSize.Height();
|
|
|
|
xObj->setVisualAreaSize( nAspect, aSz );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2004-10-04 19:28:15 +00:00
|
|
|
|
2004-02-03 12:08:03 +00:00
|
|
|
// don't call AdjustInsertPos
|
|
|
|
Point aInsPos = rPos;
|
2014-06-18 12:14:29 +02:00
|
|
|
if ( GetViewData().GetDocument()->IsNegativePage( GetViewData().GetTabNo() ) )
|
2004-02-03 12:08:03 +00:00
|
|
|
aInsPos.X() -= aSize.Width();
|
|
|
|
Rectangle aRect( aInsPos, aSize );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
ScDrawView* pDrView = GetScDrawView();
|
2006-10-13 10:37:44 +00:00
|
|
|
SdrOle2Obj* pSdrObj = new SdrOle2Obj( aObjRef, aName, aRect );
|
2006-02-01 18:09:37 +00:00
|
|
|
|
2006-11-14 15:00:57 +00:00
|
|
|
SdrPageView* pPV = pDrView->GetSdrPageView();
|
2013-02-21 02:36:00 +01:00
|
|
|
pDrView->InsertObjectSafe( pSdrObj, *pPV ); // don't mark if OLE
|
2014-06-18 12:14:29 +02:00
|
|
|
GetViewData().GetViewShell()->SetDrawShell( true );
|
2014-02-19 11:34:59 +02:00
|
|
|
return true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2011-03-10 16:55:21 -05:00
|
|
|
return false;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool ScViewFunc::PasteBitmapEx( const Point& rPos, const BitmapEx& rBmpEx )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-10-04 16:14:14 +02:00
|
|
|
OUString aEmpty;
|
2013-01-10 16:28:40 +00:00
|
|
|
Graphic aGraphic(rBmpEx);
|
2000-09-18 16:07:07 +00:00
|
|
|
return PasteGraphic( rPos, aGraphic, aEmpty, aEmpty );
|
|
|
|
}
|
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool ScViewFunc::PasteMetaFile( const Point& rPos, const GDIMetaFile& rMtf )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-10-04 16:14:14 +02:00
|
|
|
OUString aEmpty;
|
2000-09-18 16:07:07 +00:00
|
|
|
Graphic aGraphic(rMtf);
|
|
|
|
return PasteGraphic( rPos, aGraphic, aEmpty, aEmpty );
|
|
|
|
}
|
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
bool ScViewFunc::PasteGraphic( const Point& rPos, const Graphic& rGraphic,
|
2013-09-19 17:11:28 +02:00
|
|
|
const OUString& rFile, const OUString& rFilter )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
MakeDrawLayer();
|
2007-02-27 13:01:33 +00:00
|
|
|
ScDrawView* pScDrawView = GetScDrawView();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2014-02-27 10:32:12 +00:00
|
|
|
if (!pScDrawView)
|
|
|
|
return false;
|
|
|
|
|
2014-02-07 01:26:23 +00:00
|
|
|
// #i123922# check if the drop was over an existing object; if yes, evtl. replace
|
|
|
|
// the graphic for a SdrGraphObj (including link state updates) or adapt the fill
|
|
|
|
// style for other objects
|
2014-02-27 10:32:12 +00:00
|
|
|
SdrPageView* pPageView = pScDrawView->GetSdrPageView();
|
|
|
|
if (pPageView)
|
2014-02-07 01:26:23 +00:00
|
|
|
{
|
2014-02-27 10:32:12 +00:00
|
|
|
SdrObject* pPickObj = 0;
|
|
|
|
if (pScDrawView->PickObj(rPos, pScDrawView->getHitTolLog(), pPickObj, pPageView))
|
2014-02-07 01:26:23 +00:00
|
|
|
{
|
2014-02-27 10:32:12 +00:00
|
|
|
const OUString aBeginUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
|
|
|
|
SdrObject* pResult = pScDrawView->ApplyGraphicToObject(
|
|
|
|
*pPickObj,
|
|
|
|
rGraphic,
|
|
|
|
aBeginUndo,
|
|
|
|
rFile,
|
|
|
|
rFilter);
|
|
|
|
|
|
|
|
if (pResult)
|
2014-02-07 01:26:23 +00:00
|
|
|
{
|
2014-02-27 10:32:12 +00:00
|
|
|
// we are done; mark the modified/new object
|
|
|
|
pScDrawView->MarkObj(pResult, pScDrawView->GetSdrPageView());
|
|
|
|
return true;
|
2014-02-07 01:26:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
Point aPos( rPos );
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pWin = GetActiveWin();
|
2000-09-18 16:07:07 +00:00
|
|
|
MapMode aSourceMap = rGraphic.GetPrefMapMode();
|
|
|
|
MapMode aDestMap( MAP_100TH_MM );
|
|
|
|
|
|
|
|
if (aSourceMap.GetMapUnit() == MAP_PIXEL)
|
|
|
|
{
|
2013-02-21 02:36:00 +01:00
|
|
|
// consider pixel correction, so bitmap fits to screen
|
2014-10-23 17:41:47 +02:00
|
|
|
Fraction aScaleX, aScaleY;
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->CalcNormScale( aScaleX, aScaleY );
|
2000-09-18 16:07:07 +00:00
|
|
|
aDestMap.SetScaleX(aScaleX);
|
|
|
|
aDestMap.SetScaleY(aScaleY);
|
|
|
|
}
|
|
|
|
|
|
|
|
Size aSize = pWin->LogicToLogic( rGraphic.GetPrefSize(), &aSourceMap, &aDestMap );
|
2011-01-16 19:11:44 +01:00
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
if ( GetViewData().GetDocument()->IsNegativePage( GetViewData().GetTabNo() ) )
|
2004-02-03 12:08:03 +00:00
|
|
|
aPos.X() -= aSize.Width();
|
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
GetViewData().GetViewShell()->SetDrawShell( true );
|
2000-09-18 16:07:07 +00:00
|
|
|
Rectangle aRect(aPos, aSize);
|
|
|
|
SdrGrafObj* pGrafObj = new SdrGrafObj(rGraphic, aRect);
|
|
|
|
|
2013-02-21 02:36:00 +01:00
|
|
|
// path was the name of the graphic in history
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2014-10-27 14:18:59 +02:00
|
|
|
ScDrawLayer* pLayer = static_cast<ScDrawLayer*>( pScDrawView->GetModel() );
|
2013-10-04 16:14:14 +02:00
|
|
|
OUString aName = pLayer->GetNewGraphicName(); // "Graphics"
|
2000-09-18 16:07:07 +00:00
|
|
|
pGrafObj->SetName(aName);
|
|
|
|
|
2013-02-21 02:36:00 +01:00
|
|
|
// don't mark if OLE
|
2007-02-27 13:01:33 +00:00
|
|
|
pScDrawView->InsertObjectSafe(pGrafObj, *pScDrawView->GetSdrPageView());
|
2004-11-26 12:26:29 +00:00
|
|
|
|
2011-03-02 21:32:00 +01:00
|
|
|
// SetGraphicLink has to be used after inserting the object,
|
2004-11-26 12:26:29 +00:00
|
|
|
// otherwise an empty graphic is swapped in and the contact stuff crashes.
|
|
|
|
// See #i37444#.
|
2013-09-19 17:11:28 +02:00
|
|
|
if (!rFile.isEmpty())
|
rhbz#887420 Implement "block untrusted referer links" feature
For now, this checks for a trusted referer (if the BlockUntrustedRefererLinks
configuration prop is set) in utl::MediaDescriptor::impl_openStreamWithURL and
SvxBrushItem::GetGraphicObject. Checking in additional places will probably be
necessary to block /all/ unwanted communication. Also, some places marked
/*TODO?*/ currently pass in an empty referer (which is always considered
trusted) and will probably need to be adapted.
Ideally, Referer URIs would never be empty (and consistently use something like
<private:user> for cases where access is explicitly initiated by the user and
should never be blocked), but that's a very daunting task, so start small by
identifying the places that potentially need blocking and adding appropriate
Referer URIs there. Also, Referer information should always be computed as
freshly as possible from the context in which an access attempt is made, but,
again, always carrying the information from the context all the way to the
relevant functions is a very daunting task, so for now store the information
upon object instantiation in some cases (SvxBrushItem, SdrGrafObj, ...).
The Referer URI (css.document.MediaDescriptor property; SID_REFERER) was already
used to track macro execution, and there is one place in
SfxApplication::OpenDocExec_Impl where opening of hyperlinks (explicitly clicked
by the user) is done that needs the current document's URI as Referer to check
execution of macro URIs but needs an empty (or <private:user>, see above)
Referer to not block non-macro URIs. Special code has been added there to
handle that.
Change-Id: Iafbdc07a9fe925d9ee580d4f5778448f18f2ebd9
2013-11-14 10:39:27 +01:00
|
|
|
pGrafObj->SetGraphicLink( rFile, ""/*TODO?*/, rFilter );
|
2004-11-26 12:26:29 +00:00
|
|
|
|
2014-02-19 11:34:59 +02:00
|
|
|
return true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:59:00 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|