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 // -----------------------------------------------------------------------
44 static sal_Bool
lcl_IsURLButton( SdrObject
* pObject
)
46 sal_Bool bRet
= false;
48 SdrUnoObj
* pUnoCtrl
= PTR_CAST(SdrUnoObj
, pObject
);
49 if (pUnoCtrl
&& FmFormInventor
== pUnoCtrl
->GetObjInventor())
51 uno::Reference
<awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
52 OSL_ENSURE( xControlModel
.is(), "uno control without model" );
53 if ( xControlModel
.is() )
55 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
56 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
58 OUString
sPropButtonType( "ButtonType" );
59 if(xInfo
->hasPropertyByName( sPropButtonType
))
61 uno::Any aAny
= xPropSet
->getPropertyValue( sPropButtonType
);
62 form::FormButtonType eTmp
;
63 if ( (aAny
>>= eTmp
) && eTmp
== form::FormButtonType_URL
)
73 ScSelectionTransferObj
* ScSelectionTransferObj::CreateFromView( ScTabView
* pView
)
75 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
);
140 ScSelectionTransferObj::ScSelectionTransferObj( ScTabView
* pSource
, ScSelectionTransferMode eNewMode
) :
146 //! store range for StillValid
149 ScSelectionTransferObj::~ScSelectionTransferObj()
151 ScModule
* pScMod
= SC_MOD();
152 if ( pScMod
->GetSelectionTransfer() == this )
154 // this is reached when the object wasn't really copied to the selection
155 // (CopyToSelection has no effect under Windows)
158 pScMod
->SetSelectionTransfer( NULL
);
161 OSL_ENSURE( !pView
, "ScSelectionTransferObj dtor: ForgetView not called" );
164 sal_Bool
ScSelectionTransferObj::StillValid()
166 //! check if view still has same cell selection
167 //! (but return sal_False if data has changed inbetween)
171 void ScSelectionTransferObj::ForgetView()
174 eMode
= SC_SELTRANS_INVALID
;
178 pCellData
->release();
183 pDrawData
->release();
188 void ScSelectionTransferObj::AddSupportedFormats()
190 // AddSupportedFormats must work without actually creating the
191 // "real" transfer object
195 case SC_SELTRANS_CELL
:
196 case SC_SELTRANS_CELLS
:
197 // same formats as in ScTransferObj::AddSupportedFormats
198 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
199 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
200 AddFormat( SOT_FORMAT_GDIMETAFILE
);
201 AddFormat( SOT_FORMAT_BITMAP
);
202 AddFormat( SOT_FORMATSTR_ID_HTML
);
203 AddFormat( SOT_FORMATSTR_ID_SYLK
);
204 AddFormat( SOT_FORMATSTR_ID_LINK
);
205 AddFormat( SOT_FORMATSTR_ID_DIF
);
206 AddFormat( SOT_FORMAT_STRING
);
207 AddFormat( SOT_FORMAT_RTF
);
208 if ( eMode
== SC_SELTRANS_CELL
)
209 AddFormat( SOT_FORMATSTR_ID_EDITENGINE
);
212 // different graphic formats as in ScDrawTransferObj::AddSupportedFormats:
214 case SC_SELTRANS_DRAW_BITMAP
:
215 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
216 AddFormat( SOT_FORMATSTR_ID_SVXB
);
217 AddFormat( SOT_FORMAT_BITMAP
);
218 AddFormat( SOT_FORMAT_GDIMETAFILE
);
221 case SC_SELTRANS_DRAW_GRAPHIC
:
222 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
223 AddFormat( SOT_FORMATSTR_ID_SVXB
);
224 AddFormat( SOT_FORMAT_GDIMETAFILE
);
225 AddFormat( SOT_FORMAT_BITMAP
);
228 case SC_SELTRANS_DRAW_BOOKMARK
:
229 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
230 AddFormat( SOT_FORMATSTR_ID_SOLK
);
231 AddFormat( SOT_FORMAT_STRING
);
232 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR
);
233 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
);
234 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
237 case SC_SELTRANS_DRAW_OLE
:
238 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
239 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
240 AddFormat( SOT_FORMAT_GDIMETAFILE
);
243 case SC_SELTRANS_DRAW_OTHER
:
244 // other drawing objects
245 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
246 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
247 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
248 AddFormat( SOT_FORMAT_BITMAP
);
249 AddFormat( SOT_FORMAT_GDIMETAFILE
);
254 // added to avoid warnings
259 void ScSelectionTransferObj::CreateCellData()
261 OSL_ENSURE( !pCellData
, "CreateCellData twice" );
264 ScViewData
* pViewData
= pView
->GetViewData();
265 ScMarkData
aNewMark( pViewData
->GetMarkData() ); // use local copy for MarkToSimple
266 aNewMark
.MarkToSimple();
268 // similar to ScViewFunctionSet::BeginDrag
269 if ( aNewMark
.IsMarked() && !aNewMark
.IsMultiMarked() )
271 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
274 aNewMark
.GetMarkArea( aSelRange
);
275 ScDocShellRef aDragShellRef
;
276 if ( pDocSh
->GetDocument()->HasOLEObjectsInArea( aSelRange
, &aNewMark
) )
278 aDragShellRef
= new ScDocShell
; // DocShell needs a Ref immediately
279 aDragShellRef
->DoInitNew(NULL
);
281 ScDrawLayer::SetGlobalDrawPersist(aDragShellRef
);
283 ScDocument
* pClipDoc
= new ScDocument( SCDOCMODE_CLIP
);
284 // bApi = sal_True -> no error messages
285 // #i18364# bStopEdit = sal_False -> don't end edit mode
286 // (this may be called from pasting into the edit line)
287 sal_Bool bCopied
= pViewData
->GetView()->CopyToClip( pClipDoc
, false, sal_True
, sal_True
, false );
289 ScDrawLayer::SetGlobalDrawPersist(NULL
);
293 TransferableObjectDescriptor aObjDesc
;
294 pDocSh
->FillTransferableObjectDescriptor( aObjDesc
);
295 aObjDesc
.maDisplayName
= pDocSh
->GetMedium()->GetURLObject().GetURLNoPass();
296 // maSize is set in ScTransferObj ctor
298 ScTransferObj
* pTransferObj
= new ScTransferObj( pClipDoc
, aObjDesc
);
299 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
301 // SetDragHandlePos is not used - there is no mouse position
302 //? pTransferObj->SetVisibleTab( nTab );
304 SfxObjectShellRef
aPersistRef( aDragShellRef
);
305 pTransferObj
->SetDrawPersist( aPersistRef
); // keep persist for ole objects alive
307 pTransferObj
->SetDragSource( pDocSh
, aNewMark
);
309 pCellData
= pTransferObj
;
310 pCellData
->acquire(); // keep ref count up - released in ForgetView
316 OSL_ENSURE( pCellData
, "can't create CellData" );
319 void ScSelectionTransferObj::CreateDrawData()
321 OSL_ENSURE( !pDrawData
, "CreateDrawData twice" );
324 // similar to ScDrawView::BeginDrag
326 ScDrawView
* pDrawView
= pView
->GetScDrawView();
329 sal_Bool bAnyOle
, bOneOle
;
330 const SdrMarkList
& rMarkList
= pDrawView
->GetMarkedObjectList();
331 ScDrawView::CheckOle( rMarkList
, bAnyOle
, bOneOle
);
333 //---------------------------------------------------------
334 ScDocShellRef aDragShellRef
;
337 aDragShellRef
= new ScDocShell
; // ohne Ref lebt die DocShell nicht !!!
338 aDragShellRef
->DoInitNew(NULL
);
340 //---------------------------------------------------------
342 ScDrawLayer::SetGlobalDrawPersist(aDragShellRef
);
343 SdrModel
* pModel
= pDrawView
->GetMarkedObjModel();
344 ScDrawLayer::SetGlobalDrawPersist(NULL
);
346 ScViewData
* pViewData
= pView
->GetViewData();
347 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
349 TransferableObjectDescriptor aObjDesc
;
350 pDocSh
->FillTransferableObjectDescriptor( aObjDesc
);
351 aObjDesc
.maDisplayName
= pDocSh
->GetMedium()->GetURLObject().GetURLNoPass();
352 // maSize is set in ScDrawTransferObj ctor
354 ScDrawTransferObj
* pTransferObj
= new ScDrawTransferObj( pModel
, pDocSh
, aObjDesc
);
355 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
357 SfxObjectShellRef
aPersistRef( aDragShellRef
);
358 pTransferObj
->SetDrawPersist( aPersistRef
); // keep persist for ole objects alive
359 pTransferObj
->SetDragSource( pDrawView
); // copies selection
361 pDrawData
= pTransferObj
;
362 pDrawData
->acquire(); // keep ref count up - released in ForgetView
365 OSL_ENSURE( pDrawData
, "can't create DrawData" );
368 ScTransferObj
* ScSelectionTransferObj::GetCellData()
370 if ( !pCellData
&& ( eMode
== SC_SELTRANS_CELL
|| eMode
== SC_SELTRANS_CELLS
) )
375 ScDrawTransferObj
* ScSelectionTransferObj::GetDrawData()
377 if ( !pDrawData
&& ( eMode
== SC_SELTRANS_DRAW_BITMAP
|| eMode
== SC_SELTRANS_DRAW_GRAPHIC
||
378 eMode
== SC_SELTRANS_DRAW_BOOKMARK
|| eMode
== SC_SELTRANS_DRAW_OLE
||
379 eMode
== SC_SELTRANS_DRAW_OTHER
) )
384 sal_Bool
ScSelectionTransferObj::GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
)
386 sal_Bool bOK
= false;
388 uno::Reference
<datatransfer::XTransferable
> xSource
;
391 case SC_SELTRANS_CELL
:
392 case SC_SELTRANS_CELLS
:
393 xSource
= GetCellData();
395 case SC_SELTRANS_DRAW_BITMAP
:
396 case SC_SELTRANS_DRAW_GRAPHIC
:
397 case SC_SELTRANS_DRAW_BOOKMARK
:
398 case SC_SELTRANS_DRAW_OLE
:
399 case SC_SELTRANS_DRAW_OTHER
:
400 xSource
= GetDrawData();
404 // added to avoid warnings
410 TransferableDataHelper
aHelper( xSource
);
411 uno::Any aAny
= aHelper
.GetAny( rFlavor
);
412 bOK
= SetAny( aAny
, rFlavor
);
418 void ScSelectionTransferObj::ObjectReleased()
420 // called when another selection is set from outside
424 ScModule
* pScMod
= SC_MOD();
425 if ( pScMod
->GetSelectionTransfer() == this )
426 pScMod
->SetSelectionTransfer( NULL
);
428 TransferableHelper::ObjectReleased();
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */