1b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5b3f79822SAndrew Rist * distributed with this work for additional information 6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10b3f79822SAndrew Rist * 11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12b3f79822SAndrew Rist * 13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14b3f79822SAndrew Rist * software distributed under the License is distributed on an 15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17b3f79822SAndrew Rist * specific language governing permissions and limitations 18b3f79822SAndrew Rist * under the License. 19b3f79822SAndrew Rist * 20b3f79822SAndrew Rist *************************************************************/ 21b3f79822SAndrew Rist 22b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // INCLUDE --------------------------------------------------------------- 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "scitems.hxx" 32cdf0e10cSrcweir #include <editeng/eeitem.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 36cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <unotools/tempfile.hxx> 39cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 40cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 41cdf0e10cSrcweir #include <sot/storage.hxx> 42cdf0e10cSrcweir #include <vcl/svapp.hxx> 43cdf0e10cSrcweir #include <vcl/virdev.hxx> 44cdf0e10cSrcweir #include <vos/mutex.hxx> 45cdf0e10cSrcweir #include <sfx2/app.hxx> 46cdf0e10cSrcweir #include <sfx2/docfile.hxx> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include "transobj.hxx" 49cdf0e10cSrcweir #include "document.hxx" 50cdf0e10cSrcweir #include "viewopti.hxx" 51cdf0e10cSrcweir #include "editutil.hxx" 52cdf0e10cSrcweir #include "impex.hxx" 53cdf0e10cSrcweir #include "cell.hxx" 54cdf0e10cSrcweir #include "printfun.hxx" 55cdf0e10cSrcweir #include "docfunc.hxx" 56cdf0e10cSrcweir #include "scmod.hxx" 57cdf0e10cSrcweir 58cdf0e10cSrcweir // for InitDocShell 59cdf0e10cSrcweir #include <editeng/paperinf.hxx> 60cdf0e10cSrcweir #include <editeng/sizeitem.hxx> 61cdf0e10cSrcweir #include <svx/algitem.hxx> 62cdf0e10cSrcweir #include <svl/intitem.hxx> 63cdf0e10cSrcweir #include <svl/zforlist.hxx> 64cdf0e10cSrcweir #include "docsh.hxx" 65cdf0e10cSrcweir #include "markdata.hxx" 66cdf0e10cSrcweir #include "stlpool.hxx" 67cdf0e10cSrcweir #include "viewdata.hxx" 68cdf0e10cSrcweir #include "dociter.hxx" 69cdf0e10cSrcweir #include "cellsuno.hxx" 70cdf0e10cSrcweir 71cdf0e10cSrcweir using namespace com::sun::star; 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ----------------------------------------------------------------------- 74cdf0e10cSrcweir 75cdf0e10cSrcweir #define SCTRANS_TYPE_IMPEX 1 76cdf0e10cSrcweir #define SCTRANS_TYPE_EDIT_RTF 2 77cdf0e10cSrcweir #define SCTRANS_TYPE_EDIT_BIN 3 78cdf0e10cSrcweir #define SCTRANS_TYPE_EMBOBJ 4 79cdf0e10cSrcweir 80cdf0e10cSrcweir // ----------------------------------------------------------------------- 81cdf0e10cSrcweir 82cdf0e10cSrcweir // static 83cdf0e10cSrcweir void ScTransferObj::GetAreaSize( ScDocument* pDoc, SCTAB nTab1, SCTAB nTab2, SCROW& nRow, SCCOL& nCol ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir SCCOL nMaxCol = 0; 86cdf0e10cSrcweir SCROW nMaxRow = 0; 87cdf0e10cSrcweir for( SCTAB nTab = nTab1; nTab <= nTab2; nTab++ ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir SCCOL nLastCol = 0; 90cdf0e10cSrcweir SCROW nLastRow = 0; 91cdf0e10cSrcweir // GetPrintArea instead of GetCellArea - include drawing objects 92cdf0e10cSrcweir if( pDoc->GetPrintArea( nTab, nLastCol, nLastRow ) ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if( nLastCol > nMaxCol ) 95cdf0e10cSrcweir nMaxCol = nLastCol; 96cdf0e10cSrcweir if( nLastRow > nMaxRow ) 97cdf0e10cSrcweir nMaxRow = nLastRow; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir nRow = nMaxRow; 101cdf0e10cSrcweir nCol = nMaxCol; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir // static 105cdf0e10cSrcweir void ScTransferObj::PaintToDev( OutputDevice* pDev, ScDocument* pDoc, double nPrintFactor, 106cdf0e10cSrcweir const ScRange& rBlock, sal_Bool bMetaFile ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir if (!pDoc) 109cdf0e10cSrcweir return; 110cdf0e10cSrcweir 111cdf0e10cSrcweir Point aPoint; 112cdf0e10cSrcweir Rectangle aBound( aPoint, pDev->GetOutputSize() ); //! use size from clip area? 113cdf0e10cSrcweir 114cdf0e10cSrcweir ScViewData aViewData(NULL,NULL); 115cdf0e10cSrcweir aViewData.InitData( pDoc ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir aViewData.SetTabNo( rBlock.aEnd.Tab() ); 118cdf0e10cSrcweir aViewData.SetScreen( rBlock.aStart.Col(), rBlock.aStart.Row(), 119cdf0e10cSrcweir rBlock.aEnd.Col(), rBlock.aEnd.Row() ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir ScPrintFunc::DrawToDev( pDoc, pDev, nPrintFactor, aBound, &aViewData, bMetaFile ); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir // ----------------------------------------------------------------------- 125cdf0e10cSrcweir 126cdf0e10cSrcweir ScTransferObj::ScTransferObj( ScDocument* pClipDoc, const TransferableObjectDescriptor& rDesc ) : 127cdf0e10cSrcweir pDoc( pClipDoc ), 128cdf0e10cSrcweir aObjDesc( rDesc ), 129cdf0e10cSrcweir nDragHandleX( 0 ), 130cdf0e10cSrcweir nDragHandleY( 0 ), 131cdf0e10cSrcweir nDragSourceFlags( 0 ), 132cdf0e10cSrcweir bDragWasInternal( sal_False ), 133cdf0e10cSrcweir bUsedForLink( sal_False ), 134cdf0e10cSrcweir bUseInApi( false ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir DBG_ASSERT(pDoc->IsClipboard(), "wrong document"); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // 139cdf0e10cSrcweir // get aBlock from clipboard doc 140cdf0e10cSrcweir // 141cdf0e10cSrcweir 142cdf0e10cSrcweir SCCOL nCol1; 143cdf0e10cSrcweir SCROW nRow1; 144cdf0e10cSrcweir SCCOL nCol2; 145cdf0e10cSrcweir SCROW nRow2; 146cdf0e10cSrcweir pDoc->GetClipStart( nCol1, nRow1 ); 147cdf0e10cSrcweir pDoc->GetClipArea( nCol2, nRow2, sal_True ); // real source area - include filtered rows 148cdf0e10cSrcweir nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nCol1 ); 149cdf0e10cSrcweir nRow2 = sal::static_int_cast<SCROW>( nRow2 + nRow1 ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir SCCOL nDummy; 152cdf0e10cSrcweir pDoc->GetClipArea( nDummy, nNonFiltered, sal_False ); 153cdf0e10cSrcweir bHasFiltered = (nNonFiltered < (nRow2 - nRow1)); 154cdf0e10cSrcweir ++nNonFiltered; // to get count instead of diff 155cdf0e10cSrcweir 156cdf0e10cSrcweir SCTAB nTab1=0; 157cdf0e10cSrcweir SCTAB nTab2=0; 158cdf0e10cSrcweir sal_Bool bFirst = sal_True; 159cdf0e10cSrcweir for (SCTAB i=0; i<=MAXTAB; i++) 160cdf0e10cSrcweir if (pDoc->HasTable(i)) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if (bFirst) 163cdf0e10cSrcweir nTab1 = i; 164cdf0e10cSrcweir nTab2 = i; 165cdf0e10cSrcweir bFirst = sal_False; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir DBG_ASSERT(!bFirst, "no sheet selected"); 168cdf0e10cSrcweir 169cdf0e10cSrcweir // only limit to used cells if whole sheet was marked 170cdf0e10cSrcweir // (so empty cell areas can be copied) 171cdf0e10cSrcweir if ( nCol2>=MAXCOL && nRow2>=MAXROW ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir SCROW nMaxRow; 174cdf0e10cSrcweir SCCOL nMaxCol; 175cdf0e10cSrcweir GetAreaSize( pDoc, nTab1, nTab2, nMaxRow, nMaxCol ); 176cdf0e10cSrcweir if( nMaxRow < nRow2 ) 177cdf0e10cSrcweir nRow2 = nMaxRow; 178cdf0e10cSrcweir if( nMaxCol < nCol2 ) 179cdf0e10cSrcweir nCol2 = nMaxCol; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir aBlock = ScRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); 183cdf0e10cSrcweir nVisibleTab = nTab1; // valid table as default 184cdf0e10cSrcweir 185cdf0e10cSrcweir Rectangle aMMRect = pDoc->GetMMRect( nCol1,nRow1, nCol2,nRow2, nTab1 ); 186cdf0e10cSrcweir aObjDesc.maSize = aMMRect.GetSize(); 187cdf0e10cSrcweir PrepareOLE( aObjDesc ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir ScTransferObj::~ScTransferObj() 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Application::GetSolarMutex().acquire(); 193cdf0e10cSrcweir 194cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 195cdf0e10cSrcweir if ( pScMod->GetClipData().pCellClipboard == this ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir DBG_ERROR("ScTransferObj wasn't released"); 198cdf0e10cSrcweir pScMod->SetClipObject( NULL, NULL ); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir if ( pScMod->GetDragData().pCellTransfer == this ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir DBG_ERROR("ScTransferObj wasn't released"); 203cdf0e10cSrcweir pScMod->ResetDragObject(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir delete pDoc; // ScTransferObj is owner of clipboard document 207cdf0e10cSrcweir 208cdf0e10cSrcweir aDocShellRef.Clear(); // before releasing the mutex 209cdf0e10cSrcweir 210cdf0e10cSrcweir aDrawPersistRef.Clear(); // after the model 211cdf0e10cSrcweir 212cdf0e10cSrcweir Application::GetSolarMutex().release(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir // static 216cdf0e10cSrcweir ScTransferObj* ScTransferObj::GetOwnClipboard( Window* pUIWin ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir ScTransferObj* pObj = SC_MOD()->GetClipData().pCellClipboard; 219cdf0e10cSrcweir if ( pObj && pUIWin ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir // check formats to see if pObj is really in the system clipboard 222cdf0e10cSrcweir 223cdf0e10cSrcweir // pUIWin is NULL when called from core (IsClipboardSource), 224cdf0e10cSrcweir // in that case don't access the system clipboard, because the call 225cdf0e10cSrcweir // may be from other clipboard operations (like flushing, #86059#) 226cdf0e10cSrcweir 227cdf0e10cSrcweir TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pUIWin ) ); 228cdf0e10cSrcweir if ( !aDataHelper.HasFormat( SOT_FORMATSTR_ID_DIF ) ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir // DBG_ERROR("ScTransferObj wasn't released"); 231cdf0e10cSrcweir pObj = NULL; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } 234cdf0e10cSrcweir return pObj; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir void ScTransferObj::AddSupportedFormats() 238cdf0e10cSrcweir { 239cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ); 240cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 241cdf0e10cSrcweir AddFormat( SOT_FORMAT_GDIMETAFILE ); 242cdf0e10cSrcweir AddFormat( SOT_FORMAT_BITMAP ); 243cdf0e10cSrcweir 244cdf0e10cSrcweir // ScImportExport formats 245cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_HTML ); 246cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_SYLK ); 247cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_LINK ); 248cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_DIF ); 249cdf0e10cSrcweir AddFormat( SOT_FORMAT_STRING ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir AddFormat( SOT_FORMAT_RTF ); 252cdf0e10cSrcweir if ( aBlock.aStart == aBlock.aEnd ) 253cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_EDITENGINE ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir sal_Bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor ); 259cdf0e10cSrcweir sal_Bool bOK = sal_False; 260cdf0e10cSrcweir 261cdf0e10cSrcweir if( HasFormat( nFormat ) ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir if ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor ); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir else if ( ( nFormat == SOT_FORMAT_RTF || nFormat == SOT_FORMATSTR_ID_EDITENGINE ) && 268cdf0e10cSrcweir aBlock.aStart == aBlock.aEnd ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir // RTF from a single cell is handled by EditEngine 271cdf0e10cSrcweir 272cdf0e10cSrcweir SCCOL nCol = aBlock.aStart.Col(); 273cdf0e10cSrcweir SCROW nRow = aBlock.aStart.Row(); 274cdf0e10cSrcweir SCTAB nTab = aBlock.aStart.Tab(); 275cdf0e10cSrcweir 276cdf0e10cSrcweir const ScPatternAttr* pPattern = pDoc->GetPattern( nCol, nRow, nTab ); 277cdf0e10cSrcweir ScTabEditEngine aEngine( *pPattern, pDoc->GetEditPool() ); 278cdf0e10cSrcweir ScBaseCell* pCell = NULL; 279cdf0e10cSrcweir pDoc->GetCell( nCol, nRow, nTab, pCell ); 280cdf0e10cSrcweir if (pCell) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir if (pCell->GetCellType() == CELLTYPE_EDIT) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir const EditTextObject* pObj; 285cdf0e10cSrcweir ((ScEditCell*)pCell)->GetData(pObj); 286cdf0e10cSrcweir aEngine.SetText( *pObj ); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir else 289cdf0e10cSrcweir { 290cdf0e10cSrcweir String aText; 291cdf0e10cSrcweir pDoc->GetString( nCol, nRow, nTab, aText ); 292cdf0e10cSrcweir aEngine.SetText(aText); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir bOK = SetObject( &aEngine, 297cdf0e10cSrcweir (nFormat == FORMAT_RTF) ? SCTRANS_TYPE_EDIT_RTF : SCTRANS_TYPE_EDIT_BIN, 298cdf0e10cSrcweir rFlavor ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir else if ( ScImportExport::IsFormatSupported( nFormat ) || nFormat == SOT_FORMAT_RTF ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir // if this transfer object was used to create a DDE link, filtered rows 303cdf0e10cSrcweir // have to be included for subsequent calls (to be consistent with link data) 304cdf0e10cSrcweir if ( nFormat == SOT_FORMATSTR_ID_LINK ) 305cdf0e10cSrcweir bUsedForLink = sal_True; 306cdf0e10cSrcweir 307cdf0e10cSrcweir sal_Bool bIncludeFiltered = pDoc->IsCutMode() || bUsedForLink; 308cdf0e10cSrcweir 309cdf0e10cSrcweir ScImportExport aObj( pDoc, aBlock ); 310cdf0e10cSrcweir if ( bUsedForLink ) 311cdf0e10cSrcweir aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, ' ', false ) ); 312cdf0e10cSrcweir aObj.SetFormulas( pDoc->GetViewOptions().GetOption( VOPT_FORMULAS ) ); 313cdf0e10cSrcweir aObj.SetIncludeFiltered( bIncludeFiltered ); 314cdf0e10cSrcweir 315cdf0e10cSrcweir // DataType depends on format type: 316cdf0e10cSrcweir 317cdf0e10cSrcweir if ( rFlavor.DataType.equals( ::getCppuType( (const ::rtl::OUString*) 0 ) ) ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir rtl::OUString aString; 320cdf0e10cSrcweir if ( aObj.ExportString( aString, nFormat ) ) 321cdf0e10cSrcweir bOK = SetString( aString, rFlavor ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir else if ( rFlavor.DataType.equals( ::getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ) ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir // SetObject converts a stream into a Int8-Sequence 326cdf0e10cSrcweir bOK = SetObject( &aObj, SCTRANS_TYPE_IMPEX, rFlavor ); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir else 329cdf0e10cSrcweir { 330cdf0e10cSrcweir DBG_ERROR("unknown DataType"); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir } 333cdf0e10cSrcweir else if ( nFormat == SOT_FORMAT_BITMAP ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir Rectangle aMMRect = pDoc->GetMMRect( aBlock.aStart.Col(), aBlock.aStart.Row(), 336cdf0e10cSrcweir aBlock.aEnd.Col(), aBlock.aEnd.Row(), 337cdf0e10cSrcweir aBlock.aStart.Tab() ); 338cdf0e10cSrcweir VirtualDevice aVirtDev; 339cdf0e10cSrcweir aVirtDev.SetOutputSizePixel( aVirtDev.LogicToPixel( aMMRect.GetSize(), MAP_100TH_MM ) ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir PaintToDev( &aVirtDev, pDoc, 1.0, aBlock, sal_False ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir aVirtDev.SetMapMode( MapMode( MAP_PIXEL ) ); 344cdf0e10cSrcweir Bitmap aBmp = aVirtDev.GetBitmap( Point(), aVirtDev.GetOutputSize() ); 345*45fd3b9aSArmin Le Grand bOK = SetBitmapEx( aBmp, rFlavor ); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir else if ( nFormat == SOT_FORMAT_GDIMETAFILE ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir InitDocShell(); 350cdf0e10cSrcweir SfxObjectShell* pEmbObj = aDocShellRef; 351cdf0e10cSrcweir 352cdf0e10cSrcweir // like SvEmbeddedTransfer::GetData: 353cdf0e10cSrcweir 354cdf0e10cSrcweir GDIMetaFile aMtf; 355cdf0e10cSrcweir VirtualDevice aVDev; 356cdf0e10cSrcweir MapMode aMapMode( pEmbObj->GetMapUnit() ); 357cdf0e10cSrcweir Rectangle aVisArea( pEmbObj->GetVisArea( ASPECT_CONTENT ) ); 358cdf0e10cSrcweir 359cdf0e10cSrcweir aVDev.EnableOutput( sal_False ); 360cdf0e10cSrcweir aVDev.SetMapMode( aMapMode ); 361cdf0e10cSrcweir aMtf.SetPrefSize( aVisArea.GetSize() ); 362cdf0e10cSrcweir aMtf.SetPrefMapMode( aMapMode ); 363cdf0e10cSrcweir aMtf.Record( &aVDev ); 364cdf0e10cSrcweir 365cdf0e10cSrcweir pEmbObj->DoDraw( &aVDev, Point(), aVisArea.GetSize(), JobSetup(), ASPECT_CONTENT ); 366cdf0e10cSrcweir 367cdf0e10cSrcweir aMtf.Stop(); 368cdf0e10cSrcweir aMtf.WindStart(); 369cdf0e10cSrcweir 370cdf0e10cSrcweir bOK = SetGDIMetaFile( aMtf, rFlavor ); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir else if ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir //TODO/LATER: differentiate between formats?! 375cdf0e10cSrcweir InitDocShell(); // set aDocShellRef 376cdf0e10cSrcweir 377cdf0e10cSrcweir SfxObjectShell* pEmbObj = aDocShellRef; 378cdf0e10cSrcweir bOK = SetObject( pEmbObj, SCTRANS_TYPE_EMBOBJ, rFlavor ); 379cdf0e10cSrcweir } 380cdf0e10cSrcweir } 381cdf0e10cSrcweir return bOK; 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir sal_Bool ScTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, 385cdf0e10cSrcweir const datatransfer::DataFlavor& rFlavor ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir // called from SetObject, put data into stream 388cdf0e10cSrcweir 389cdf0e10cSrcweir sal_Bool bRet = sal_False; 390cdf0e10cSrcweir switch (nUserObjectId) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir case SCTRANS_TYPE_IMPEX: 393cdf0e10cSrcweir { 394cdf0e10cSrcweir ScImportExport* pImpEx = (ScImportExport*)pUserObject; 395cdf0e10cSrcweir 396cdf0e10cSrcweir sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor ); 397cdf0e10cSrcweir // mba: no BaseURL for data exchange 398cdf0e10cSrcweir if ( pImpEx->ExportStream( *rxOStm, String(), nFormat ) ) 399cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir break; 402cdf0e10cSrcweir 403cdf0e10cSrcweir case SCTRANS_TYPE_EDIT_RTF: 404cdf0e10cSrcweir case SCTRANS_TYPE_EDIT_BIN: 405cdf0e10cSrcweir { 406cdf0e10cSrcweir ScTabEditEngine* pEngine = (ScTabEditEngine*)pUserObject; 407cdf0e10cSrcweir if ( nUserObjectId == SCTRANS_TYPE_EDIT_RTF ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir pEngine->Write( *rxOStm, EE_FORMAT_RTF ); 410cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE ); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir else 413cdf0e10cSrcweir { 414cdf0e10cSrcweir // #107722# can't use Write for EditEngine format because that would 415cdf0e10cSrcweir // write old format without support for unicode characters. 416cdf0e10cSrcweir // Get the data from the EditEngine's transferable instead. 417cdf0e10cSrcweir 418cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 419cdf0e10cSrcweir if ( nParCnt == 0 ) 420cdf0e10cSrcweir nParCnt = 1; 421cdf0e10cSrcweir ESelection aSel( 0, 0, nParCnt-1, pEngine->GetTextLen(nParCnt-1) ); 422cdf0e10cSrcweir 423cdf0e10cSrcweir uno::Reference<datatransfer::XTransferable> xEditTrans = pEngine->CreateTransferable( aSel ); 424cdf0e10cSrcweir TransferableDataHelper aEditHelper( xEditTrans ); 425cdf0e10cSrcweir 426cdf0e10cSrcweir bRet = aEditHelper.GetSotStorageStream( rFlavor, rxOStm ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir } 429cdf0e10cSrcweir break; 430cdf0e10cSrcweir 431cdf0e10cSrcweir case SCTRANS_TYPE_EMBOBJ: 432cdf0e10cSrcweir { 433cdf0e10cSrcweir // TODO/MBA: testing 434cdf0e10cSrcweir SfxObjectShell* pEmbObj = (SfxObjectShell*) pUserObject; 435cdf0e10cSrcweir ::utl::TempFile aTempFile; 436cdf0e10cSrcweir aTempFile.EnableKillingFile(); 437cdf0e10cSrcweir uno::Reference< embed::XStorage > xWorkStore = 438cdf0e10cSrcweir ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE ); 439cdf0e10cSrcweir 440cdf0e10cSrcweir // write document storage 441cdf0e10cSrcweir pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir // mba: no relative ULRs for clipboard! 444cdf0e10cSrcweir SfxMedium aMedium( xWorkStore, String() ); 445cdf0e10cSrcweir bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False ); 446cdf0e10cSrcweir pEmbObj->DoSaveCompleted(); 447cdf0e10cSrcweir 448cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY ); 449cdf0e10cSrcweir if ( xTransact.is() ) 450cdf0e10cSrcweir xTransact->commit(); 451cdf0e10cSrcweir 452cdf0e10cSrcweir SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ); 453cdf0e10cSrcweir if( pSrcStm ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir rxOStm->SetBufferSize( 0xff00 ); 456cdf0e10cSrcweir *rxOStm << *pSrcStm; 457cdf0e10cSrcweir delete pSrcStm; 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir bRet = sal_True; 461cdf0e10cSrcweir 462cdf0e10cSrcweir xWorkStore->dispose(); 463cdf0e10cSrcweir xWorkStore = uno::Reference < embed::XStorage >(); 464cdf0e10cSrcweir rxOStm->Commit(); 465cdf0e10cSrcweir } 466cdf0e10cSrcweir break; 467cdf0e10cSrcweir 468cdf0e10cSrcweir default: 469cdf0e10cSrcweir DBG_ERROR("unknown object id"); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir return bRet; 472cdf0e10cSrcweir } 473cdf0e10cSrcweir 474cdf0e10cSrcweir void ScTransferObj::ObjectReleased() 475cdf0e10cSrcweir { 476cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 477cdf0e10cSrcweir if ( pScMod->GetClipData().pCellClipboard == this ) 478cdf0e10cSrcweir pScMod->SetClipObject( NULL, NULL ); 479cdf0e10cSrcweir 480cdf0e10cSrcweir TransferableHelper::ObjectReleased(); 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir void ScTransferObj::DragFinished( sal_Int8 nDropAction ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir // move: delete source data 488cdf0e10cSrcweir ScDocShell* pSourceSh = GetSourceDocShell(); 489cdf0e10cSrcweir if (pSourceSh) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir ScMarkData aMarkData = GetSourceMarkData(); 492cdf0e10cSrcweir // external drag&drop doesn't copy objects, so they also aren't deleted: 493cdf0e10cSrcweir // #105703# bApi=sal_True, don't show error messages from drag&drop 494cdf0e10cSrcweir pSourceSh->GetDocFunc().DeleteContents( aMarkData, IDF_ALL & ~IDF_OBJECTS, sal_True, sal_True ); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 499cdf0e10cSrcweir if ( pScMod->GetDragData().pCellTransfer == this ) 500cdf0e10cSrcweir pScMod->ResetDragObject(); 501cdf0e10cSrcweir 502cdf0e10cSrcweir xDragSourceRanges = NULL; // don't keep source after dropping 503cdf0e10cSrcweir 504cdf0e10cSrcweir TransferableHelper::DragFinished( nDropAction ); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir void ScTransferObj::SetDragHandlePos( SCCOL nX, SCROW nY ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir nDragHandleX = nX; 510cdf0e10cSrcweir nDragHandleY = nY; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir void ScTransferObj::SetVisibleTab( SCTAB nNew ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir nVisibleTab = nNew; 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir void ScTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef ) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir aDrawPersistRef = rRef; 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir void ScTransferObj::SetDragSource( ScDocShell* pSourceShell, const ScMarkData& rMark ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir ScRangeList aRanges; 526cdf0e10cSrcweir rMark.FillRangeListWithMarks( &aRanges, sal_False ); 527cdf0e10cSrcweir xDragSourceRanges = new ScCellRangesObj( pSourceShell, aRanges ); 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir void ScTransferObj::SetDragSourceFlags( sal_uInt16 nFlags ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir nDragSourceFlags = nFlags; 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir void ScTransferObj::SetDragWasInternal() 536cdf0e10cSrcweir { 537cdf0e10cSrcweir bDragWasInternal = sal_True; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir void ScTransferObj::SetUseInApi( bool bSet ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir bUseInApi = bSet; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir ScDocument* ScTransferObj::GetSourceDocument() 546cdf0e10cSrcweir { 547cdf0e10cSrcweir ScDocShell* pSourceDocSh = GetSourceDocShell(); 548cdf0e10cSrcweir if (pSourceDocSh) 549cdf0e10cSrcweir return pSourceDocSh->GetDocument(); 550cdf0e10cSrcweir return NULL; 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir ScDocShell* ScTransferObj::GetSourceDocShell() 554cdf0e10cSrcweir { 555cdf0e10cSrcweir ScCellRangesBase* pRangesObj = ScCellRangesBase::getImplementation( xDragSourceRanges ); 556cdf0e10cSrcweir if (pRangesObj) 557cdf0e10cSrcweir return pRangesObj->GetDocShell(); 558cdf0e10cSrcweir 559cdf0e10cSrcweir return NULL; // none set 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir ScMarkData ScTransferObj::GetSourceMarkData() 563cdf0e10cSrcweir { 564cdf0e10cSrcweir ScMarkData aMarkData; 565cdf0e10cSrcweir ScCellRangesBase* pRangesObj = ScCellRangesBase::getImplementation( xDragSourceRanges ); 566cdf0e10cSrcweir if (pRangesObj) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir const ScRangeList& rRanges = pRangesObj->GetRangeList(); 569cdf0e10cSrcweir aMarkData.MarkFromRangeList( rRanges, sal_False ); 570cdf0e10cSrcweir } 571cdf0e10cSrcweir return aMarkData; 572cdf0e10cSrcweir } 573cdf0e10cSrcweir 574cdf0e10cSrcweir // 575cdf0e10cSrcweir // initialize aDocShellRef with a live document from the ClipDoc 576cdf0e10cSrcweir // 577cdf0e10cSrcweir 578cdf0e10cSrcweir void ScTransferObj::InitDocShell() 579cdf0e10cSrcweir { 580cdf0e10cSrcweir if ( !aDocShellRef.Is() ) 581cdf0e10cSrcweir { 582cdf0e10cSrcweir ScDocShell* pDocSh = new ScDocShell; 583cdf0e10cSrcweir aDocShellRef = pDocSh; // ref must be there before InitNew 584cdf0e10cSrcweir 585cdf0e10cSrcweir pDocSh->DoInitNew(NULL); 586cdf0e10cSrcweir 587cdf0e10cSrcweir ScDocument* pDestDoc = pDocSh->GetDocument(); 588cdf0e10cSrcweir ScMarkData aDestMark; 589cdf0e10cSrcweir aDestMark.SelectTable( 0, sal_True ); 590cdf0e10cSrcweir 591cdf0e10cSrcweir pDestDoc->SetDocOptions( pDoc->GetDocOptions() ); // #i42666# 592cdf0e10cSrcweir 593cdf0e10cSrcweir String aTabName; 594cdf0e10cSrcweir pDoc->GetName( aBlock.aStart.Tab(), aTabName ); 595cdf0e10cSrcweir pDestDoc->RenameTab( 0, aTabName, sal_False ); // no UpdateRef (empty) 596cdf0e10cSrcweir 597cdf0e10cSrcweir pDestDoc->CopyStdStylesFrom( pDoc ); 598cdf0e10cSrcweir 599cdf0e10cSrcweir SCCOL nStartX = aBlock.aStart.Col(); 600cdf0e10cSrcweir SCROW nStartY = aBlock.aStart.Row(); 601cdf0e10cSrcweir SCCOL nEndX = aBlock.aEnd.Col(); 602cdf0e10cSrcweir SCROW nEndY = aBlock.aEnd.Row(); 603cdf0e10cSrcweir 604cdf0e10cSrcweir // widths / heights 605cdf0e10cSrcweir // (must be copied before CopyFromClip, for drawing objects) 606cdf0e10cSrcweir 607cdf0e10cSrcweir SCCOL nCol, nLastCol; 608cdf0e10cSrcweir SCTAB nSrcTab = aBlock.aStart.Tab(); 609cdf0e10cSrcweir pDestDoc->SetLayoutRTL(0, pDoc->IsLayoutRTL(nSrcTab)); 610cdf0e10cSrcweir for (nCol=nStartX; nCol<=nEndX; nCol++) 611cdf0e10cSrcweir if ( pDoc->ColHidden(nCol, nSrcTab, nLastCol) ) 612cdf0e10cSrcweir pDestDoc->ShowCol( nCol, 0, sal_False ); 613cdf0e10cSrcweir else 614cdf0e10cSrcweir pDestDoc->SetColWidth( nCol, 0, pDoc->GetColWidth( nCol, nSrcTab ) ); 615cdf0e10cSrcweir 616cdf0e10cSrcweir ScBitMaskCompressedArray< SCROW, sal_uInt8> & rDestRowFlags = 617cdf0e10cSrcweir pDestDoc->GetRowFlagsArrayModifiable(0); 618cdf0e10cSrcweir 619cdf0e10cSrcweir for (SCROW nRow = nStartY; nRow <= nEndY; ++nRow) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir sal_uInt8 nSourceFlags = pDoc->GetRowFlags(nRow, nSrcTab); 622cdf0e10cSrcweir SCROW nLastRow = -1; 623cdf0e10cSrcweir if ( pDoc->RowHidden(nRow, nSrcTab, nLastRow) ) 624cdf0e10cSrcweir pDestDoc->ShowRow( nRow, 0, sal_False ); 625cdf0e10cSrcweir else 626cdf0e10cSrcweir { 627cdf0e10cSrcweir pDestDoc->SetRowHeight( nRow, 0, pDoc->GetOriginalHeight( nRow, nSrcTab ) ); 628cdf0e10cSrcweir 629cdf0e10cSrcweir // if height was set manually, that flag has to be copied, too 630cdf0e10cSrcweir if ( nSourceFlags & CR_MANUALSIZE ) 631cdf0e10cSrcweir rDestRowFlags.OrValue( nRow, CR_MANUALSIZE); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir } 634cdf0e10cSrcweir 635cdf0e10cSrcweir if ( pDoc->GetDrawLayer() ) 636cdf0e10cSrcweir pDocSh->MakeDrawLayer(); 637cdf0e10cSrcweir 638cdf0e10cSrcweir // cell range is copied to the original position, but on the first sheet 639cdf0e10cSrcweir // -> bCutMode must be set 640cdf0e10cSrcweir // pDoc is always a Clipboard-document 641cdf0e10cSrcweir 642cdf0e10cSrcweir ScRange aDestRange( nStartX,nStartY,0, nEndX,nEndY,0 ); 643cdf0e10cSrcweir sal_Bool bWasCut = pDoc->IsCutMode(); 644cdf0e10cSrcweir if (!bWasCut) 645cdf0e10cSrcweir pDoc->SetClipArea( aDestRange, sal_True ); // Cut 646cdf0e10cSrcweir pDestDoc->CopyFromClip( aDestRange, aDestMark, IDF_ALL, NULL, pDoc, sal_False ); 647cdf0e10cSrcweir pDoc->SetClipArea( aDestRange, bWasCut ); 648cdf0e10cSrcweir 649cdf0e10cSrcweir StripRefs( pDoc, nStartX,nStartY, nEndX,nEndY, pDestDoc, 0,0 ); 650cdf0e10cSrcweir 651cdf0e10cSrcweir ScRange aMergeRange = aDestRange; 652cdf0e10cSrcweir pDestDoc->ExtendMerge( aMergeRange, sal_True ); 653cdf0e10cSrcweir 654cdf0e10cSrcweir pDoc->CopyDdeLinks( pDestDoc ); // copy values of DDE Links 655cdf0e10cSrcweir 656cdf0e10cSrcweir // page format (grid etc) and page size (maximum size for ole object) 657cdf0e10cSrcweir 658cdf0e10cSrcweir Size aPaperSize = SvxPaperInfo::GetPaperSize( PAPER_A4 ); // Twips 659cdf0e10cSrcweir ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); 660cdf0e10cSrcweir String aStyleName = pDoc->GetPageStyle( aBlock.aStart.Tab() ); 661cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE ); 662cdf0e10cSrcweir if (pStyleSheet) 663cdf0e10cSrcweir { 664cdf0e10cSrcweir const SfxItemSet& rSourceSet = pStyleSheet->GetItemSet(); 665cdf0e10cSrcweir aPaperSize = ((const SvxSizeItem&) rSourceSet.Get(ATTR_PAGE_SIZE)).GetSize(); 666cdf0e10cSrcweir 667cdf0e10cSrcweir // CopyStyleFrom kopiert SetItems mit richtigem Pool 668cdf0e10cSrcweir ScStyleSheetPool* pDestPool = pDestDoc->GetStyleSheetPool(); 669cdf0e10cSrcweir pDestPool->CopyStyleFrom( pStylePool, aStyleName, SFX_STYLE_FAMILY_PAGE ); 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir ScViewData aViewData( pDocSh, NULL ); 673cdf0e10cSrcweir aViewData.SetScreen( nStartX,nStartY, nEndX,nEndY ); 674cdf0e10cSrcweir aViewData.SetCurX( nStartX ); 675cdf0e10cSrcweir aViewData.SetCurY( nStartY ); 676cdf0e10cSrcweir 677cdf0e10cSrcweir pDestDoc->SetViewOptions( pDoc->GetViewOptions() ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir // Size 680cdf0e10cSrcweir //! get while copying sizes 681cdf0e10cSrcweir 682cdf0e10cSrcweir long nPosX = 0; 683cdf0e10cSrcweir long nPosY = 0; 684cdf0e10cSrcweir 685cdf0e10cSrcweir for (nCol=0; nCol<nStartX; nCol++) 686cdf0e10cSrcweir nPosX += pDestDoc->GetColWidth( nCol, 0 ); 687cdf0e10cSrcweir nPosY += pDestDoc->GetRowHeight( 0, nStartY-1, 0 ); 688cdf0e10cSrcweir nPosX = (long) ( nPosX * HMM_PER_TWIPS ); 689cdf0e10cSrcweir nPosY = (long) ( nPosY * HMM_PER_TWIPS ); 690cdf0e10cSrcweir 691cdf0e10cSrcweir 692cdf0e10cSrcweir aPaperSize.Width() *= 2; // limit OLE object to double of page size 693cdf0e10cSrcweir aPaperSize.Height() *= 2; 694cdf0e10cSrcweir 695cdf0e10cSrcweir long nSizeX = 0; 696cdf0e10cSrcweir long nSizeY = 0; 697cdf0e10cSrcweir for (nCol=nStartX; nCol<=nEndX; nCol++) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir long nAdd = pDestDoc->GetColWidth( nCol, 0 ); 700cdf0e10cSrcweir if ( nSizeX+nAdd > aPaperSize.Width() && nSizeX ) // above limit? 701cdf0e10cSrcweir break; 702cdf0e10cSrcweir nSizeX += nAdd; 703cdf0e10cSrcweir } 704cdf0e10cSrcweir for (SCROW nRow=nStartY; nRow<=nEndY; nRow++) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir long nAdd = pDestDoc->GetRowHeight( nRow, 0 ); 707cdf0e10cSrcweir if ( nSizeY+nAdd > aPaperSize.Height() && nSizeY ) // above limit? 708cdf0e10cSrcweir break; 709cdf0e10cSrcweir nSizeY += nAdd; 710cdf0e10cSrcweir } 711cdf0e10cSrcweir nSizeX = (long) ( nSizeX * HMM_PER_TWIPS ); 712cdf0e10cSrcweir nSizeY = (long) ( nSizeY * HMM_PER_TWIPS ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir // pDocSh->SetVisAreaSize( Size(nSizeX,nSizeY) ); 715cdf0e10cSrcweir 716cdf0e10cSrcweir Rectangle aNewArea( Point(nPosX,nPosY), Size(nSizeX,nSizeY) ); 717cdf0e10cSrcweir //TODO/LATER: why twice?! 718cdf0e10cSrcweir //pDocSh->SvInPlaceObject::SetVisArea( aNewArea ); 719cdf0e10cSrcweir pDocSh->SetVisArea( aNewArea ); 720cdf0e10cSrcweir 721cdf0e10cSrcweir pDocSh->UpdateOle(&aViewData, sal_True); 722cdf0e10cSrcweir 723cdf0e10cSrcweir //! SetDocumentModified? 724cdf0e10cSrcweir if ( pDestDoc->IsChartListenerCollectionNeedsUpdate() ) 725cdf0e10cSrcweir pDestDoc->UpdateChartListenerCollection(); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729cdf0e10cSrcweir // static 730cdf0e10cSrcweir SfxObjectShell* ScTransferObj::SetDrawClipDoc( sal_Bool bAnyOle ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir // update ScGlobal::pDrawClipDocShellRef 733cdf0e10cSrcweir 734cdf0e10cSrcweir delete ScGlobal::pDrawClipDocShellRef; 735cdf0e10cSrcweir if (bAnyOle) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir ScGlobal::pDrawClipDocShellRef = 738cdf0e10cSrcweir new ScDocShellRef(new ScDocShell(SFX_CREATE_MODE_INTERNAL)); // there must be a ref 739cdf0e10cSrcweir (*ScGlobal::pDrawClipDocShellRef)->DoInitNew(NULL); 740cdf0e10cSrcweir return *ScGlobal::pDrawClipDocShellRef; 741cdf0e10cSrcweir } 742cdf0e10cSrcweir else 743cdf0e10cSrcweir { 744cdf0e10cSrcweir ScGlobal::pDrawClipDocShellRef = NULL; 745cdf0e10cSrcweir return NULL; 746cdf0e10cSrcweir } 747cdf0e10cSrcweir } 748cdf0e10cSrcweir 749cdf0e10cSrcweir // static 750cdf0e10cSrcweir void ScTransferObj::StripRefs( ScDocument* pDoc, 751cdf0e10cSrcweir SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY, 752cdf0e10cSrcweir ScDocument* pDestDoc, SCCOL nSubX, SCROW nSubY ) 753cdf0e10cSrcweir { 754cdf0e10cSrcweir if (!pDestDoc) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir pDestDoc = pDoc; 757cdf0e10cSrcweir DBG_ASSERT(nSubX==0&&nSubY==0, "can't move within the document"); 758cdf0e10cSrcweir } 759cdf0e10cSrcweir 760cdf0e10cSrcweir // In a clipboard doc the data don't have to be on the first sheet 761cdf0e10cSrcweir 762cdf0e10cSrcweir SCTAB nSrcTab = 0; 763cdf0e10cSrcweir while (nSrcTab<MAXTAB && !pDoc->HasTable(nSrcTab)) 764cdf0e10cSrcweir ++nSrcTab; 765cdf0e10cSrcweir SCTAB nDestTab = 0; 766cdf0e10cSrcweir while (nDestTab<MAXTAB && !pDestDoc->HasTable(nDestTab)) 767cdf0e10cSrcweir ++nDestTab; 768cdf0e10cSrcweir 769cdf0e10cSrcweir if (!pDoc->HasTable(nSrcTab) || !pDestDoc->HasTable(nDestTab)) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir DBG_ERROR("Sheet not found in ScTransferObj::StripRefs"); 772cdf0e10cSrcweir return; 773cdf0e10cSrcweir } 774cdf0e10cSrcweir 775cdf0e10cSrcweir SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); 776cdf0e10cSrcweir ScRange aRef; 777cdf0e10cSrcweir 778cdf0e10cSrcweir ScCellIterator aIter( pDoc, nStartX, nStartY, nSrcTab, nEndX, nEndY, nSrcTab ); 779cdf0e10cSrcweir ScBaseCell* pCell = aIter.GetFirst(); 780cdf0e10cSrcweir while (pCell) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir if (pCell->GetCellType() == CELLTYPE_FORMULA) 783cdf0e10cSrcweir { 784cdf0e10cSrcweir ScFormulaCell* pFCell = (ScFormulaCell*) pCell; 785cdf0e10cSrcweir sal_Bool bOut = sal_False; 786cdf0e10cSrcweir ScDetectiveRefIter aRefIter( pFCell ); 787cdf0e10cSrcweir while ( !bOut && aRefIter.GetNextRef( aRef ) ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if ( aRef.aStart.Tab() != nSrcTab || aRef.aEnd.Tab() != nSrcTab || 790cdf0e10cSrcweir aRef.aStart.Col() < nStartX || aRef.aEnd.Col() > nEndX || 791cdf0e10cSrcweir aRef.aStart.Row() < nStartY || aRef.aEnd.Row() > nEndY ) 792cdf0e10cSrcweir bOut = sal_True; 793cdf0e10cSrcweir } 794cdf0e10cSrcweir if (bOut) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir SCCOL nCol = aIter.GetCol() - nSubX; 797cdf0e10cSrcweir SCROW nRow = aIter.GetRow() - nSubY; 798cdf0e10cSrcweir 799cdf0e10cSrcweir ScBaseCell* pNew = 0; 800cdf0e10cSrcweir sal_uInt16 nErrCode = pFCell->GetErrCode(); 801cdf0e10cSrcweir if (nErrCode) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir pNew = new ScStringCell( ScGlobal::GetErrorString(nErrCode) ); 804cdf0e10cSrcweir if ( ((const SvxHorJustifyItem*) pDestDoc->GetAttr( 805cdf0e10cSrcweir nCol,nRow,nDestTab, ATTR_HOR_JUSTIFY))->GetValue() == 806cdf0e10cSrcweir SVX_HOR_JUSTIFY_STANDARD ) 807cdf0e10cSrcweir pDestDoc->ApplyAttr( nCol,nRow,nDestTab, 808cdf0e10cSrcweir SvxHorJustifyItem(SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY) ); 809cdf0e10cSrcweir } 810cdf0e10cSrcweir else if (pFCell->IsValue()) 811cdf0e10cSrcweir { 812cdf0e10cSrcweir double fVal = pFCell->GetValue(); 813cdf0e10cSrcweir pNew = new ScValueCell( fVal ); 814cdf0e10cSrcweir } 815cdf0e10cSrcweir else 816cdf0e10cSrcweir { 817cdf0e10cSrcweir String aStr; 818cdf0e10cSrcweir pFCell->GetString(aStr); 819cdf0e10cSrcweir if ( pFCell->IsMultilineResult() ) 820cdf0e10cSrcweir pNew = new ScEditCell( aStr, pDestDoc ); 821cdf0e10cSrcweir else 822cdf0e10cSrcweir pNew = new ScStringCell( aStr ); 823cdf0e10cSrcweir } 824cdf0e10cSrcweir pDestDoc->PutCell( nCol,nRow,nDestTab, pNew ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir // number formats 827cdf0e10cSrcweir 828cdf0e10cSrcweir sal_uLong nOldFormat = ((const SfxUInt32Item*) 829cdf0e10cSrcweir pDestDoc->GetAttr(nCol,nRow,nDestTab, ATTR_VALUE_FORMAT))->GetValue(); 830cdf0e10cSrcweir if ( (nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir sal_uLong nNewFormat = pFCell->GetStandardFormat( *pFormatter, 833cdf0e10cSrcweir nOldFormat ); 834cdf0e10cSrcweir pDestDoc->ApplyAttr( nCol,nRow,nDestTab, 835cdf0e10cSrcweir SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) ); 836cdf0e10cSrcweir } 837cdf0e10cSrcweir } 838cdf0e10cSrcweir } 839cdf0e10cSrcweir pCell = aIter.GetNext(); 840cdf0e10cSrcweir } 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir const com::sun::star::uno::Sequence< sal_Int8 >& ScTransferObj::getUnoTunnelId() 844cdf0e10cSrcweir { 845cdf0e10cSrcweir static com::sun::star::uno::Sequence< sal_Int8 > aSeq; 846cdf0e10cSrcweir if( !aSeq.getLength() ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir static osl::Mutex aCreateMutex; 849cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( aCreateMutex ); 850cdf0e10cSrcweir aSeq.realloc( 16 ); 851cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); 852cdf0e10cSrcweir } 853cdf0e10cSrcweir return aSeq; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir sal_Int64 SAL_CALL ScTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException ) 857cdf0e10cSrcweir { 858cdf0e10cSrcweir sal_Int64 nRet; 859cdf0e10cSrcweir if( ( rId.getLength() == 16 ) && 860cdf0e10cSrcweir ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir nRet = reinterpret_cast< sal_Int64 >( this ); 863cdf0e10cSrcweir } 864cdf0e10cSrcweir else 865cdf0e10cSrcweir nRet = TransferableHelper::getSomething(rId); 866cdf0e10cSrcweir return nRet; 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir 870