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