1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/beans/XPropertySetInfo.hpp>
22 #include <com/sun/star/form/FormButtonType.hpp>
24 #include <tools/urlobj.hxx>
25 #include <sfx2/docfile.hxx>
26 #include <svx/fmglob.hxx>
27 #include <svx/svdograf.hxx>
28 #include <svx/svdouno.hxx>
30 #include "seltrans.hxx"
31 #include "transobj.hxx"
32 #include "drwtrans.hxx"
36 #include "drawview.hxx"
37 #include "drwlayer.hxx"
38 #include "markdata.hxx"
40 using namespace com::sun::star
;
42 static bool lcl_IsURLButton( SdrObject
* pObject
)
46 SdrUnoObj
* pUnoCtrl
= PTR_CAST(SdrUnoObj
, pObject
);
47 if (pUnoCtrl
&& FmFormInventor
== pUnoCtrl
->GetObjInventor())
49 uno::Reference
<awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
50 OSL_ENSURE( xControlModel
.is(), "uno control without model" );
51 if ( xControlModel
.is() )
53 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
54 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
56 OUString
sPropButtonType( "ButtonType" );
57 if(xInfo
->hasPropertyByName( sPropButtonType
))
59 uno::Any aAny
= xPropSet
->getPropertyValue( sPropButtonType
);
60 form::FormButtonType eTmp
;
61 if ( (aAny
>>= eTmp
) && eTmp
== form::FormButtonType_URL
)
71 ScSelectionTransferObj
* ScSelectionTransferObj::CreateFromView( ScTabView
* pView
)
73 ScSelectionTransferObj
* pRet
= NULL
;
79 ScSelectionTransferMode eMode
= SC_SELTRANS_INVALID
;
81 SdrView
* pSdrView
= pView
->GetSdrView();
84 // handle selection on drawing layer
85 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
86 sal_uLong nMarkCount
= rMarkList
.GetMarkCount();
89 if ( nMarkCount
== 1 )
91 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
92 sal_uInt16 nSdrObjKind
= pObj
->GetObjIdentifier();
94 if ( nSdrObjKind
== OBJ_GRAF
)
96 if ( ((SdrGrafObj
*)pObj
)->GetGraphic().GetType() == GRAPHIC_BITMAP
)
97 eMode
= SC_SELTRANS_DRAW_BITMAP
;
99 eMode
= SC_SELTRANS_DRAW_GRAPHIC
;
101 else if ( nSdrObjKind
== OBJ_OLE2
)
102 eMode
= SC_SELTRANS_DRAW_OLE
;
103 else if ( lcl_IsURLButton( pObj
) )
104 eMode
= SC_SELTRANS_DRAW_BOOKMARK
;
107 if ( eMode
== SC_SELTRANS_INVALID
)
108 eMode
= SC_SELTRANS_DRAW_OTHER
; // something selected but no special selection
111 if ( eMode
== SC_SELTRANS_INVALID
) // no drawing object selected
114 ScViewData
* pViewData
= pView
->GetViewData();
115 const ScMarkData
& rMark
= pViewData
->GetMarkData();
116 // allow MultiMarked because GetSimpleArea may be able to merge into a simple range
117 // (GetSimpleArea modifies a local copy of MarkData)
118 // Also allow simple filtered area.
119 ScMarkType eMarkType
;
120 if ( ( rMark
.IsMarked() || rMark
.IsMultiMarked() ) &&
121 (((eMarkType
= pViewData
->GetSimpleArea( aRange
)) == SC_MARK_SIMPLE
) ||
122 (eMarkType
== SC_MARK_SIMPLE_FILTERED
)) )
124 // only for "real" selection, cursor alone isn't used
125 if ( aRange
.aStart
== aRange
.aEnd
)
126 eMode
= SC_SELTRANS_CELL
;
128 eMode
= SC_SELTRANS_CELLS
;
132 if ( eMode
!= SC_SELTRANS_INVALID
)
133 pRet
= new ScSelectionTransferObj( pView
, eMode
);
144 ScSelectionTransferObj::ScSelectionTransferObj( ScTabView
* pSource
, ScSelectionTransferMode eNewMode
) :
150 //! store range for StillValid
153 ScSelectionTransferObj::~ScSelectionTransferObj()
155 ScModule
* pScMod
= SC_MOD();
156 if ( pScMod
->GetSelectionTransfer() == this )
158 // this is reached when the object wasn't really copied to the selection
159 // (CopyToSelection has no effect under Windows)
162 pScMod
->SetSelectionTransfer( NULL
);
165 OSL_ENSURE( !pView
, "ScSelectionTransferObj dtor: ForgetView not called" );
168 bool ScSelectionTransferObj::StillValid()
170 //! check if view still has same cell selection
171 //! (but return sal_False if data has changed inbetween)
175 void ScSelectionTransferObj::ForgetView()
178 eMode
= SC_SELTRANS_INVALID
;
182 pCellData
->release();
187 pDrawData
->release();
192 void ScSelectionTransferObj::AddSupportedFormats()
194 // AddSupportedFormats must work without actually creating the
195 // "real" transfer object
199 case SC_SELTRANS_CELL
:
200 case SC_SELTRANS_CELLS
:
201 // same formats as in ScTransferObj::AddSupportedFormats
202 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
203 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
204 AddFormat( SOT_FORMAT_GDIMETAFILE
);
205 AddFormat( SOT_FORMATSTR_ID_PNG
);
206 AddFormat( SOT_FORMAT_BITMAP
);
207 AddFormat( SOT_FORMATSTR_ID_HTML
);
208 AddFormat( SOT_FORMATSTR_ID_SYLK
);
209 AddFormat( SOT_FORMATSTR_ID_LINK
);
210 AddFormat( SOT_FORMATSTR_ID_DIF
);
211 AddFormat( SOT_FORMAT_STRING
);
212 AddFormat( SOT_FORMAT_RTF
);
213 if ( eMode
== SC_SELTRANS_CELL
)
214 AddFormat( SOT_FORMATSTR_ID_EDITENGINE
);
217 // different graphic formats as in ScDrawTransferObj::AddSupportedFormats:
219 case SC_SELTRANS_DRAW_BITMAP
:
220 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
221 AddFormat( SOT_FORMATSTR_ID_SVXB
);
222 AddFormat( SOT_FORMATSTR_ID_PNG
);
223 AddFormat( SOT_FORMAT_BITMAP
);
224 AddFormat( SOT_FORMAT_GDIMETAFILE
);
227 case SC_SELTRANS_DRAW_GRAPHIC
:
228 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
229 AddFormat( SOT_FORMATSTR_ID_SVXB
);
230 AddFormat( SOT_FORMAT_GDIMETAFILE
);
231 AddFormat( SOT_FORMATSTR_ID_PNG
);
232 AddFormat( SOT_FORMAT_BITMAP
);
235 case SC_SELTRANS_DRAW_BOOKMARK
:
236 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
237 AddFormat( SOT_FORMATSTR_ID_SOLK
);
238 AddFormat( SOT_FORMAT_STRING
);
239 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR
);
240 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
);
241 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
244 case SC_SELTRANS_DRAW_OLE
:
245 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
246 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
247 AddFormat( SOT_FORMAT_GDIMETAFILE
);
250 case SC_SELTRANS_DRAW_OTHER
:
251 // other drawing objects
252 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
253 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
254 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
255 AddFormat( SOT_FORMATSTR_ID_PNG
);
256 AddFormat( SOT_FORMAT_BITMAP
);
257 AddFormat( SOT_FORMAT_GDIMETAFILE
);
262 // added to avoid warnings
267 void ScSelectionTransferObj::CreateCellData()
269 OSL_ENSURE( !pCellData
, "CreateCellData twice" );
272 ScViewData
* pViewData
= pView
->GetViewData();
273 ScMarkData
aNewMark( pViewData
->GetMarkData() ); // use local copy for MarkToSimple
274 aNewMark
.MarkToSimple();
276 // similar to ScViewFunctionSet::BeginDrag
277 if ( aNewMark
.IsMarked() && !aNewMark
.IsMultiMarked() )
279 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
282 aNewMark
.GetMarkArea( aSelRange
);
283 ScDocShellRef aDragShellRef
;
284 if ( pDocSh
->GetDocument()->HasOLEObjectsInArea( aSelRange
, &aNewMark
) )
286 aDragShellRef
= new ScDocShell
; // DocShell needs a Ref immediately
287 aDragShellRef
->DoInitNew(NULL
);
289 ScDrawLayer::SetGlobalDrawPersist(aDragShellRef
);
291 ScDocument
* pClipDoc
= new ScDocument( SCDOCMODE_CLIP
);
292 // bApi = sal_True -> no error messages
293 // #i18364# bStopEdit = sal_False -> don't end edit mode
294 // (this may be called from pasting into the edit line)
295 bool bCopied
= pViewData
->GetView()->CopyToClip( pClipDoc
, false, true, true, false );
297 ScDrawLayer::SetGlobalDrawPersist(NULL
);
301 TransferableObjectDescriptor aObjDesc
;
302 pDocSh
->FillTransferableObjectDescriptor( aObjDesc
);
303 aObjDesc
.maDisplayName
= pDocSh
->GetMedium()->GetURLObject().GetURLNoPass();
304 // maSize is set in ScTransferObj ctor
306 ScTransferObj
* pTransferObj
= new ScTransferObj( pClipDoc
, aObjDesc
);
307 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
309 // SetDragHandlePos is not used - there is no mouse position
310 //? pTransferObj->SetVisibleTab( nTab );
312 SfxObjectShellRef
aPersistRef( aDragShellRef
);
313 pTransferObj
->SetDrawPersist( aPersistRef
); // keep persist for ole objects alive
315 pTransferObj
->SetDragSource( pDocSh
, aNewMark
);
317 pCellData
= pTransferObj
;
318 pCellData
->acquire(); // keep ref count up - released in ForgetView
324 OSL_ENSURE( pCellData
, "can't create CellData" );
327 void ScSelectionTransferObj::CreateDrawData()
329 OSL_ENSURE( !pDrawData
, "CreateDrawData twice" );
332 // similar to ScDrawView::BeginDrag
334 ScDrawView
* pDrawView
= pView
->GetScDrawView();
337 bool bAnyOle
, bOneOle
;
338 const SdrMarkList
& rMarkList
= pDrawView
->GetMarkedObjectList();
339 ScDrawView::CheckOle( rMarkList
, bAnyOle
, bOneOle
);
342 ScDocShellRef aDragShellRef
;
345 aDragShellRef
= new ScDocShell
; // Without Ref the DocShell does not live
346 aDragShellRef
->DoInitNew(NULL
);
350 ScDrawLayer::SetGlobalDrawPersist(aDragShellRef
);
351 SdrModel
* pModel
= pDrawView
->GetMarkedObjModel();
352 ScDrawLayer::SetGlobalDrawPersist(NULL
);
354 ScViewData
* pViewData
= pView
->GetViewData();
355 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
357 TransferableObjectDescriptor aObjDesc
;
358 pDocSh
->FillTransferableObjectDescriptor( aObjDesc
);
359 aObjDesc
.maDisplayName
= pDocSh
->GetMedium()->GetURLObject().GetURLNoPass();
360 // maSize is set in ScDrawTransferObj ctor
362 ScDrawTransferObj
* pTransferObj
= new ScDrawTransferObj( pModel
, pDocSh
, aObjDesc
);
363 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
365 SfxObjectShellRef
aPersistRef( aDragShellRef
);
366 pTransferObj
->SetDrawPersist( aPersistRef
); // keep persist for ole objects alive
367 pTransferObj
->SetDragSource( pDrawView
); // copies selection
369 pDrawData
= pTransferObj
;
370 pDrawData
->acquire(); // keep ref count up - released in ForgetView
373 OSL_ENSURE( pDrawData
, "can't create DrawData" );
376 ScTransferObj
* ScSelectionTransferObj::GetCellData()
378 if ( !pCellData
&& ( eMode
== SC_SELTRANS_CELL
|| eMode
== SC_SELTRANS_CELLS
) )
383 ScDrawTransferObj
* ScSelectionTransferObj::GetDrawData()
385 if ( !pDrawData
&& ( eMode
== SC_SELTRANS_DRAW_BITMAP
|| eMode
== SC_SELTRANS_DRAW_GRAPHIC
||
386 eMode
== SC_SELTRANS_DRAW_BOOKMARK
|| eMode
== SC_SELTRANS_DRAW_OLE
||
387 eMode
== SC_SELTRANS_DRAW_OTHER
) )
392 bool ScSelectionTransferObj::GetData(
393 const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
)
397 uno::Reference
<datatransfer::XTransferable
> xSource
;
400 case SC_SELTRANS_CELL
:
401 case SC_SELTRANS_CELLS
:
402 xSource
= GetCellData();
404 case SC_SELTRANS_DRAW_BITMAP
:
405 case SC_SELTRANS_DRAW_GRAPHIC
:
406 case SC_SELTRANS_DRAW_BOOKMARK
:
407 case SC_SELTRANS_DRAW_OLE
:
408 case SC_SELTRANS_DRAW_OTHER
:
409 xSource
= GetDrawData();
413 // added to avoid warnings
419 TransferableDataHelper
aHelper( xSource
);
420 uno::Any aAny
= aHelper
.GetAny(rFlavor
, rDestDoc
);
421 bOK
= SetAny( aAny
, rFlavor
);
427 void ScSelectionTransferObj::ObjectReleased()
429 // called when another selection is set from outside
433 ScModule
* pScMod
= SC_MOD();
434 if ( pScMod
->GetSelectionTransfer() == this )
435 pScMod
->SetSelectionTransfer( NULL
);
437 TransferableHelper::ObjectReleased();
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */