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/embed/NoVisualAreaSizeException.hpp>
30 : :
31 : : #include <svx/svditer.hxx>
32 : : #include <svx/svdograf.hxx>
33 : : #include <svx/svdoole2.hxx>
34 : : #include <svx/svdouno.hxx>
35 : : #include <svx/svdpage.hxx>
36 : : #include <svx/svdpagv.hxx>
37 : : #include <svx/svdundo.hxx>
38 : : #include <svx/xbitmap.hxx>
39 : : #include <svx/xbtmpit.hxx>
40 : : #include <svx/xoutbmp.hxx>
41 : : #include <sfx2/objsh.hxx>
42 : : #include <sfx2/viewfrm.hxx>
43 : : #include <toolkit/helper/vclunohelper.hxx>
44 : : #include <com/sun/star/embed/Aspects.hpp>
45 : :
46 : : #include "document.hxx" // fuer MapMode Initialisierung in PasteDraw
47 : : #include "viewfunc.hxx"
48 : : #include "tabvwsh.hxx"
49 : : #include "drawview.hxx"
50 : : #include "scmod.hxx"
51 : : #include "drwlayer.hxx"
52 : : #include "drwtrans.hxx"
53 : : #include "globstr.hrc"
54 : : #include "chartlis.hxx"
55 : : #include "docuno.hxx"
56 : : #include "docsh.hxx"
57 : : #include "convuno.hxx"
58 : : #include "dragdata.hxx"
59 : :
60 : : extern Point aDragStartDiff;
61 : :
62 : : // STATIC DATA -----------------------------------------------------------
63 : :
64 : : sal_Bool bPasteIsMove = false;
65 : :
66 : : using namespace com::sun::star;
67 : :
68 : : //==================================================================
69 : :
70 : 0 : void lcl_AdjustInsertPos( ScViewData* pData, Point& rPos, Size& rSize )
71 : : {
72 [ # # ][ # # ]: 0 : SdrPage* pPage = pData->GetScDrawView()->GetModel()->GetPage( static_cast<sal_uInt16>(pData->GetTabNo()) );
73 : : OSL_ENSURE(pPage,"pPage ???");
74 [ # # ]: 0 : Size aPgSize( pPage->GetSize() );
75 [ # # ]: 0 : if (aPgSize.Width() < 0)
76 : 0 : aPgSize.Width() = -aPgSize.Width();
77 : 0 : long x = aPgSize.Width() - rPos.X() - rSize.Width();
78 : 0 : long y = aPgSize.Height() - rPos.Y() - rSize.Height();
79 : : // ggf. Ajustments (80/200) fuer Pixel-Rundungsfehler
80 [ # # ]: 0 : if( x < 0 )
81 : 0 : rPos.X() += x + 80;
82 [ # # ]: 0 : if( y < 0 )
83 : 0 : rPos.Y() += y + 200;
84 : 0 : rPos.X() += rSize.Width() / 2; // Position bei Paste gibt Mittelpunkt an
85 : 0 : rPos.Y() += rSize.Height() / 2;
86 : 0 : }
87 : :
88 : 0 : void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel,
89 : : sal_Bool bGroup, sal_Bool bSameDocClipboard )
90 : : {
91 [ # # ]: 0 : MakeDrawLayer();
92 : 0 : Point aPos( rLogicPos );
93 : :
94 : : // MapMode am Outliner-RefDevice muss stimmen (wie in FuText::MakeOutliner)
95 : : //! mit FuText::MakeOutliner zusammenfassen?
96 [ # # ]: 0 : MapMode aOldMapMode;
97 [ # # ][ # # ]: 0 : OutputDevice* pRef = GetViewData()->GetDocument()->GetDrawLayer()->GetRefDevice();
98 [ # # ]: 0 : if (pRef)
99 : : {
100 [ # # ]: 0 : aOldMapMode = pRef->GetMapMode();
101 [ # # ][ # # ]: 0 : pRef->SetMapMode( MapMode(MAP_100TH_MM) );
[ # # ]
102 : : }
103 : :
104 [ # # ][ # # ]: 0 : sal_Bool bNegativePage = GetViewData()->GetDocument()->IsNegativePage( GetViewData()->GetTabNo() );
105 : :
106 : 0 : SdrView* pDragEditView = NULL;
107 [ # # ]: 0 : ScModule* pScMod = SC_MOD();
108 [ # # ]: 0 : const ScDragData& rData = pScMod->GetDragData();
109 : 0 : ScDrawTransferObj* pDrawTrans = rData.pDrawTransfer;
110 [ # # ]: 0 : if (pDrawTrans)
111 : : {
112 : 0 : pDragEditView = pDrawTrans->GetDragSourceView();
113 : :
114 : 0 : aPos -= aDragStartDiff;
115 [ # # ]: 0 : if ( bNegativePage )
116 : : {
117 [ # # ]: 0 : if (aPos.X() > 0) aPos.X() = 0;
118 : : }
119 : : else
120 : : {
121 [ # # ]: 0 : if (aPos.X() < 0) aPos.X() = 0;
122 : : }
123 [ # # ]: 0 : if (aPos.Y() < 0) aPos.Y() = 0;
124 : : }
125 : :
126 : 0 : ScDrawView* pScDrawView = GetScDrawView();
127 [ # # ]: 0 : if (bGroup)
128 [ # # ][ # # ]: 0 : pScDrawView->BegUndo( ScGlobal::GetRscString( STR_UNDO_PASTE ) );
129 : :
130 [ # # ][ # # ]: 0 : sal_Bool bSameDoc = ( pDragEditView && pDragEditView->GetModel() == pScDrawView->GetModel() );
131 [ # # ]: 0 : if (bSameDoc)
132 : : {
133 : : // lokal kopieren - incl. Charts
134 : :
135 [ # # ]: 0 : Point aSourceStart = pDragEditView->GetAllMarkedRect().TopLeft();
136 : 0 : long nDiffX = aPos.X() - aSourceStart.X();
137 : 0 : long nDiffY = aPos.Y() - aSourceStart.Y();
138 : :
139 : : // innerhalb einer Page verschieben?
140 : :
141 [ # # ]: 0 : if ( bPasteIsMove &&
[ # # # # ]
142 : 0 : pScDrawView->GetSdrPageView()->GetPage() ==
143 : 0 : pDragEditView->GetSdrPageView()->GetPage() )
144 : : {
145 [ # # ][ # # ]: 0 : if ( nDiffX != 0 || nDiffY != 0 )
146 [ # # ]: 0 : pDragEditView->MoveAllMarked(Size(nDiffX,nDiffY), false);
147 : : }
148 : : else
149 : : {
150 : 0 : SdrModel* pDrawModel = pDragEditView->GetModel();
151 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
152 [ # # ]: 0 : SdrPage* pDestPage = pDrawModel->GetPage( static_cast< sal_uInt16 >( nTab ) );
153 : : OSL_ENSURE(pDestPage,"nanu, Page?");
154 : :
155 [ # # ]: 0 : ::std::vector< ::rtl::OUString > aExcludedChartNames;
156 [ # # ]: 0 : if ( pDestPage )
157 : : {
158 [ # # ]: 0 : ScChartHelper::GetChartNames( aExcludedChartNames, pDestPage );
159 : : }
160 : :
161 [ # # ]: 0 : SdrMarkList aMark = pDragEditView->GetMarkedObjectList();
162 [ # # ]: 0 : aMark.ForceSort();
163 : 0 : sal_uLong nMarkAnz=aMark.GetMarkCount();
164 [ # # ]: 0 : for (sal_uLong nm=0; nm<nMarkAnz; nm++) {
165 [ # # ]: 0 : const SdrMark* pM=aMark.GetMark(nm);
166 [ # # ]: 0 : const SdrObject* pObj=pM->GetMarkedSdrObj();
167 : :
168 [ # # ]: 0 : SdrObject* pNeuObj=pObj->Clone();
169 : :
170 [ # # ]: 0 : if (pNeuObj!=NULL)
171 : : {
172 [ # # ]: 0 : pNeuObj->SetModel(pDrawModel);
173 [ # # ]: 0 : pNeuObj->SetPage(pDestPage);
174 : :
175 : : // copy graphics within the same model - always needs new name
176 [ # # ][ # # ]: 0 : if ( pNeuObj->ISA(SdrGrafObj) && !bPasteIsMove )
[ # # ][ # # ]
[ # # ]
177 [ # # ][ # # ]: 0 : pNeuObj->SetName(((ScDrawLayer*)pDrawModel)->GetNewGraphicName());
[ # # ][ # # ]
178 : :
179 [ # # ][ # # ]: 0 : if (nDiffX!=0 || nDiffY!=0)
180 [ # # ]: 0 : pNeuObj->NbcMove(Size(nDiffX,nDiffY));
181 [ # # ]: 0 : pDestPage->InsertObject( pNeuObj );
182 [ # # ][ # # ]: 0 : pScDrawView->AddUndo(new SdrUndoInsertObj( *pNeuObj ));
[ # # ]
183 : :
184 : : // Chart braucht nicht mehr getrennt behandelt zu werden,
185 : : // weil es seine Daten jetzt selber hat
186 : : }
187 : : }
188 : :
189 [ # # ]: 0 : if (bPasteIsMove)
190 [ # # ]: 0 : pDragEditView->DeleteMarked();
191 : :
192 [ # # ]: 0 : ScDocument* pDocument = GetViewData()->GetDocument();
193 : 0 : ScDocShell* pDocShell = GetViewData()->GetDocShell();
194 [ # # ][ # # ]: 0 : ScModelObj* pModelObj = ( pDocShell ? ScModelObj::getImplementation( pDocShell->GetModel() ) : NULL );
[ # # ][ # # ]
[ # # # # ]
[ # # ]
195 [ # # ][ # # ]: 0 : if ( pDocument && pDestPage && pModelObj && pDrawTrans )
[ # # ][ # # ]
196 : : {
197 : 0 : const ScRangeListVector& rProtectedChartRangesVector( pDrawTrans->GetProtectedChartRangesVector() );
198 : : ScChartHelper::CreateProtectedChartListenersAndNotify( pDocument, pDestPage, pModelObj, nTab,
199 [ # # ]: 0 : rProtectedChartRangesVector, aExcludedChartNames, bSameDoc );
200 [ # # ]: 0 : }
201 : : }
202 : : }
203 : : else
204 : : {
205 : 0 : bPasteIsMove = false; // kein internes Verschieben passiert
206 : :
207 [ # # ]: 0 : SdrView aView(pModel); // #i71529# never create a base class of SdrView directly!
208 [ # # ][ # # ]: 0 : SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
209 [ # # ]: 0 : aView.MarkAllObj(pPv);
210 [ # # ][ # # ]: 0 : Size aSize = aView.GetAllMarkedRect().GetSize();
211 [ # # ]: 0 : lcl_AdjustInsertPos( GetViewData(), aPos, aSize );
212 : :
213 : : // Markierung nicht aendern, wenn Ole-Objekt aktiv
214 : : // (bei Drop aus Ole-Objekt wuerde sonst mitten im ExecuteDrag deaktiviert!)
215 : :
216 : 0 : sal_uLong nOptions = 0;
217 [ # # ]: 0 : SfxInPlaceClient* pClient = GetViewData()->GetViewShell()->GetIPClient();
218 [ # # ][ # # ]: 0 : if ( pClient && pClient->IsObjectInPlaceActive() )
[ # # ][ # # ]
219 : 0 : nOptions |= SDRINSERT_DONTMARK;
220 : :
221 [ # # ]: 0 : ::std::vector< ::rtl::OUString > aExcludedChartNames;
222 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
223 [ # # ]: 0 : SdrPage* pPage = pScDrawView->GetModel()->GetPage( static_cast< sal_uInt16 >( nTab ) );
224 : : OSL_ENSURE( pPage, "Page?" );
225 [ # # ]: 0 : if ( pPage )
226 : : {
227 [ # # ]: 0 : ScChartHelper::GetChartNames( aExcludedChartNames, pPage );
228 : : }
229 : :
230 : : // #89247# Set flag for ScDocument::UpdateChartListeners() which is
231 : : // called during paste.
232 [ # # ]: 0 : if ( !bSameDocClipboard )
233 [ # # ]: 0 : GetViewData()->GetDocument()->SetPastingDrawFromOtherDoc( sal_True );
234 : :
235 [ # # ]: 0 : pScDrawView->Paste( *pModel, aPos, NULL, nOptions );
236 : :
237 [ # # ]: 0 : if ( !bSameDocClipboard )
238 [ # # ]: 0 : GetViewData()->GetDocument()->SetPastingDrawFromOtherDoc( false );
239 : :
240 : : // Paste puts all objects on the active (front) layer
241 : : // controls must be on SC_LAYER_CONTROLS
242 [ # # ]: 0 : if (pPage)
243 : : {
244 [ # # ]: 0 : SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
245 [ # # ]: 0 : SdrObject* pObject = aIter.Next();
246 [ # # ]: 0 : while (pObject)
247 : : {
248 [ # # ][ # # ]: 0 : if ( pObject->ISA(SdrUnoObj) && pObject->GetLayer() != SC_LAYER_CONTROLS )
[ # # ][ # # ]
[ # # ][ # # ]
249 [ # # ]: 0 : pObject->NbcSetLayer(SC_LAYER_CONTROLS);
250 [ # # ]: 0 : pObject = aIter.Next();
251 : 0 : }
252 : : }
253 : :
254 : : // all graphics objects must have names
255 [ # # ][ # # ]: 0 : GetViewData()->GetDocument()->EnsureGraphicNames();
256 : :
257 [ # # ]: 0 : ScDocument* pDocument = GetViewData()->GetDocument();
258 : 0 : ScDocShell* pDocShell = GetViewData()->GetDocShell();
259 [ # # ][ # # ]: 0 : ScModelObj* pModelObj = ( pDocShell ? ScModelObj::getImplementation( pDocShell->GetModel() ) : NULL );
[ # # ][ # # ]
[ # # # # ]
[ # # ]
260 [ # # ]: 0 : ScDrawTransferObj* pTransferObj = ScDrawTransferObj::GetOwnClipboard( NULL );
261 [ # # ][ # # ]: 0 : if ( pDocument && pPage && pModelObj && ( pTransferObj || pDrawTrans ) )
[ # # ][ # # ]
[ # # ]
262 : : {
263 : : const ScRangeListVector& rProtectedChartRangesVector(
264 [ # # ]: 0 : pTransferObj ? pTransferObj->GetProtectedChartRangesVector() : pDrawTrans->GetProtectedChartRangesVector() );
265 : : ScChartHelper::CreateProtectedChartListenersAndNotify( pDocument, pPage, pModelObj, nTab,
266 [ # # ]: 0 : rProtectedChartRangesVector, aExcludedChartNames, bSameDocClipboard );
267 [ # # ]: 0 : }
268 : : }
269 : :
270 [ # # ]: 0 : if (bGroup)
271 : : {
272 [ # # ]: 0 : pScDrawView->GroupMarked();
273 [ # # ]: 0 : pScDrawView->EndUndo();
274 : : }
275 : :
276 [ # # ]: 0 : if (pRef)
277 [ # # ]: 0 : pRef->SetMapMode( aOldMapMode );
278 : :
279 : : // GetViewData()->GetViewShell()->SetDrawShell( TRUE );
280 : : // It is not sufficient to just set the DrawShell if we pasted, for
281 : : // example, a chart. SetDrawShellOrSub() would only work for D&D in the
282 : : // same document but not if inserting from the clipboard, therefore
283 : : // MarkListHasChanged() is what we need.
284 [ # # ][ # # ]: 0 : pScDrawView->MarkListHasChanged();
285 : :
286 : 0 : }
287 : :
288 : 0 : sal_Bool ScViewFunc::PasteObject( const Point& rPos, const uno::Reference < embed::XEmbeddedObject >& xObj,
289 : : const Size* pDescSize, const Graphic* pReplGraph, const ::rtl::OUString& aMediaType, sal_Int64 nAspect )
290 : : {
291 : 0 : MakeDrawLayer();
292 [ # # ]: 0 : if ( xObj.is() )
293 : : {
294 : 0 : ::rtl::OUString aName;
295 : : //TODO/MBA: is that OK?
296 [ # # ][ # # ]: 0 : comphelper::EmbeddedObjectContainer& aCnt = GetViewData()->GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer();
297 [ # # ][ # # ]: 0 : if ( !aCnt.HasEmbeddedObject( xObj ) )
298 [ # # ]: 0 : aCnt.InsertEmbeddedObject( xObj, aName );
299 : : else
300 [ # # ]: 0 : aName = aCnt.GetEmbeddedObjectName( xObj );
301 : :
302 [ # # ]: 0 : svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
303 [ # # ]: 0 : if ( pReplGraph )
304 [ # # ]: 0 : aObjRef.SetGraphic( *pReplGraph, aMediaType );
305 : :
306 : 0 : Size aSize;
307 [ # # ]: 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
308 : : {
309 [ # # ]: 0 : MapMode aMapMode( MAP_100TH_MM );
310 [ # # ][ # # ]: 0 : aSize = aObjRef.GetSize( &aMapMode );
311 : : }
312 : : else
313 : : {
314 : : // working with visual area can switch object to running state
315 [ # # ][ # # ]: 0 : MapUnit aMapObj = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
[ # # ]
316 : 0 : MapUnit aMap100 = MAP_100TH_MM;
317 : :
318 [ # # ][ # # ]: 0 : if ( pDescSize && pDescSize->Width() && pDescSize->Height() )
[ # # ][ # # ]
319 : : {
320 : : // use size from object descriptor if given
321 [ # # ][ # # ]: 0 : aSize = OutputDevice::LogicToLogic( *pDescSize, aMap100, aMapObj );
[ # # ][ # # ]
[ # # # # ]
322 : 0 : awt::Size aSz;
323 : 0 : aSz.Width = aSize.Width();
324 : 0 : aSz.Height = aSize.Height();
325 [ # # ][ # # ]: 0 : xObj->setVisualAreaSize( nAspect, aSz );
326 : : }
327 : :
328 : 0 : awt::Size aSz;
329 : : try
330 : : {
331 [ # # ][ # # ]: 0 : aSz = xObj->getVisualAreaSize( nAspect );
332 : : }
333 [ # # ]: 0 : catch ( embed::NoVisualAreaSizeException& )
334 : : {
335 : : // the default size will be set later
336 : : }
337 : :
338 : 0 : aSize = Size( aSz.Width, aSz.Height );
339 [ # # ][ # # ]: 0 : aSize = OutputDevice::LogicToLogic( aSize, aMapObj, aMap100 ); // fuer SdrOle2Obj
[ # # ][ # # ]
[ # # ]
340 : :
341 [ # # ][ # # ]: 0 : if( aSize.Height() == 0 || aSize.Width() == 0 )
[ # # ]
342 : : {
343 : : OSL_FAIL("SvObjectDescriptor::GetSize == 0");
344 : 0 : aSize.Width() = 5000;
345 : 0 : aSize.Height() = 5000;
346 [ # # ][ # # ]: 0 : aSize = OutputDevice::LogicToLogic( aSize, aMap100, aMapObj );
[ # # ][ # # ]
[ # # ]
347 : 0 : aSz.Width = aSize.Width();
348 : 0 : aSz.Height = aSize.Height();
349 [ # # ][ # # ]: 0 : xObj->setVisualAreaSize( nAspect, aSz );
350 : : }
351 : : }
352 : :
353 : : // don't call AdjustInsertPos
354 : 0 : Point aInsPos = rPos;
355 [ # # ][ # # ]: 0 : if ( GetViewData()->GetDocument()->IsNegativePage( GetViewData()->GetTabNo() ) )
[ # # ]
356 : 0 : aInsPos.X() -= aSize.Width();
357 [ # # ]: 0 : Rectangle aRect( aInsPos, aSize );
358 : :
359 : 0 : ScDrawView* pDrView = GetScDrawView();
360 [ # # ][ # # ]: 0 : SdrOle2Obj* pSdrObj = new SdrOle2Obj( aObjRef, aName, aRect );
[ # # ][ # # ]
361 : :
362 : 0 : SdrPageView* pPV = pDrView->GetSdrPageView();
363 [ # # ]: 0 : pDrView->InsertObjectSafe( pSdrObj, *pPV ); // nicht markieren wenn Ole
364 [ # # ]: 0 : GetViewData()->GetViewShell()->SetDrawShell( sal_True );
365 [ # # ]: 0 : return sal_True;
366 : : }
367 : : else
368 : 0 : return false;
369 : : }
370 : :
371 : 0 : sal_Bool ScViewFunc::PasteBitmap( const Point& rPos, const Bitmap& rBmp )
372 : : {
373 [ # # ]: 0 : String aEmpty;
374 [ # # ]: 0 : Graphic aGraphic(rBmp);
375 [ # # ][ # # ]: 0 : return PasteGraphic( rPos, aGraphic, aEmpty, aEmpty );
[ # # ]
376 : : }
377 : :
378 : 0 : sal_Bool ScViewFunc::PasteMetaFile( const Point& rPos, const GDIMetaFile& rMtf )
379 : : {
380 [ # # ]: 0 : String aEmpty;
381 [ # # ]: 0 : Graphic aGraphic(rMtf);
382 [ # # ][ # # ]: 0 : return PasteGraphic( rPos, aGraphic, aEmpty, aEmpty );
[ # # ]
383 : : }
384 : :
385 : 0 : sal_Bool ScViewFunc::PasteGraphic( const Point& rPos, const Graphic& rGraphic,
386 : : const String& rFile, const String& rFilter )
387 : : {
388 [ # # ]: 0 : MakeDrawLayer();
389 : 0 : ScDrawView* pScDrawView = GetScDrawView();
390 : :
391 : 0 : Point aPos( rPos );
392 [ # # ]: 0 : Window* pWin = GetActiveWin();
393 [ # # ]: 0 : MapMode aSourceMap = rGraphic.GetPrefMapMode();
394 [ # # ]: 0 : MapMode aDestMap( MAP_100TH_MM );
395 : :
396 [ # # ]: 0 : if (aSourceMap.GetMapUnit() == MAP_PIXEL)
397 : : {
398 : : // Pixel-Korrektur beruecksichtigen, damit Bitmap auf dem Bildschirm stimmt
399 : :
400 : 0 : Fraction aScaleX, aScaleY;
401 [ # # ]: 0 : pScDrawView->CalcNormScale( aScaleX, aScaleY );
402 [ # # ]: 0 : aDestMap.SetScaleX(aScaleX);
403 [ # # ]: 0 : aDestMap.SetScaleY(aScaleY);
404 : : }
405 : :
406 [ # # ][ # # ]: 0 : Size aSize = pWin->LogicToLogic( rGraphic.GetPrefSize(), &aSourceMap, &aDestMap );
407 : :
408 [ # # ][ # # ]: 0 : if ( GetViewData()->GetDocument()->IsNegativePage( GetViewData()->GetTabNo() ) )
[ # # ]
409 : 0 : aPos.X() -= aSize.Width();
410 : :
411 [ # # ]: 0 : GetViewData()->GetViewShell()->SetDrawShell( sal_True );
412 : :
413 [ # # ]: 0 : Rectangle aRect(aPos, aSize);
414 [ # # ][ # # ]: 0 : SdrGrafObj* pGrafObj = new SdrGrafObj(rGraphic, aRect);
415 : :
416 : : // calling SetGraphicLink here doesn't work
417 : :
418 : : // Pfad wird nicht mehr als Name der Grafik gesetzt
419 : :
420 : 0 : ScDrawLayer* pLayer = (ScDrawLayer*) pScDrawView->GetModel();
421 [ # # ]: 0 : String aName = pLayer->GetNewGraphicName(); // "Grafik x"
422 [ # # ][ # # ]: 0 : pGrafObj->SetName(aName);
423 : :
424 : : // nicht markieren wenn Ole
425 [ # # ]: 0 : pScDrawView->InsertObjectSafe(pGrafObj, *pScDrawView->GetSdrPageView());
426 : :
427 : : // SetGraphicLink has to be used after inserting the object,
428 : : // otherwise an empty graphic is swapped in and the contact stuff crashes.
429 : : // See #i37444#.
430 [ # # ]: 0 : if (rFile.Len())
431 [ # # ][ # # ]: 0 : pGrafObj->SetGraphicLink( rFile, rFilter );
432 : :
433 [ # # ][ # # ]: 0 : return sal_True;
[ # # ]
434 : : }
435 : :
436 : 0 : sal_Bool ScViewFunc::ApplyGraphicToObject( SdrObject* pPickObj, const Graphic& rGraphic )
437 : : {
438 : 0 : sal_Bool bRet = false;
439 : 0 : SdrGrafObj* pNewGrafObj = NULL;
440 : :
441 : 0 : ScDrawView* pScDrawView = GetScDrawView();
442 [ # # ][ # # ]: 0 : if ( pScDrawView && pPickObj )
443 : : {
444 : : /**********************************************************************
445 : : * Objekt neu attributieren
446 : : **********************************************************************/
447 : 0 : SdrPageView* pPV = pScDrawView->GetSdrPageView();
448 [ # # ]: 0 : if (pPickObj->ISA(SdrGrafObj))
449 : : {
450 : : /******************************************************************
451 : : * Das Graphik-Objekt bekommt eine neue Graphik
452 : : ******************************************************************/
453 : 0 : pNewGrafObj = (SdrGrafObj*) pPickObj->Clone();
454 : 0 : pNewGrafObj->SetGraphic(rGraphic);
455 : :
456 : 0 : pScDrawView->BegUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
457 : 0 : pScDrawView->ReplaceObjectAtView(pPickObj, *pPV, pNewGrafObj);
458 : 0 : pScDrawView->EndUndo();
459 : :
460 : 0 : bRet = sal_True;
461 : : }
462 [ # # ][ # # ]: 0 : else if (pPickObj->IsClosedObj() && !pPickObj->ISA(SdrOle2Obj))
[ # # ]
463 : : {
464 : : /******************************************************************
465 : : * Das Objekt wird mit der Graphik gefuellt
466 : : ******************************************************************/
467 : : //pScDrawView->BegUndo(ScGlobal::GetRscString(STR_UNDO_DRAGDROP));
468 [ # # ][ # # ]: 0 : pScDrawView->AddUndo(new SdrUndoAttrObj(*pPickObj));
[ # # ]
469 : : //pScDrawView->EndUndo();
470 : :
471 [ # # ][ # # ]: 0 : XOBitmap aXOBitmap( rGraphic.GetBitmap() );
[ # # ]
472 : 0 : SfxItemSet aSet( pScDrawView->GetModel()->GetItemPool(),
473 [ # # ]: 0 : XATTR_FILLSTYLE, XATTR_FILLBITMAP );
474 [ # # ][ # # ]: 0 : aSet.Put(XFillStyleItem(XFILL_BITMAP));
[ # # ]
475 [ # # ][ # # ]: 0 : aSet.Put(XFillBitmapItem(String(), aXOBitmap));
[ # # ][ # # ]
[ # # ]
476 : :
477 [ # # ]: 0 : pPickObj->SetMergedItemSetAndBroadcast(aSet);
478 : :
479 [ # # ][ # # ]: 0 : bRet = sal_True;
480 : : }
481 : : }
482 : 0 : return bRet;
483 : : }
484 : :
485 : :
486 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|