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