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