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