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() ); 34545fd3b9aSArmin Le Grand bOK = SetBitmapEx( aBmp, rFlavor ); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir else if ( nFormat == SOT_FORMAT_GDIMETAFILE ) 348cdf0e10cSrcweir { 349*474a1d93SArmin Le Grand // #123405# Do not limit visual size calculation for metafile creation. 350*474a1d93SArmin Le Grand // It seems unlikely that removing the limitation causes problems since 351*474a1d93SArmin Le Grand // metafile creation means that no real pixel device in the needed size is 352*474a1d93SArmin Le Grand // created. 353*474a1d93SArmin Le Grand InitDocShell(false); 354*474a1d93SArmin Le Grand 355cdf0e10cSrcweir SfxObjectShell* pEmbObj = aDocShellRef; 356cdf0e10cSrcweir 357cdf0e10cSrcweir // like SvEmbeddedTransfer::GetData: 358cdf0e10cSrcweir GDIMetaFile aMtf; 359cdf0e10cSrcweir VirtualDevice aVDev; 360cdf0e10cSrcweir MapMode aMapMode( pEmbObj->GetMapUnit() ); 361cdf0e10cSrcweir Rectangle aVisArea( pEmbObj->GetVisArea( ASPECT_CONTENT ) ); 362cdf0e10cSrcweir 363cdf0e10cSrcweir aVDev.EnableOutput( sal_False ); 364cdf0e10cSrcweir aVDev.SetMapMode( aMapMode ); 365cdf0e10cSrcweir aMtf.SetPrefSize( aVisArea.GetSize() ); 366cdf0e10cSrcweir aMtf.SetPrefMapMode( aMapMode ); 367cdf0e10cSrcweir aMtf.Record( &aVDev ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir pEmbObj->DoDraw( &aVDev, Point(), aVisArea.GetSize(), JobSetup(), ASPECT_CONTENT ); 370cdf0e10cSrcweir 371cdf0e10cSrcweir aMtf.Stop(); 372cdf0e10cSrcweir aMtf.WindStart(); 373cdf0e10cSrcweir 374cdf0e10cSrcweir bOK = SetGDIMetaFile( aMtf, rFlavor ); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir else if ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir //TODO/LATER: differentiate between formats?! 379*474a1d93SArmin Le Grand // #123405# Do limit visual size calculation to PageSize 380*474a1d93SArmin Le Grand InitDocShell(true); // set aDocShellRef 381cdf0e10cSrcweir 382cdf0e10cSrcweir SfxObjectShell* pEmbObj = aDocShellRef; 383cdf0e10cSrcweir bOK = SetObject( pEmbObj, SCTRANS_TYPE_EMBOBJ, rFlavor ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir return bOK; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir sal_Bool ScTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, 390cdf0e10cSrcweir const datatransfer::DataFlavor& rFlavor ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir // called from SetObject, put data into stream 393cdf0e10cSrcweir 394cdf0e10cSrcweir sal_Bool bRet = sal_False; 395cdf0e10cSrcweir switch (nUserObjectId) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir case SCTRANS_TYPE_IMPEX: 398cdf0e10cSrcweir { 399cdf0e10cSrcweir ScImportExport* pImpEx = (ScImportExport*)pUserObject; 400cdf0e10cSrcweir 401cdf0e10cSrcweir sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor ); 402cdf0e10cSrcweir // mba: no BaseURL for data exchange 403cdf0e10cSrcweir if ( pImpEx->ExportStream( *rxOStm, String(), nFormat ) ) 404cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE ); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir break; 407cdf0e10cSrcweir 408cdf0e10cSrcweir case SCTRANS_TYPE_EDIT_RTF: 409cdf0e10cSrcweir case SCTRANS_TYPE_EDIT_BIN: 410cdf0e10cSrcweir { 411cdf0e10cSrcweir ScTabEditEngine* pEngine = (ScTabEditEngine*)pUserObject; 412cdf0e10cSrcweir if ( nUserObjectId == SCTRANS_TYPE_EDIT_RTF ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir pEngine->Write( *rxOStm, EE_FORMAT_RTF ); 415cdf0e10cSrcweir bRet = ( rxOStm->GetError() == ERRCODE_NONE ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir else 418cdf0e10cSrcweir { 419cdf0e10cSrcweir // #107722# can't use Write for EditEngine format because that would 420cdf0e10cSrcweir // write old format without support for unicode characters. 421cdf0e10cSrcweir // Get the data from the EditEngine's transferable instead. 422cdf0e10cSrcweir 423cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 424cdf0e10cSrcweir if ( nParCnt == 0 ) 425cdf0e10cSrcweir nParCnt = 1; 426cdf0e10cSrcweir ESelection aSel( 0, 0, nParCnt-1, pEngine->GetTextLen(nParCnt-1) ); 427cdf0e10cSrcweir 428cdf0e10cSrcweir uno::Reference<datatransfer::XTransferable> xEditTrans = pEngine->CreateTransferable( aSel ); 429cdf0e10cSrcweir TransferableDataHelper aEditHelper( xEditTrans ); 430cdf0e10cSrcweir 431cdf0e10cSrcweir bRet = aEditHelper.GetSotStorageStream( rFlavor, rxOStm ); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir } 434cdf0e10cSrcweir break; 435cdf0e10cSrcweir 436cdf0e10cSrcweir case SCTRANS_TYPE_EMBOBJ: 437cdf0e10cSrcweir { 438cdf0e10cSrcweir // TODO/MBA: testing 439cdf0e10cSrcweir SfxObjectShell* pEmbObj = (SfxObjectShell*) pUserObject; 440cdf0e10cSrcweir ::utl::TempFile aTempFile; 441cdf0e10cSrcweir aTempFile.EnableKillingFile(); 442cdf0e10cSrcweir uno::Reference< embed::XStorage > xWorkStore = 443cdf0e10cSrcweir ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE ); 444cdf0e10cSrcweir 445cdf0e10cSrcweir // write document storage 446cdf0e10cSrcweir pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir // mba: no relative ULRs for clipboard! 449cdf0e10cSrcweir SfxMedium aMedium( xWorkStore, String() ); 450cdf0e10cSrcweir bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False ); 451cdf0e10cSrcweir pEmbObj->DoSaveCompleted(); 452cdf0e10cSrcweir 453cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY ); 454cdf0e10cSrcweir if ( xTransact.is() ) 455cdf0e10cSrcweir xTransact->commit(); 456cdf0e10cSrcweir 457cdf0e10cSrcweir SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ); 458cdf0e10cSrcweir if( pSrcStm ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir rxOStm->SetBufferSize( 0xff00 ); 461cdf0e10cSrcweir *rxOStm << *pSrcStm; 462cdf0e10cSrcweir delete pSrcStm; 463cdf0e10cSrcweir } 464cdf0e10cSrcweir 465cdf0e10cSrcweir bRet = sal_True; 466cdf0e10cSrcweir 467cdf0e10cSrcweir xWorkStore->dispose(); 468cdf0e10cSrcweir xWorkStore = uno::Reference < embed::XStorage >(); 469cdf0e10cSrcweir rxOStm->Commit(); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir break; 472cdf0e10cSrcweir 473cdf0e10cSrcweir default: 474cdf0e10cSrcweir DBG_ERROR("unknown object id"); 475cdf0e10cSrcweir } 476cdf0e10cSrcweir return bRet; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir void ScTransferObj::ObjectReleased() 480cdf0e10cSrcweir { 481cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 482cdf0e10cSrcweir if ( pScMod->GetClipData().pCellClipboard == this ) 483cdf0e10cSrcweir pScMod->SetClipObject( NULL, NULL ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir TransferableHelper::ObjectReleased(); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir void ScTransferObj::DragFinished( sal_Int8 nDropAction ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir // move: delete source data 493cdf0e10cSrcweir ScDocShell* pSourceSh = GetSourceDocShell(); 494cdf0e10cSrcweir if (pSourceSh) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir ScMarkData aMarkData = GetSourceMarkData(); 497cdf0e10cSrcweir // external drag&drop doesn't copy objects, so they also aren't deleted: 498cdf0e10cSrcweir // #105703# bApi=sal_True, don't show error messages from drag&drop 499cdf0e10cSrcweir pSourceSh->GetDocFunc().DeleteContents( aMarkData, IDF_ALL & ~IDF_OBJECTS, sal_True, sal_True ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir } 502cdf0e10cSrcweir 503cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 504cdf0e10cSrcweir if ( pScMod->GetDragData().pCellTransfer == this ) 505cdf0e10cSrcweir pScMod->ResetDragObject(); 506cdf0e10cSrcweir 507cdf0e10cSrcweir xDragSourceRanges = NULL; // don't keep source after dropping 508cdf0e10cSrcweir 509cdf0e10cSrcweir TransferableHelper::DragFinished( nDropAction ); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir void ScTransferObj::SetDragHandlePos( SCCOL nX, SCROW nY ) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir nDragHandleX = nX; 515cdf0e10cSrcweir nDragHandleY = nY; 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir void ScTransferObj::SetVisibleTab( SCTAB nNew ) 519cdf0e10cSrcweir { 520cdf0e10cSrcweir nVisibleTab = nNew; 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir void ScTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir aDrawPersistRef = rRef; 526cdf0e10cSrcweir } 527cdf0e10cSrcweir 528cdf0e10cSrcweir void ScTransferObj::SetDragSource( ScDocShell* pSourceShell, const ScMarkData& rMark ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir ScRangeList aRanges; 531cdf0e10cSrcweir rMark.FillRangeListWithMarks( &aRanges, sal_False ); 532cdf0e10cSrcweir xDragSourceRanges = new ScCellRangesObj( pSourceShell, aRanges ); 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir void ScTransferObj::SetDragSourceFlags( sal_uInt16 nFlags ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir nDragSourceFlags = nFlags; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir void ScTransferObj::SetDragWasInternal() 541cdf0e10cSrcweir { 542cdf0e10cSrcweir bDragWasInternal = sal_True; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir void ScTransferObj::SetUseInApi( bool bSet ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir bUseInApi = bSet; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir ScDocument* ScTransferObj::GetSourceDocument() 551cdf0e10cSrcweir { 552cdf0e10cSrcweir ScDocShell* pSourceDocSh = GetSourceDocShell(); 553cdf0e10cSrcweir if (pSourceDocSh) 554cdf0e10cSrcweir return pSourceDocSh->GetDocument(); 555cdf0e10cSrcweir return NULL; 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir ScDocShell* ScTransferObj::GetSourceDocShell() 559cdf0e10cSrcweir { 560cdf0e10cSrcweir ScCellRangesBase* pRangesObj = ScCellRangesBase::getImplementation( xDragSourceRanges ); 561cdf0e10cSrcweir if (pRangesObj) 562cdf0e10cSrcweir return pRangesObj->GetDocShell(); 563cdf0e10cSrcweir 564cdf0e10cSrcweir return NULL; // none set 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir ScMarkData ScTransferObj::GetSourceMarkData() 568cdf0e10cSrcweir { 569cdf0e10cSrcweir ScMarkData aMarkData; 570cdf0e10cSrcweir ScCellRangesBase* pRangesObj = ScCellRangesBase::getImplementation( xDragSourceRanges ); 571cdf0e10cSrcweir if (pRangesObj) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir const ScRangeList& rRanges = pRangesObj->GetRangeList(); 574cdf0e10cSrcweir aMarkData.MarkFromRangeList( rRanges, sal_False ); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir return aMarkData; 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir // 580cdf0e10cSrcweir // initialize aDocShellRef with a live document from the ClipDoc 581cdf0e10cSrcweir // 582*474a1d93SArmin Le Grand // #123405# added parameter to allow size calculation without limitation 583*474a1d93SArmin Le Grand // to PageSize, e.g. used for Metafile creation for clipboard. 584cdf0e10cSrcweir 585*474a1d93SArmin Le Grand void ScTransferObj::InitDocShell(bool bLimitToPageSize) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir if ( !aDocShellRef.Is() ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir ScDocShell* pDocSh = new ScDocShell; 590cdf0e10cSrcweir aDocShellRef = pDocSh; // ref must be there before InitNew 591cdf0e10cSrcweir 592cdf0e10cSrcweir pDocSh->DoInitNew(NULL); 593cdf0e10cSrcweir 594cdf0e10cSrcweir ScDocument* pDestDoc = pDocSh->GetDocument(); 595cdf0e10cSrcweir ScMarkData aDestMark; 596cdf0e10cSrcweir aDestMark.SelectTable( 0, sal_True ); 597cdf0e10cSrcweir 598cdf0e10cSrcweir pDestDoc->SetDocOptions( pDoc->GetDocOptions() ); // #i42666# 599cdf0e10cSrcweir 600cdf0e10cSrcweir String aTabName; 601cdf0e10cSrcweir pDoc->GetName( aBlock.aStart.Tab(), aTabName ); 602cdf0e10cSrcweir pDestDoc->RenameTab( 0, aTabName, sal_False ); // no UpdateRef (empty) 603cdf0e10cSrcweir 604cdf0e10cSrcweir pDestDoc->CopyStdStylesFrom( pDoc ); 605cdf0e10cSrcweir 606cdf0e10cSrcweir SCCOL nStartX = aBlock.aStart.Col(); 607cdf0e10cSrcweir SCROW nStartY = aBlock.aStart.Row(); 608cdf0e10cSrcweir SCCOL nEndX = aBlock.aEnd.Col(); 609cdf0e10cSrcweir SCROW nEndY = aBlock.aEnd.Row(); 610cdf0e10cSrcweir 611cdf0e10cSrcweir // widths / heights 612cdf0e10cSrcweir // (must be copied before CopyFromClip, for drawing objects) 613cdf0e10cSrcweir 614cdf0e10cSrcweir SCCOL nCol, nLastCol; 615cdf0e10cSrcweir SCTAB nSrcTab = aBlock.aStart.Tab(); 616cdf0e10cSrcweir pDestDoc->SetLayoutRTL(0, pDoc->IsLayoutRTL(nSrcTab)); 617cdf0e10cSrcweir for (nCol=nStartX; nCol<=nEndX; nCol++) 618cdf0e10cSrcweir if ( pDoc->ColHidden(nCol, nSrcTab, nLastCol) ) 619cdf0e10cSrcweir pDestDoc->ShowCol( nCol, 0, sal_False ); 620cdf0e10cSrcweir else 621cdf0e10cSrcweir pDestDoc->SetColWidth( nCol, 0, pDoc->GetColWidth( nCol, nSrcTab ) ); 622cdf0e10cSrcweir 623cdf0e10cSrcweir ScBitMaskCompressedArray< SCROW, sal_uInt8> & rDestRowFlags = 624cdf0e10cSrcweir pDestDoc->GetRowFlagsArrayModifiable(0); 625cdf0e10cSrcweir 626cdf0e10cSrcweir for (SCROW nRow = nStartY; nRow <= nEndY; ++nRow) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir sal_uInt8 nSourceFlags = pDoc->GetRowFlags(nRow, nSrcTab); 629cdf0e10cSrcweir SCROW nLastRow = -1; 630cdf0e10cSrcweir if ( pDoc->RowHidden(nRow, nSrcTab, nLastRow) ) 631cdf0e10cSrcweir pDestDoc->ShowRow( nRow, 0, sal_False ); 632cdf0e10cSrcweir else 633cdf0e10cSrcweir { 634cdf0e10cSrcweir pDestDoc->SetRowHeight( nRow, 0, pDoc->GetOriginalHeight( nRow, nSrcTab ) ); 635cdf0e10cSrcweir 636cdf0e10cSrcweir // if height was set manually, that flag has to be copied, too 637cdf0e10cSrcweir if ( nSourceFlags & CR_MANUALSIZE ) 638cdf0e10cSrcweir rDestRowFlags.OrValue( nRow, CR_MANUALSIZE); 639cdf0e10cSrcweir } 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir if ( pDoc->GetDrawLayer() ) 643cdf0e10cSrcweir pDocSh->MakeDrawLayer(); 644cdf0e10cSrcweir 645cdf0e10cSrcweir // cell range is copied to the original position, but on the first sheet 646cdf0e10cSrcweir // -> bCutMode must be set 647cdf0e10cSrcweir // pDoc is always a Clipboard-document 648cdf0e10cSrcweir 649cdf0e10cSrcweir ScRange aDestRange( nStartX,nStartY,0, nEndX,nEndY,0 ); 650cdf0e10cSrcweir sal_Bool bWasCut = pDoc->IsCutMode(); 651cdf0e10cSrcweir if (!bWasCut) 652cdf0e10cSrcweir pDoc->SetClipArea( aDestRange, sal_True ); // Cut 653cdf0e10cSrcweir pDestDoc->CopyFromClip( aDestRange, aDestMark, IDF_ALL, NULL, pDoc, sal_False ); 654cdf0e10cSrcweir pDoc->SetClipArea( aDestRange, bWasCut ); 655cdf0e10cSrcweir 656cdf0e10cSrcweir StripRefs( pDoc, nStartX,nStartY, nEndX,nEndY, pDestDoc, 0,0 ); 657cdf0e10cSrcweir 658cdf0e10cSrcweir ScRange aMergeRange = aDestRange; 659cdf0e10cSrcweir pDestDoc->ExtendMerge( aMergeRange, sal_True ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir pDoc->CopyDdeLinks( pDestDoc ); // copy values of DDE Links 662cdf0e10cSrcweir 663cdf0e10cSrcweir // page format (grid etc) and page size (maximum size for ole object) 664cdf0e10cSrcweir 665cdf0e10cSrcweir Size aPaperSize = SvxPaperInfo::GetPaperSize( PAPER_A4 ); // Twips 666cdf0e10cSrcweir ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); 667cdf0e10cSrcweir String aStyleName = pDoc->GetPageStyle( aBlock.aStart.Tab() ); 668cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE ); 669cdf0e10cSrcweir if (pStyleSheet) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir const SfxItemSet& rSourceSet = pStyleSheet->GetItemSet(); 672cdf0e10cSrcweir aPaperSize = ((const SvxSizeItem&) rSourceSet.Get(ATTR_PAGE_SIZE)).GetSize(); 673cdf0e10cSrcweir 674cdf0e10cSrcweir // CopyStyleFrom kopiert SetItems mit richtigem Pool 675cdf0e10cSrcweir ScStyleSheetPool* pDestPool = pDestDoc->GetStyleSheetPool(); 676cdf0e10cSrcweir pDestPool->CopyStyleFrom( pStylePool, aStyleName, SFX_STYLE_FAMILY_PAGE ); 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir ScViewData aViewData( pDocSh, NULL ); 680cdf0e10cSrcweir aViewData.SetScreen( nStartX,nStartY, nEndX,nEndY ); 681cdf0e10cSrcweir aViewData.SetCurX( nStartX ); 682cdf0e10cSrcweir aViewData.SetCurY( nStartY ); 683cdf0e10cSrcweir 684cdf0e10cSrcweir pDestDoc->SetViewOptions( pDoc->GetViewOptions() ); 685cdf0e10cSrcweir 686cdf0e10cSrcweir // Size 687cdf0e10cSrcweir //! get while copying sizes 688cdf0e10cSrcweir 689cdf0e10cSrcweir long nPosX = 0; 690cdf0e10cSrcweir long nPosY = 0; 691cdf0e10cSrcweir 692cdf0e10cSrcweir for (nCol=0; nCol<nStartX; nCol++) 693cdf0e10cSrcweir nPosX += pDestDoc->GetColWidth( nCol, 0 ); 694cdf0e10cSrcweir nPosY += pDestDoc->GetRowHeight( 0, nStartY-1, 0 ); 695cdf0e10cSrcweir nPosX = (long) ( nPosX * HMM_PER_TWIPS ); 696cdf0e10cSrcweir nPosY = (long) ( nPosY * HMM_PER_TWIPS ); 697cdf0e10cSrcweir 698cdf0e10cSrcweir 699cdf0e10cSrcweir aPaperSize.Width() *= 2; // limit OLE object to double of page size 700cdf0e10cSrcweir aPaperSize.Height() *= 2; 701cdf0e10cSrcweir 702cdf0e10cSrcweir long nSizeX = 0; 703cdf0e10cSrcweir long nSizeY = 0; 704cdf0e10cSrcweir for (nCol=nStartX; nCol<=nEndX; nCol++) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir long nAdd = pDestDoc->GetColWidth( nCol, 0 ); 707*474a1d93SArmin Le Grand if ( bLimitToPageSize && nSizeX+nAdd > aPaperSize.Width() && nSizeX ) // above limit? 708cdf0e10cSrcweir break; 709cdf0e10cSrcweir nSizeX += nAdd; 710cdf0e10cSrcweir } 711cdf0e10cSrcweir for (SCROW nRow=nStartY; nRow<=nEndY; nRow++) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir long nAdd = pDestDoc->GetRowHeight( nRow, 0 ); 714*474a1d93SArmin Le Grand if ( bLimitToPageSize && nSizeY+nAdd > aPaperSize.Height() && nSizeY ) // above limit? 715cdf0e10cSrcweir break; 716cdf0e10cSrcweir nSizeY += nAdd; 717cdf0e10cSrcweir } 718cdf0e10cSrcweir nSizeX = (long) ( nSizeX * HMM_PER_TWIPS ); 719cdf0e10cSrcweir nSizeY = (long) ( nSizeY * HMM_PER_TWIPS ); 720cdf0e10cSrcweir 721cdf0e10cSrcweir // pDocSh->SetVisAreaSize( Size(nSizeX,nSizeY) ); 722cdf0e10cSrcweir 723cdf0e10cSrcweir Rectangle aNewArea( Point(nPosX,nPosY), Size(nSizeX,nSizeY) ); 724cdf0e10cSrcweir //TODO/LATER: why twice?! 725cdf0e10cSrcweir //pDocSh->SvInPlaceObject::SetVisArea( aNewArea ); 726cdf0e10cSrcweir pDocSh->SetVisArea( aNewArea ); 727cdf0e10cSrcweir 728cdf0e10cSrcweir pDocSh->UpdateOle(&aViewData, sal_True); 729cdf0e10cSrcweir 730cdf0e10cSrcweir //! SetDocumentModified? 731cdf0e10cSrcweir if ( pDestDoc->IsChartListenerCollectionNeedsUpdate() ) 732cdf0e10cSrcweir pDestDoc->UpdateChartListenerCollection(); 733cdf0e10cSrcweir } 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir // static 737cdf0e10cSrcweir SfxObjectShell* ScTransferObj::SetDrawClipDoc( sal_Bool bAnyOle ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir // update ScGlobal::pDrawClipDocShellRef 740cdf0e10cSrcweir 741cdf0e10cSrcweir delete ScGlobal::pDrawClipDocShellRef; 742cdf0e10cSrcweir if (bAnyOle) 743cdf0e10cSrcweir { 744cdf0e10cSrcweir ScGlobal::pDrawClipDocShellRef = 745cdf0e10cSrcweir new ScDocShellRef(new ScDocShell(SFX_CREATE_MODE_INTERNAL)); // there must be a ref 746cdf0e10cSrcweir (*ScGlobal::pDrawClipDocShellRef)->DoInitNew(NULL); 747cdf0e10cSrcweir return *ScGlobal::pDrawClipDocShellRef; 748cdf0e10cSrcweir } 749cdf0e10cSrcweir else 750cdf0e10cSrcweir { 751cdf0e10cSrcweir ScGlobal::pDrawClipDocShellRef = NULL; 752cdf0e10cSrcweir return NULL; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir } 755cdf0e10cSrcweir 756cdf0e10cSrcweir // static 757cdf0e10cSrcweir void ScTransferObj::StripRefs( ScDocument* pDoc, 758cdf0e10cSrcweir SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY, 759cdf0e10cSrcweir ScDocument* pDestDoc, SCCOL nSubX, SCROW nSubY ) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir if (!pDestDoc) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir pDestDoc = pDoc; 764cdf0e10cSrcweir DBG_ASSERT(nSubX==0&&nSubY==0, "can't move within the document"); 765cdf0e10cSrcweir } 766cdf0e10cSrcweir 767cdf0e10cSrcweir // In a clipboard doc the data don't have to be on the first sheet 768cdf0e10cSrcweir 769cdf0e10cSrcweir SCTAB nSrcTab = 0; 770cdf0e10cSrcweir while (nSrcTab<MAXTAB && !pDoc->HasTable(nSrcTab)) 771cdf0e10cSrcweir ++nSrcTab; 772cdf0e10cSrcweir SCTAB nDestTab = 0; 773cdf0e10cSrcweir while (nDestTab<MAXTAB && !pDestDoc->HasTable(nDestTab)) 774cdf0e10cSrcweir ++nDestTab; 775cdf0e10cSrcweir 776cdf0e10cSrcweir if (!pDoc->HasTable(nSrcTab) || !pDestDoc->HasTable(nDestTab)) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir DBG_ERROR("Sheet not found in ScTransferObj::StripRefs"); 779cdf0e10cSrcweir return; 780cdf0e10cSrcweir } 781cdf0e10cSrcweir 782cdf0e10cSrcweir SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); 783cdf0e10cSrcweir ScRange aRef; 784cdf0e10cSrcweir 785cdf0e10cSrcweir ScCellIterator aIter( pDoc, nStartX, nStartY, nSrcTab, nEndX, nEndY, nSrcTab ); 786cdf0e10cSrcweir ScBaseCell* pCell = aIter.GetFirst(); 787cdf0e10cSrcweir while (pCell) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if (pCell->GetCellType() == CELLTYPE_FORMULA) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir ScFormulaCell* pFCell = (ScFormulaCell*) pCell; 792cdf0e10cSrcweir sal_Bool bOut = sal_False; 793cdf0e10cSrcweir ScDetectiveRefIter aRefIter( pFCell ); 794cdf0e10cSrcweir while ( !bOut && aRefIter.GetNextRef( aRef ) ) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir if ( aRef.aStart.Tab() != nSrcTab || aRef.aEnd.Tab() != nSrcTab || 797cdf0e10cSrcweir aRef.aStart.Col() < nStartX || aRef.aEnd.Col() > nEndX || 798cdf0e10cSrcweir aRef.aStart.Row() < nStartY || aRef.aEnd.Row() > nEndY ) 799cdf0e10cSrcweir bOut = sal_True; 800cdf0e10cSrcweir } 801cdf0e10cSrcweir if (bOut) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir SCCOL nCol = aIter.GetCol() - nSubX; 804cdf0e10cSrcweir SCROW nRow = aIter.GetRow() - nSubY; 805cdf0e10cSrcweir 806cdf0e10cSrcweir ScBaseCell* pNew = 0; 807cdf0e10cSrcweir sal_uInt16 nErrCode = pFCell->GetErrCode(); 808cdf0e10cSrcweir if (nErrCode) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir pNew = new ScStringCell( ScGlobal::GetErrorString(nErrCode) ); 811cdf0e10cSrcweir if ( ((const SvxHorJustifyItem*) pDestDoc->GetAttr( 812cdf0e10cSrcweir nCol,nRow,nDestTab, ATTR_HOR_JUSTIFY))->GetValue() == 813cdf0e10cSrcweir SVX_HOR_JUSTIFY_STANDARD ) 814cdf0e10cSrcweir pDestDoc->ApplyAttr( nCol,nRow,nDestTab, 815cdf0e10cSrcweir SvxHorJustifyItem(SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY) ); 816cdf0e10cSrcweir } 817cdf0e10cSrcweir else if (pFCell->IsValue()) 818cdf0e10cSrcweir { 819cdf0e10cSrcweir double fVal = pFCell->GetValue(); 820cdf0e10cSrcweir pNew = new ScValueCell( fVal ); 821cdf0e10cSrcweir } 822cdf0e10cSrcweir else 823cdf0e10cSrcweir { 824cdf0e10cSrcweir String aStr; 825cdf0e10cSrcweir pFCell->GetString(aStr); 826cdf0e10cSrcweir if ( pFCell->IsMultilineResult() ) 827cdf0e10cSrcweir pNew = new ScEditCell( aStr, pDestDoc ); 828cdf0e10cSrcweir else 829cdf0e10cSrcweir pNew = new ScStringCell( aStr ); 830cdf0e10cSrcweir } 831cdf0e10cSrcweir pDestDoc->PutCell( nCol,nRow,nDestTab, pNew ); 832cdf0e10cSrcweir 833cdf0e10cSrcweir // number formats 834cdf0e10cSrcweir 835cdf0e10cSrcweir sal_uLong nOldFormat = ((const SfxUInt32Item*) 836cdf0e10cSrcweir pDestDoc->GetAttr(nCol,nRow,nDestTab, ATTR_VALUE_FORMAT))->GetValue(); 837cdf0e10cSrcweir if ( (nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir sal_uLong nNewFormat = pFCell->GetStandardFormat( *pFormatter, 840cdf0e10cSrcweir nOldFormat ); 841cdf0e10cSrcweir pDestDoc->ApplyAttr( nCol,nRow,nDestTab, 842cdf0e10cSrcweir SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) ); 843cdf0e10cSrcweir } 844cdf0e10cSrcweir } 845cdf0e10cSrcweir } 846cdf0e10cSrcweir pCell = aIter.GetNext(); 847cdf0e10cSrcweir } 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir const com::sun::star::uno::Sequence< sal_Int8 >& ScTransferObj::getUnoTunnelId() 851cdf0e10cSrcweir { 852cdf0e10cSrcweir static com::sun::star::uno::Sequence< sal_Int8 > aSeq; 853cdf0e10cSrcweir if( !aSeq.getLength() ) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir static osl::Mutex aCreateMutex; 856cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( aCreateMutex ); 857cdf0e10cSrcweir aSeq.realloc( 16 ); 858cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); 859cdf0e10cSrcweir } 860cdf0e10cSrcweir return aSeq; 861cdf0e10cSrcweir } 862cdf0e10cSrcweir 863cdf0e10cSrcweir sal_Int64 SAL_CALL ScTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir sal_Int64 nRet; 866cdf0e10cSrcweir if( ( rId.getLength() == 16 ) && 867cdf0e10cSrcweir ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir nRet = reinterpret_cast< sal_Int64 >( this ); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir else 872cdf0e10cSrcweir nRet = TransferableHelper::getSomething(rId); 873cdf0e10cSrcweir return nRet; 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir 877