xref: /AOO41X/main/sc/source/ui/app/seltrans.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <com/sun/star/beans/XPropertySet.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/form/FormButtonType.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <tools/urlobj.hxx>
40*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
41*cdf0e10cSrcweir #include <svx/fmglob.hxx>
42*cdf0e10cSrcweir #include <svx/svdograf.hxx>
43*cdf0e10cSrcweir #include <svx/svdouno.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "seltrans.hxx"
46*cdf0e10cSrcweir #include "transobj.hxx"
47*cdf0e10cSrcweir #include "drwtrans.hxx"
48*cdf0e10cSrcweir #include "scmod.hxx"
49*cdf0e10cSrcweir #include "dbfunc.hxx"	// for CopyToClip
50*cdf0e10cSrcweir #include "docsh.hxx"
51*cdf0e10cSrcweir #include "drawview.hxx"
52*cdf0e10cSrcweir #include "drwlayer.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace com::sun::star;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // -----------------------------------------------------------------------
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir sal_Bool lcl_IsURLButton( SdrObject* pObject )
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
63*cdf0e10cSrcweir 	if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
64*cdf0e10cSrcweir    	{
65*cdf0e10cSrcweir 		uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
66*cdf0e10cSrcweir 		DBG_ASSERT( xControlModel.is(), "uno control without model" );
67*cdf0e10cSrcweir 		if ( xControlModel.is() )
68*cdf0e10cSrcweir 		{
69*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
70*cdf0e10cSrcweir 			uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 			rtl::OUString sPropButtonType = rtl::OUString::createFromAscii( "ButtonType" );
73*cdf0e10cSrcweir 			if(xInfo->hasPropertyByName( sPropButtonType ))
74*cdf0e10cSrcweir 			{
75*cdf0e10cSrcweir 				uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
76*cdf0e10cSrcweir 				form::FormButtonType eTmp;
77*cdf0e10cSrcweir 				if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
78*cdf0e10cSrcweir 					bRet = sal_True;
79*cdf0e10cSrcweir 			}
80*cdf0e10cSrcweir  		}
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	return bRet;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // static
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir ScSelectionTransferObj* ScSelectionTransferObj::CreateFromView( ScTabView* pView )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	ScSelectionTransferObj* pRet = NULL;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	if ( pView )
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		ScSelectionTransferMode eMode = SC_SELTRANS_INVALID;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 		SdrView* pSdrView = pView->GetSdrView();
97*cdf0e10cSrcweir 		if ( pSdrView )
98*cdf0e10cSrcweir 		{
99*cdf0e10cSrcweir 			//	handle selection on drawing layer
100*cdf0e10cSrcweir 			const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
101*cdf0e10cSrcweir 			sal_uLong nMarkCount = rMarkList.GetMarkCount();
102*cdf0e10cSrcweir 			if ( nMarkCount )
103*cdf0e10cSrcweir 			{
104*cdf0e10cSrcweir 				if ( nMarkCount == 1 )
105*cdf0e10cSrcweir 				{
106*cdf0e10cSrcweir 					SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
107*cdf0e10cSrcweir 					sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 					if ( nSdrObjKind == OBJ_GRAF )
110*cdf0e10cSrcweir 					{
111*cdf0e10cSrcweir 						if ( ((SdrGrafObj*)pObj)->GetGraphic().GetType() == GRAPHIC_BITMAP )
112*cdf0e10cSrcweir 							eMode = SC_SELTRANS_DRAW_BITMAP;
113*cdf0e10cSrcweir 						else
114*cdf0e10cSrcweir 							eMode = SC_SELTRANS_DRAW_GRAPHIC;
115*cdf0e10cSrcweir 					}
116*cdf0e10cSrcweir 					else if ( nSdrObjKind == OBJ_OLE2 )
117*cdf0e10cSrcweir 						eMode = SC_SELTRANS_DRAW_OLE;
118*cdf0e10cSrcweir 					else if ( lcl_IsURLButton( pObj ) )
119*cdf0e10cSrcweir 						eMode = SC_SELTRANS_DRAW_BOOKMARK;
120*cdf0e10cSrcweir 				}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 				if ( eMode == SC_SELTRANS_INVALID )
123*cdf0e10cSrcweir 					eMode = SC_SELTRANS_DRAW_OTHER;		// something selected but no special selection
124*cdf0e10cSrcweir 			}
125*cdf0e10cSrcweir 		}
126*cdf0e10cSrcweir 		if ( eMode == SC_SELTRANS_INVALID )				// no drawing object selected
127*cdf0e10cSrcweir 		{
128*cdf0e10cSrcweir 			ScRange aRange;
129*cdf0e10cSrcweir 			ScViewData* pViewData = pView->GetViewData();
130*cdf0e10cSrcweir 			const ScMarkData& rMark = pViewData->GetMarkData();
131*cdf0e10cSrcweir 			//	allow MultiMarked because GetSimpleArea may be able to merge into a simple range
132*cdf0e10cSrcweir 			//	(GetSimpleArea modifies a local copy of MarkData)
133*cdf0e10cSrcweir             // Also allow simple filtered area.
134*cdf0e10cSrcweir             ScMarkType eMarkType;
135*cdf0e10cSrcweir 			if ( ( rMark.IsMarked() || rMark.IsMultiMarked() ) &&
136*cdf0e10cSrcweir                     (((eMarkType = pViewData->GetSimpleArea( aRange )) == SC_MARK_SIMPLE) ||
137*cdf0e10cSrcweir                      (eMarkType == SC_MARK_SIMPLE_FILTERED)) )
138*cdf0e10cSrcweir 			{
139*cdf0e10cSrcweir 				//	only for "real" selection, cursor alone isn't used
140*cdf0e10cSrcweir 				if ( aRange.aStart == aRange.aEnd )
141*cdf0e10cSrcweir 					eMode = SC_SELTRANS_CELL;
142*cdf0e10cSrcweir 				else
143*cdf0e10cSrcweir 					eMode = SC_SELTRANS_CELLS;
144*cdf0e10cSrcweir 			}
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		if ( eMode != SC_SELTRANS_INVALID )
148*cdf0e10cSrcweir 			pRet = new ScSelectionTransferObj( pView, eMode );
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	return pRet;
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir ScSelectionTransferObj::ScSelectionTransferObj( ScTabView* pSource, ScSelectionTransferMode eNewMode ) :
156*cdf0e10cSrcweir 	pView( pSource ),
157*cdf0e10cSrcweir 	eMode( eNewMode ),
158*cdf0e10cSrcweir 	pCellData( NULL ),
159*cdf0e10cSrcweir 	pDrawData( NULL )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	//!	store range for StillValid
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir ScSelectionTransferObj::~ScSelectionTransferObj()
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
167*cdf0e10cSrcweir 	if ( pScMod->GetSelectionTransfer() == this )
168*cdf0e10cSrcweir 	{
169*cdf0e10cSrcweir 		//	this is reached when the object wasn't really copied to the selection
170*cdf0e10cSrcweir 		//	(CopyToSelection has no effect under Windows)
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		ForgetView();
173*cdf0e10cSrcweir 		pScMod->SetSelectionTransfer( NULL );
174*cdf0e10cSrcweir 	}
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	DBG_ASSERT( !pView, "ScSelectionTransferObj dtor: ForgetView not called" );
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir sal_Bool ScSelectionTransferObj::StillValid()
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	//!	check if view still has same cell selection
182*cdf0e10cSrcweir 	//!	(but return sal_False if data has changed inbetween)
183*cdf0e10cSrcweir 	return sal_False;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir void ScSelectionTransferObj::ForgetView()
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	pView = NULL;
189*cdf0e10cSrcweir 	eMode = SC_SELTRANS_INVALID;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	if (pCellData)
192*cdf0e10cSrcweir 	{
193*cdf0e10cSrcweir 		pCellData->release();
194*cdf0e10cSrcweir 		pCellData = NULL;
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir 	if (pDrawData)
197*cdf0e10cSrcweir 	{
198*cdf0e10cSrcweir 		pDrawData->release();
199*cdf0e10cSrcweir 		pDrawData = NULL;
200*cdf0e10cSrcweir 	}
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void ScSelectionTransferObj::AddSupportedFormats()
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	//	AddSupportedFormats must work without actually creating the
206*cdf0e10cSrcweir 	//	"real" transfer object
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	switch (eMode)
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		case SC_SELTRANS_CELL:
211*cdf0e10cSrcweir 		case SC_SELTRANS_CELLS:
212*cdf0e10cSrcweir 			//	same formats as in ScTransferObj::AddSupportedFormats
213*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
214*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
215*cdf0e10cSrcweir 			AddFormat( SOT_FORMAT_GDIMETAFILE );
216*cdf0e10cSrcweir 			AddFormat( SOT_FORMAT_BITMAP );
217*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_HTML );
218*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_SYLK );
219*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_LINK );
220*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_DIF );
221*cdf0e10cSrcweir 			AddFormat( SOT_FORMAT_STRING );
222*cdf0e10cSrcweir 			AddFormat( SOT_FORMAT_RTF );
223*cdf0e10cSrcweir 			if ( eMode == SC_SELTRANS_CELL )
224*cdf0e10cSrcweir 				AddFormat( SOT_FORMATSTR_ID_EDITENGINE );
225*cdf0e10cSrcweir 			break;
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 		// different graphic formats as in ScDrawTransferObj::AddSupportedFormats:
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_BITMAP:
230*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
231*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_SVXB );
232*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_BITMAP );
233*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_GDIMETAFILE );
234*cdf0e10cSrcweir 			break;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_GRAPHIC:
237*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
238*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_SVXB );
239*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_GDIMETAFILE );
240*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_BITMAP );
241*cdf0e10cSrcweir  			break;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_BOOKMARK:
244*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
245*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_SOLK );
246*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_STRING );
247*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
248*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
249*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_DRAWING );
250*cdf0e10cSrcweir 			break;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_OLE:
253*cdf0e10cSrcweir 			AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
254*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
255*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_GDIMETAFILE );
256*cdf0e10cSrcweir 			break;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_OTHER:
259*cdf0e10cSrcweir 			//	other drawing objects
260*cdf0e10cSrcweir 	        AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
261*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
262*cdf0e10cSrcweir         	AddFormat( SOT_FORMATSTR_ID_DRAWING );
263*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_BITMAP );
264*cdf0e10cSrcweir         	AddFormat( SOT_FORMAT_GDIMETAFILE );
265*cdf0e10cSrcweir 			break;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         default:
268*cdf0e10cSrcweir         {
269*cdf0e10cSrcweir             // added to avoid warnings
270*cdf0e10cSrcweir         }
271*cdf0e10cSrcweir 	}
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void ScSelectionTransferObj::CreateCellData()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	DBG_ASSERT( !pCellData, "CreateCellData twice" );
277*cdf0e10cSrcweir 	if ( pView )
278*cdf0e10cSrcweir 	{
279*cdf0e10cSrcweir 		ScViewData* pViewData = pView->GetViewData();
280*cdf0e10cSrcweir 		ScMarkData aNewMark( pViewData->GetMarkData() );	// use local copy for MarkToSimple
281*cdf0e10cSrcweir 		aNewMark.MarkToSimple();
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 		//	similar to ScViewFunctionSet::BeginDrag
284*cdf0e10cSrcweir 		if ( aNewMark.IsMarked() && !aNewMark.IsMultiMarked() )
285*cdf0e10cSrcweir 		{
286*cdf0e10cSrcweir 			ScDocShell* pDocSh = pViewData->GetDocShell();
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 			ScRange aSelRange;
289*cdf0e10cSrcweir 			aNewMark.GetMarkArea( aSelRange );
290*cdf0e10cSrcweir 			ScDocShellRef aDragShellRef;
291*cdf0e10cSrcweir 			if ( pDocSh->GetDocument()->HasOLEObjectsInArea( aSelRange, &aNewMark ) )
292*cdf0e10cSrcweir 			{
293*cdf0e10cSrcweir 				aDragShellRef = new ScDocShell;		// DocShell needs a Ref immediately
294*cdf0e10cSrcweir 				aDragShellRef->DoInitNew(NULL);
295*cdf0e10cSrcweir 			}
296*cdf0e10cSrcweir 			ScDrawLayer::SetGlobalDrawPersist(aDragShellRef);
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 			ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
299*cdf0e10cSrcweir 			// bApi = sal_True -> no error mesages
300*cdf0e10cSrcweir 			// #i18364# bStopEdit = sal_False -> don't end edit mode
301*cdf0e10cSrcweir 			// (this may be called from pasting into the edit line)
302*cdf0e10cSrcweir 			sal_Bool bCopied = pViewData->GetView()->CopyToClip( pClipDoc, sal_False, sal_True, sal_True, sal_False );
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 			ScDrawLayer::SetGlobalDrawPersist(NULL);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 			if ( bCopied )
307*cdf0e10cSrcweir 			{
308*cdf0e10cSrcweir 				TransferableObjectDescriptor aObjDesc;
309*cdf0e10cSrcweir 				pDocSh->FillTransferableObjectDescriptor( aObjDesc );
310*cdf0e10cSrcweir 				aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
311*cdf0e10cSrcweir 				// maSize is set in ScTransferObj ctor
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 				ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
314*cdf0e10cSrcweir 				uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 				// SetDragHandlePos is not used - there is no mouse position
317*cdf0e10cSrcweir 				//? pTransferObj->SetVisibleTab( nTab );
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir                 SfxObjectShellRef aPersistRef( aDragShellRef );
320*cdf0e10cSrcweir 				pTransferObj->SetDrawPersist( aPersistRef );	// keep persist for ole objects alive
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 				pTransferObj->SetDragSource( pDocSh, aNewMark );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 				pCellData = pTransferObj;
325*cdf0e10cSrcweir 				pCellData->acquire();		// keep ref count up - released in ForgetView
326*cdf0e10cSrcweir 			}
327*cdf0e10cSrcweir 			else
328*cdf0e10cSrcweir 				delete pClipDoc;
329*cdf0e10cSrcweir 		}
330*cdf0e10cSrcweir 	}
331*cdf0e10cSrcweir 	DBG_ASSERT( pCellData, "can't create CellData" );
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir //!	make static member of ScDrawView
335*cdf0e10cSrcweir extern void lcl_CheckOle( const SdrMarkList& rMarkList, sal_Bool& rAnyOle, sal_Bool& rOneOle );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir void ScSelectionTransferObj::CreateDrawData()
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir 	DBG_ASSERT( !pDrawData, "CreateDrawData twice" );
340*cdf0e10cSrcweir 	if ( pView )
341*cdf0e10cSrcweir 	{
342*cdf0e10cSrcweir 		//	similar to ScDrawView::BeginDrag
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 		ScDrawView* pDrawView = pView->GetScDrawView();
345*cdf0e10cSrcweir 		if ( pDrawView )
346*cdf0e10cSrcweir 		{
347*cdf0e10cSrcweir 			sal_Bool bAnyOle, bOneOle;
348*cdf0e10cSrcweir 			const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
349*cdf0e10cSrcweir 			lcl_CheckOle( rMarkList, bAnyOle, bOneOle );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 			//---------------------------------------------------------
352*cdf0e10cSrcweir 			ScDocShellRef aDragShellRef;
353*cdf0e10cSrcweir 			if (bAnyOle)
354*cdf0e10cSrcweir 			{
355*cdf0e10cSrcweir 				aDragShellRef = new ScDocShell;		// ohne Ref lebt die DocShell nicht !!!
356*cdf0e10cSrcweir 				aDragShellRef->DoInitNew(NULL);
357*cdf0e10cSrcweir 			}
358*cdf0e10cSrcweir 			//---------------------------------------------------------
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 			ScDrawLayer::SetGlobalDrawPersist(aDragShellRef);
361*cdf0e10cSrcweir 			SdrModel* pModel = pDrawView->GetAllMarkedModel();
362*cdf0e10cSrcweir 			ScDrawLayer::SetGlobalDrawPersist(NULL);
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 			ScViewData* pViewData = pView->GetViewData();
365*cdf0e10cSrcweir 			ScDocShell* pDocSh = pViewData->GetDocShell();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 			TransferableObjectDescriptor aObjDesc;
368*cdf0e10cSrcweir 			pDocSh->FillTransferableObjectDescriptor( aObjDesc );
369*cdf0e10cSrcweir 			aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
370*cdf0e10cSrcweir 			// maSize is set in ScDrawTransferObj ctor
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 			ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pModel, pDocSh, aObjDesc );
373*cdf0e10cSrcweir 			uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir             SfxObjectShellRef aPersistRef( aDragShellRef );
376*cdf0e10cSrcweir 			pTransferObj->SetDrawPersist( aPersistRef );	// keep persist for ole objects alive
377*cdf0e10cSrcweir 			pTransferObj->SetDragSource( pDrawView );		// copies selection
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 			pDrawData = pTransferObj;
380*cdf0e10cSrcweir 			pDrawData->acquire();		// keep ref count up - released in ForgetView
381*cdf0e10cSrcweir 		}
382*cdf0e10cSrcweir 	}
383*cdf0e10cSrcweir 	DBG_ASSERT( pDrawData, "can't create DrawData" );
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir ScTransferObj* ScSelectionTransferObj::GetCellData()
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir 	if ( !pCellData && ( eMode == SC_SELTRANS_CELL || eMode == SC_SELTRANS_CELLS ) )
389*cdf0e10cSrcweir 		CreateCellData();
390*cdf0e10cSrcweir 	return pCellData;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir ScDrawTransferObj* ScSelectionTransferObj::GetDrawData()
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir 	if ( !pDrawData && ( eMode == SC_SELTRANS_DRAW_BITMAP || eMode == SC_SELTRANS_DRAW_GRAPHIC ||
396*cdf0e10cSrcweir 						 eMode == SC_SELTRANS_DRAW_BOOKMARK || eMode == SC_SELTRANS_DRAW_OLE ||
397*cdf0e10cSrcweir 						 eMode == SC_SELTRANS_DRAW_OTHER ) )
398*cdf0e10cSrcweir 		CreateDrawData();
399*cdf0e10cSrcweir 	return pDrawData;
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir sal_Bool ScSelectionTransferObj::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir 	sal_Bool bOK = sal_False;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 	uno::Reference<datatransfer::XTransferable> xSource;
407*cdf0e10cSrcweir 	switch (eMode)
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir 		case SC_SELTRANS_CELL:
410*cdf0e10cSrcweir 		case SC_SELTRANS_CELLS:
411*cdf0e10cSrcweir 			xSource = GetCellData();
412*cdf0e10cSrcweir 			break;
413*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_BITMAP:
414*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_GRAPHIC:
415*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_BOOKMARK:
416*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_OLE:
417*cdf0e10cSrcweir 		case SC_SELTRANS_DRAW_OTHER:
418*cdf0e10cSrcweir 			xSource = GetDrawData();
419*cdf0e10cSrcweir 			break;
420*cdf0e10cSrcweir         default:
421*cdf0e10cSrcweir         {
422*cdf0e10cSrcweir             // added to avoid warnings
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir 	}
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 	if ( xSource.is() )
427*cdf0e10cSrcweir 	{
428*cdf0e10cSrcweir 		TransferableDataHelper aHelper( xSource );
429*cdf0e10cSrcweir 		uno::Any aAny = aHelper.GetAny( rFlavor );
430*cdf0e10cSrcweir 		bOK = SetAny( aAny, rFlavor );
431*cdf0e10cSrcweir 	}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	return bOK;
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir void ScSelectionTransferObj::ObjectReleased()
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir 	//	called when another selection is set from outside
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 	ForgetView();
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
443*cdf0e10cSrcweir 	if ( pScMod->GetSelectionTransfer() == this )
444*cdf0e10cSrcweir 		pScMod->SetSelectionTransfer( NULL );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 	TransferableHelper::ObjectReleased();
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 
450