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 : :
30 : : #include <vector>
31 : : #include <editeng/editeng.hxx>
32 : : #include "svx/xexch.hxx"
33 : : #include <svx/xflclit.hxx>
34 : : #include <svx/svdxcgv.hxx>
35 : : #include <svx/svdoutl.hxx>
36 : : #include "svx/svditext.hxx"
37 : : #include <svx/svdetc.hxx>
38 : : #include <svx/svdundo.hxx>
39 : : #include <svx/svdograf.hxx>
40 : : #include <svx/svdoole2.hxx> // to not have OLE in SdrClipboardFormat
41 : : #include <svx/svdorect.hxx>
42 : : #include <svx/svdoedge.hxx> // for connectors via the clipboard
43 : : #include <svx/svdopage.hxx> // for connectors via the clipboard
44 : : #include <svx/svdpage.hxx>
45 : : #include <svx/svdpagv.hxx>
46 : : #include <svx/svdtrans.hxx> // for GetMapFactor, to rescale at PasteModel
47 : : #include "svx/svdstr.hrc" // names taken from the resource
48 : : #include "svx/svdglob.hxx" // StringCache
49 : : #include "svx/xoutbmp.hxx"
50 : : #include <vcl/metaact.hxx>
51 : : #include <svl/poolitem.hxx>
52 : : #include <svl/itempool.hxx>
53 : : #include <tools/bigint.hxx>
54 : : #include <sot/formats.hxx>
55 : :
56 : : // #i13033#
57 : : #include <clonelist.hxx>
58 : : #include <vcl/virdev.hxx>
59 : :
60 : : #include <svl/style.hxx>
61 : :
62 : : // #i72535#
63 : : #include "fmobj.hxx"
64 : : #include <rtl/strbuf.hxx>
65 : :
66 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
67 : :
68 : 4699 : SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut):
69 : 4699 : SdrObjEditView(pModel1,pOut)
70 : : {
71 : 4699 : }
72 : :
73 : 0 : sal_Bool SdrExchangeView::ImpLimitToWorkArea(Point& rPt) const
74 : : {
75 : 0 : sal_Bool bRet(sal_False);
76 : :
77 [ # # ]: 0 : if(!aMaxWorkArea.IsEmpty())
78 : : {
79 [ # # ]: 0 : if(rPt.X()<aMaxWorkArea.Left())
80 : : {
81 : 0 : rPt.X() = aMaxWorkArea.Left();
82 : 0 : bRet = sal_True;
83 : : }
84 : :
85 [ # # ]: 0 : if(rPt.X()>aMaxWorkArea.Right())
86 : : {
87 : 0 : rPt.X() = aMaxWorkArea.Right();
88 : 0 : bRet = sal_True;
89 : : }
90 : :
91 [ # # ]: 0 : if(rPt.Y()<aMaxWorkArea.Top())
92 : : {
93 : 0 : rPt.Y() = aMaxWorkArea.Top();
94 : 0 : bRet = sal_True;
95 : : }
96 : :
97 [ # # ]: 0 : if(rPt.Y()>aMaxWorkArea.Bottom())
98 : : {
99 : 0 : rPt.Y() = aMaxWorkArea.Bottom();
100 : 0 : bRet = sal_True;
101 : : }
102 : : }
103 : 0 : return bRet;
104 : : }
105 : :
106 : 0 : void SdrExchangeView::ImpGetPasteObjList(Point& /*rPos*/, SdrObjList*& rpLst)
107 : : {
108 [ # # ]: 0 : if (rpLst==NULL)
109 : : {
110 : 0 : SdrPageView* pPV = GetSdrPageView();
111 : :
112 [ # # ]: 0 : if (pPV!=NULL) {
113 : 0 : rpLst=pPV->GetObjList();
114 : : }
115 : : }
116 : 0 : }
117 : :
118 : 0 : sal_Bool SdrExchangeView::ImpGetPasteLayer(const SdrObjList* pObjList, SdrLayerID& rLayer) const
119 : : {
120 : 0 : sal_Bool bRet=sal_False;
121 : 0 : rLayer=0;
122 [ # # ]: 0 : if (pObjList!=NULL) {
123 : 0 : const SdrPage* pPg=pObjList->GetPage();
124 [ # # ]: 0 : if (pPg!=NULL) {
125 : 0 : rLayer=pPg->GetLayerAdmin().GetLayerID(aAktLayer,sal_True);
126 [ # # ]: 0 : if (rLayer==SDRLAYER_NOTFOUND) rLayer=0;
127 : 0 : SdrPageView* pPV = GetSdrPageView();
128 [ # # ]: 0 : if (pPV!=NULL) {
129 [ # # ][ # # ]: 0 : bRet=!pPV->GetLockedLayers().IsSet(rLayer) && pPV->GetVisibleLayers().IsSet(rLayer);
130 : : }
131 : : }
132 : : }
133 : 0 : return bRet;
134 : : }
135 : :
136 : 0 : sal_Bool SdrExchangeView::Paste(const XubString& rStr, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
137 : : {
138 [ # # ]: 0 : if(!rStr.Len())
139 : 0 : return sal_False;
140 : :
141 : 0 : Point aPos(rPos);
142 [ # # ]: 0 : ImpGetPasteObjList(aPos,pLst);
143 [ # # ]: 0 : ImpLimitToWorkArea( aPos );
144 [ # # ]: 0 : if (pLst==NULL) return sal_False;
145 : : SdrLayerID nLayer;
146 [ # # ][ # # ]: 0 : if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
147 [ # # ][ # # ]: 0 : sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
[ # # ]
148 [ # # ][ # # ]: 0 : if (bUnmark) UnmarkAllObj();
149 [ # # ]: 0 : Rectangle aTextRect(0,0,500,500);
150 [ # # ]: 0 : SdrPage* pPage=pLst->GetPage();
151 [ # # ]: 0 : if (pPage!=NULL) {
152 [ # # ][ # # ]: 0 : aTextRect.SetSize(pPage->GetSize());
153 : : }
154 [ # # ][ # # ]: 0 : SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
155 [ # # ]: 0 : pObj->SetModel(pMod);
156 [ # # ]: 0 : pObj->SetLayer(nLayer);
157 [ # # ]: 0 : pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't work!
158 [ # # ][ # # ]: 0 : if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
159 : :
160 [ # # ]: 0 : pObj->SetMergedItemSet(aDefaultAttr);
161 : :
162 [ # # ]: 0 : SfxItemSet aTempAttr(pMod->GetItemPool()); // no fill, no line
163 [ # # ][ # # ]: 0 : aTempAttr.Put(XLineStyleItem(XLINE_NONE));
[ # # ]
164 [ # # ][ # # ]: 0 : aTempAttr.Put(XFillStyleItem(XFILL_NONE));
[ # # ]
165 : :
166 [ # # ]: 0 : pObj->SetMergedItemSet(aTempAttr);
167 : :
168 [ # # ]: 0 : pObj->FitFrameToTextSize();
169 [ # # ][ # # ]: 0 : Size aSiz(pObj->GetLogicRect().GetSize());
170 : 0 : MapUnit eMap=pMod->GetScaleUnit();
171 [ # # ]: 0 : Fraction aMap=pMod->GetScaleFraction();
172 [ # # ][ # # ]: 0 : ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
[ # # ]
173 [ # # ]: 0 : return sal_True;
174 : : }
175 : :
176 : 0 : sal_Bool SdrExchangeView::Paste(SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
177 : : {
178 : 0 : Point aPos(rPos);
179 [ # # ]: 0 : ImpGetPasteObjList(aPos,pLst);
180 [ # # ]: 0 : ImpLimitToWorkArea( aPos );
181 [ # # ]: 0 : if (pLst==NULL) return sal_False;
182 : : SdrLayerID nLayer;
183 [ # # ][ # # ]: 0 : if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
184 [ # # ][ # # ]: 0 : sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
[ # # ]
185 [ # # ][ # # ]: 0 : if (bUnmark) UnmarkAllObj();
186 [ # # ]: 0 : Rectangle aTextRect(0,0,500,500);
187 [ # # ]: 0 : SdrPage* pPage=pLst->GetPage();
188 [ # # ]: 0 : if (pPage!=NULL) {
189 [ # # ][ # # ]: 0 : aTextRect.SetSize(pPage->GetSize());
190 : : }
191 [ # # ][ # # ]: 0 : SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
192 [ # # ]: 0 : pObj->SetModel(pMod);
193 [ # # ]: 0 : pObj->SetLayer(nLayer);
194 [ # # ][ # # ]: 0 : if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
195 : :
196 [ # # ]: 0 : pObj->SetMergedItemSet(aDefaultAttr);
197 : :
198 [ # # ]: 0 : SfxItemSet aTempAttr(pMod->GetItemPool()); // no fill, no line
199 [ # # ][ # # ]: 0 : aTempAttr.Put(XLineStyleItem(XLINE_NONE));
[ # # ]
200 [ # # ][ # # ]: 0 : aTempAttr.Put(XFillStyleItem(XFILL_NONE));
[ # # ]
201 : :
202 [ # # ]: 0 : pObj->SetMergedItemSet(aTempAttr);
203 : :
204 [ # # ]: 0 : pObj->NbcSetText(rInput,rBaseURL,eFormat);
205 [ # # ]: 0 : pObj->FitFrameToTextSize();
206 [ # # ][ # # ]: 0 : Size aSiz(pObj->GetLogicRect().GetSize());
207 : 0 : MapUnit eMap=pMod->GetScaleUnit();
208 [ # # ]: 0 : Fraction aMap=pMod->GetScaleFraction();
209 [ # # ][ # # ]: 0 : ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
[ # # ]
210 : :
211 : : // b4967543
212 [ # # ][ # # ]: 0 : if(pObj && pObj->GetModel() && pObj->GetOutlinerParaObject())
[ # # ][ # # ]
[ # # ][ # # ]
213 : : {
214 [ # # ]: 0 : SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner();
215 [ # # ][ # # ]: 0 : rOutliner.SetText(*pObj->GetOutlinerParaObject());
216 : :
217 [ # # ][ # # ]: 0 : if(1L == rOutliner.GetParagraphCount())
218 : : {
219 [ # # ]: 0 : SfxStyleSheet* pCandidate = rOutliner.GetStyleSheet(0L);
220 : :
221 [ # # ]: 0 : if(pCandidate)
222 : : {
223 [ # # ][ # # ]: 0 : if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool())
[ # # ]
224 : : {
225 [ # # ]: 0 : pObj->NbcSetStyleSheet(pCandidate, sal_True);
226 : : }
227 : : }
228 : : }
229 : : }
230 : :
231 [ # # ]: 0 : return sal_True;
232 : : }
233 : :
234 : 0 : sal_Bool SdrExchangeView::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
235 : : {
236 : 0 : const SdrModel* pSrcMod=&rMod;
237 [ # # ]: 0 : if (pSrcMod==pMod)
238 : 0 : return sal_False; // this can't work, right?
239 : :
240 [ # # ]: 0 : const bool bUndo = IsUndoEnabled();
241 : :
242 [ # # ]: 0 : if( bUndo )
243 [ # # ][ # # ]: 0 : BegUndo(ImpGetResStr(STR_ExchangePaste));
[ # # ]
244 : :
245 [ # # ][ # # ]: 0 : if( mxSelectionController.is() && mxSelectionController->PasteObjModel( rMod ) )
[ # # ][ # # ]
246 : : {
247 [ # # ]: 0 : if( bUndo )
248 [ # # ]: 0 : EndUndo();
249 : 0 : return sal_True;
250 : : }
251 : :
252 : 0 : Point aPos(rPos);
253 [ # # ]: 0 : ImpGetPasteObjList(aPos,pLst);
254 : 0 : SdrPageView* pMarkPV=NULL;
255 : 0 : SdrPageView* pPV = GetSdrPageView();
256 : :
257 [ # # ]: 0 : if(pPV)
258 : : {
259 [ # # ]: 0 : if ( pPV->GetObjList() == pLst )
260 : 0 : pMarkPV=pPV;
261 : : }
262 : :
263 [ # # ]: 0 : ImpLimitToWorkArea( aPos );
264 [ # # ]: 0 : if (pLst==NULL)
265 : 0 : return sal_False;
266 : :
267 [ # # ][ # # ]: 0 : sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
[ # # ]
268 [ # # ]: 0 : if (bUnmark)
269 [ # # ]: 0 : UnmarkAllObj();
270 : :
271 : : // Rescale, if the Model uses a different MapUnit.
272 : : // Calculate the necessary factors first.
273 : 0 : MapUnit eSrcUnit=pSrcMod->GetScaleUnit();
274 : 0 : MapUnit eDstUnit=pMod->GetScaleUnit();
275 : 0 : sal_Bool bResize=eSrcUnit!=eDstUnit;
276 : 0 : Fraction xResize,yResize;
277 : 0 : Point aPt0;
278 [ # # ]: 0 : if (bResize)
279 : : {
280 [ # # ]: 0 : FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
281 [ # # ]: 0 : xResize=aResize.X();
282 [ # # ]: 0 : yResize=aResize.Y();
283 : : }
284 : 0 : SdrObjList* pDstLst=pLst;
285 [ # # ]: 0 : sal_uInt16 nPg,nPgAnz=pSrcMod->GetPageCount();
286 [ # # ]: 0 : for (nPg=0; nPg<nPgAnz; nPg++)
287 : : {
288 [ # # ]: 0 : const SdrPage* pSrcPg=pSrcMod->GetPage(nPg);
289 : :
290 : : // Use SnapRect, not BoundRect here
291 [ # # ]: 0 : Rectangle aR=pSrcPg->GetAllObjSnapRect();
292 : :
293 [ # # ]: 0 : if (bResize)
294 [ # # ]: 0 : ResizeRect(aR,aPt0,xResize,yResize);
295 [ # # ]: 0 : Point aDist(aPos-aR.Center());
296 : 0 : Size aSiz(aDist.X(),aDist.Y());
297 : 0 : sal_uIntPtr nCloneErrCnt=0;
298 [ # # ]: 0 : sal_uIntPtr nOb,nObAnz=pSrcPg->GetObjCount();
299 [ # # ][ # # ]: 0 : sal_Bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
[ # # ][ # # ]
300 : :
301 : : // #i13033#
302 : : // New mechanism to re-create the connections of cloned connectors
303 [ # # ]: 0 : CloneList aCloneList;
304 : :
305 [ # # ]: 0 : for (nOb=0; nOb<nObAnz; nOb++)
306 : : {
307 [ # # ]: 0 : const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
308 : :
309 [ # # ]: 0 : SdrObject* pNeuObj = pSrcOb->Clone();
310 : :
311 [ # # ]: 0 : if (pNeuObj!=NULL)
312 : : {
313 [ # # ]: 0 : if(bResize)
314 : : {
315 [ # # ]: 0 : pNeuObj->GetModel()->SetPasteResize(sal_True);
316 [ # # ]: 0 : pNeuObj->NbcResize(aPt0,xResize,yResize);
317 [ # # ]: 0 : pNeuObj->GetModel()->SetPasteResize(sal_False);
318 : : }
319 : :
320 : : // #i39861#
321 [ # # ][ # # ]: 0 : pNeuObj->SetModel(pDstLst->GetModel());
322 [ # # ][ # # ]: 0 : pNeuObj->SetPage(pDstLst->GetPage());
323 : :
324 [ # # ]: 0 : pNeuObj->NbcMove(aSiz);
325 : :
326 [ # # ]: 0 : const SdrPage* pPg = pDstLst->GetPage();
327 : :
328 [ # # ]: 0 : if(pPg)
329 : : {
330 : : // #i72535#
331 : 0 : const SdrLayerAdmin& rAd = pPg->GetLayerAdmin();
332 : 0 : SdrLayerID nLayer(0);
333 : :
334 [ # # ][ # # ]: 0 : if(pNeuObj->ISA(FmFormObj))
[ # # ]
335 : : {
336 : : // for FormControls, force to form layer
337 [ # # ]: 0 : nLayer = rAd.GetLayerID(rAd.GetControlLayerName(), true);
338 : : }
339 : : else
340 : : {
341 [ # # ]: 0 : nLayer = rAd.GetLayerID(aAktLayer, sal_True);
342 : : }
343 : :
344 [ # # ]: 0 : if(SDRLAYER_NOTFOUND == nLayer)
345 : : {
346 : 0 : nLayer = 0;
347 : : }
348 : :
349 [ # # ]: 0 : pNeuObj->SetLayer(nLayer);
350 : : }
351 : :
352 : 0 : SdrInsertReason aReason(SDRREASON_VIEWCALL);
353 [ # # ]: 0 : pDstLst->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
354 : :
355 [ # # ]: 0 : if( bUndo )
356 [ # # ][ # # ]: 0 : AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNeuObj));
[ # # ]
357 : :
358 [ # # ]: 0 : if (bMark) {
359 : : // Don't already set Markhandles!
360 : : // That is instead being done by ModelHasChanged in MarkView.
361 [ # # ]: 0 : MarkObj(pNeuObj,pMarkPV,sal_False,sal_True);
362 : : }
363 : :
364 : : // #i13033#
365 [ # # ]: 0 : aCloneList.AddPair(pSrcOb, pNeuObj);
366 : : }
367 : : else
368 : : {
369 : 0 : nCloneErrCnt++;
370 : : }
371 : : }
372 : :
373 : : // #i13033#
374 : : // New mechanism to re-create the connections of cloned connectors
375 [ # # ]: 0 : aCloneList.CopyConnections();
376 : :
377 : : if(0L != nCloneErrCnt)
378 : : {
379 : : #ifdef DBG_UTIL
380 : : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
381 : : "SdrExchangeView::Paste(): Error when cloning "));
382 : :
383 : : if(nCloneErrCnt == 1)
384 : : {
385 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(
386 : : "a drawing object."));
387 : : }
388 : : else
389 : : {
390 : : aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
391 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
392 : : }
393 : :
394 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(
395 : : " Not copying object connectors."));
396 : :
397 : : OSL_FAIL(aStr.getStr());
398 : : #endif
399 : : }
400 : 0 : }
401 : :
402 [ # # ]: 0 : if( bUndo )
403 [ # # ]: 0 : EndUndo();
404 : :
405 : 0 : return sal_True;
406 : : }
407 : :
408 : 0 : void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Point& rCenter, const Size& rSiz, const MapMode& rMap, sal_uInt32 nOptions)
409 : : {
410 [ # # ]: 0 : BigInt nSizX(rSiz.Width());
411 [ # # ]: 0 : BigInt nSizY(rSiz.Height());
412 : 0 : MapUnit eSrcMU=rMap.GetMapUnit();
413 : 0 : MapUnit eDstMU=pMod->GetScaleUnit();
414 [ # # ]: 0 : FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU));
415 [ # # ]: 0 : Fraction aDstFr(pMod->GetScaleFraction());
416 [ # # ][ # # ]: 0 : nSizX*=aMapFact.X().GetNumerator();
417 [ # # ][ # # ]: 0 : nSizX*=rMap.GetScaleX().GetNumerator();
418 [ # # ][ # # ]: 0 : nSizX*=aDstFr.GetDenominator();
419 [ # # ][ # # ]: 0 : nSizX/=aMapFact.X().GetDenominator();
420 [ # # ][ # # ]: 0 : nSizX/=rMap.GetScaleX().GetDenominator();
421 [ # # ][ # # ]: 0 : nSizX/=aDstFr.GetNumerator();
422 [ # # ][ # # ]: 0 : nSizY*=aMapFact.Y().GetNumerator();
423 [ # # ][ # # ]: 0 : nSizY*=rMap.GetScaleY().GetNumerator();
424 [ # # ][ # # ]: 0 : nSizX*=aDstFr.GetDenominator();
425 [ # # ][ # # ]: 0 : nSizY/=aMapFact.Y().GetDenominator();
426 [ # # ][ # # ]: 0 : nSizY/=rMap.GetScaleY().GetDenominator();
427 [ # # ][ # # ]: 0 : nSizY/=aDstFr.GetNumerator();
428 [ # # ]: 0 : long xs=nSizX;
429 [ # # ]: 0 : long ys=nSizY;
430 : 0 : Point aPos(rCenter.X()-xs/2,rCenter.Y()-ys/2);
431 [ # # ]: 0 : Rectangle aR(aPos.X(),aPos.Y(),aPos.X()+xs,aPos.Y()+ys);
432 [ # # ]: 0 : pObj->SetLogicRect(aR);
433 : 0 : SdrInsertReason aReason(SDRREASON_VIEWCALL);
434 [ # # ]: 0 : rLst.InsertObject(pObj,CONTAINER_APPEND,&aReason);
435 : :
436 [ # # ][ # # ]: 0 : if( IsUndoEnabled() )
437 [ # # ][ # # ]: 0 : AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
[ # # ]
438 : :
439 : 0 : SdrPageView* pMarkPV=NULL;
440 : 0 : SdrPageView* pPV = GetSdrPageView();
441 : :
442 [ # # ]: 0 : if(pPV)
443 : : {
444 [ # # ]: 0 : if (pPV->GetObjList()==&rLst)
445 : 0 : pMarkPV=pPV;
446 : : }
447 : :
448 [ # # ][ # # ]: 0 : sal_Bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
[ # # ][ # # ]
449 [ # # ]: 0 : if (bMark)
450 : : { // select object the first PageView we found
451 [ # # ]: 0 : MarkObj(pObj,pMarkPV);
452 : : }
453 : 0 : }
454 : :
455 : : ////////////////////////////////////////////////////////////////////////////////////////////////////
456 : :
457 : 0 : Bitmap SdrExchangeView::GetMarkedObjBitmap( sal_Bool bNoVDevIfOneBmpMarked ) const
458 : : {
459 : 0 : Bitmap aBmp;
460 : :
461 [ # # ]: 0 : if( AreObjectsMarked() )
462 : : {
463 [ # # ]: 0 : if( bNoVDevIfOneBmpMarked )
464 : : {
465 [ # # ]: 0 : SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
466 [ # # ][ # # ]: 0 : SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() == 1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
[ # # ][ # # ]
[ # # ]
467 : :
468 [ # # ][ # # ]: 0 : if( pGrafObj && ( pGrafObj->GetGraphicType() == GRAPHIC_BITMAP ) )
[ # # ][ # # ]
469 [ # # ][ # # ]: 0 : aBmp = pGrafObj->GetTransformedGraphic().GetBitmap();
[ # # ][ # # ]
[ # # ]
470 : : }
471 : :
472 [ # # ]: 0 : if( !aBmp )
473 : : {
474 [ # # ][ # # ]: 0 : const Graphic aGraphic( GetMarkedObjMetaFile( bNoVDevIfOneBmpMarked ) );
[ # # ]
475 : :
476 : : // #i102089# support user's settings of AA and LineSnap when the MetaFile gets
477 : : // raster-converted to a bitmap
478 [ # # ]: 0 : const SvtOptionsDrawinglayer aDrawinglayerOpt;
479 : : const GraphicConversionParameters aParameters(
480 : : Size(),
481 : : false,
482 [ # # ]: 0 : aDrawinglayerOpt.IsAntiAliasing(),
483 [ # # ]: 0 : aDrawinglayerOpt.IsSnapHorVerLinesToDiscrete());
484 : :
485 [ # # ][ # # ]: 0 : aBmp = aGraphic.GetBitmap(aParameters);
[ # # ][ # # ]
[ # # ]
486 : : }
487 : : }
488 : :
489 : 0 : return aBmp;
490 : : }
491 : :
492 : : // -----------------------------------------------------------------------------
493 : :
494 : 21 : GDIMetaFile SdrExchangeView::GetMarkedObjMetaFile( sal_Bool bNoVDevIfOneMtfMarked ) const
495 : : {
496 : 21 : GDIMetaFile aMtf;
497 : :
498 [ + - ]: 21 : if( AreObjectsMarked() )
499 : : {
500 [ + - ]: 21 : Rectangle aBound( GetMarkedObjBoundRect() );
501 [ + - ][ + - ]: 21 : Size aBoundSize( aBound.GetWidth(), aBound.GetHeight() );
502 [ + - ]: 21 : MapMode aMap( pMod->GetScaleUnit(), Point(), pMod->GetScaleFraction(), pMod->GetScaleFraction() );
503 : :
504 [ - + ]: 21 : if( bNoVDevIfOneMtfMarked )
505 : : {
506 [ # # ]: 0 : SdrObject* pGrafObjTmp = GetMarkedObjectByIndex( 0 );
507 [ # # ][ # # ]: 0 : SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() ==1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
[ # # ][ # # ]
[ # # ]
508 : :
509 [ # # ]: 0 : if( pGrafObj )
510 : : {
511 [ # # ]: 0 : Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
512 : :
513 [ # # ][ # # ]: 0 : if( aGraphic.GetType() == GRAPHIC_BITMAP )
514 : : {
515 : 0 : const Point aPos;
516 : :
517 [ # # ][ # # ]: 0 : aMtf.AddAction( new MetaBmpExScaleAction( aPos, aBoundSize, aGraphic.GetBitmapEx() ) );
[ # # ][ # # ]
[ # # ]
518 [ # # ]: 0 : aMtf.SetPrefMapMode( aMap );
519 : 0 : aMtf.SetPrefSize( aBoundSize );
520 : : }
521 : : else
522 [ # # ][ # # ]: 0 : aMtf = aGraphic.GetGDIMetaFile();
[ # # ]
523 : : }
524 : : }
525 : :
526 [ + - ][ + - ]: 21 : if( !aMtf.GetActionSize() )
527 : : {
528 [ + - ]: 21 : VirtualDevice aOut;
529 : 21 : Size aDummySize( 2, 2 );
530 : :
531 [ + - ]: 21 : aOut.SetOutputSizePixel( aDummySize );
532 [ + - ]: 21 : aOut.EnableOutput( sal_False );
533 [ + - ]: 21 : aOut.SetMapMode( aMap );
534 : :
535 [ + - ]: 21 : aMtf.Clear();
536 [ + - ]: 21 : aMtf.Record( &aOut );
537 : :
538 : : // Replace offset given formally to DrawMarkedObj and used at XOutDev with relative
539 : : // MapMode (which was also used in XOutDev in that case). Goal is to paint the object
540 : : // as if TopLeft point is (0,0)
541 [ + - ]: 21 : const Fraction aNeutralFraction(1, 1);
542 [ + - ]: 21 : const MapMode aRelativeMapMode(MAP_RELATIVE, Point(-aBound.Left(), -aBound.Top()), aNeutralFraction, aNeutralFraction);
543 [ + - ]: 21 : aOut.SetMapMode(aRelativeMapMode);
544 : :
545 [ + - ]: 21 : DrawMarkedObj(aOut);
546 : :
547 [ + - ]: 21 : aMtf.Stop();
548 [ + - ]: 21 : aMtf.WindStart();
549 [ + - ]: 21 : aMtf.SetPrefMapMode( aMap );
550 : :
551 : : // removed PrefSize extension. It is principally wrong to set a reduced size at
552 : : // the created MetaFile. The mentioned errors occur at output time since the integer
553 : : // MapModes from VCL lead to errors. It is now corrected in the VCLRenderer for
554 : : // primitives (and may later be done in breaking up a MetaFile to primitives)
555 [ + - ][ + - ]: 21 : aMtf.SetPrefSize(aBoundSize);
556 [ + - ]: 21 : }
557 : : }
558 : :
559 : 21 : return aMtf;
560 : : }
561 : :
562 : : // -----------------------------------------------------------------------------
563 : :
564 : 0 : Graphic SdrExchangeView::GetAllMarkedGraphic() const
565 : : {
566 : 0 : Graphic aRet;
567 : :
568 [ # # ]: 0 : if( AreObjectsMarked() )
569 : : {
570 [ # # ][ # # ]: 0 : if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
[ # # ][ # # ]
571 [ # # ][ # # ]: 0 : aRet = SdrExchangeView::GetObjGraphic( pMod, GetMarkedObjectByIndex( 0 ) );
[ # # ][ # # ]
572 : : else
573 [ # # ][ # # ]: 0 : aRet = GetMarkedObjMetaFile( sal_False );
[ # # ][ # # ]
[ # # ]
574 : : }
575 : :
576 : 0 : return aRet;
577 : : }
578 : :
579 : : // -----------------------------------------------------------------------------
580 : :
581 : 3 : Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj )
582 : : {
583 : 3 : Graphic aRet;
584 : :
585 [ + - ][ + - ]: 3 : if( pModel && pObj )
586 : : {
587 : : // try to get a graphic from the object first
588 [ - + ]: 3 : const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
589 [ - + ]: 3 : const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
590 : :
591 [ - + ]: 3 : if(pSdrGrafObj)
592 : : {
593 : : // Make behaviour coherent with metafile
594 : : // recording below (which of course also takes
595 : : // view-transformed objects)
596 [ # # ][ # # ]: 0 : aRet = pSdrGrafObj->GetTransformedGraphic();
[ # # ]
597 : : }
598 [ - + ]: 3 : else if(pSdrOle2Obj)
599 : : {
600 [ # # ][ # # ]: 0 : if ( pSdrOle2Obj->GetGraphic() )
601 [ # # ][ # # ]: 0 : aRet = *pSdrOle2Obj->GetGraphic();
602 : : }
603 : :
604 : : // if graphic could not be retrieved => go the hard way and create a MetaFile
605 [ + - ][ - + ]: 3 : if( ( GRAPHIC_NONE == aRet.GetType() ) || ( GRAPHIC_DEFAULT == aRet.GetType() ) )
[ # # ][ # # ]
[ + - ]
606 : : {
607 [ + - ]: 3 : VirtualDevice aOut;
608 [ + - ]: 3 : GDIMetaFile aMtf;
609 [ + - ]: 3 : const Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
610 : : const MapMode aMap( pModel->GetScaleUnit(),
611 : : Point(),
612 : 3 : pModel->GetScaleFraction(),
613 [ + - ]: 6 : pModel->GetScaleFraction() );
614 : :
615 [ + - ]: 3 : aOut.EnableOutput( sal_False );
616 [ + - ]: 3 : aOut.SetMapMode( aMap );
617 [ + - ]: 3 : aMtf.Record( &aOut );
618 [ + - ]: 3 : pObj->SingleObjectPainter( aOut );
619 [ + - ]: 3 : aMtf.Stop();
620 [ + - ]: 3 : aMtf.WindStart();
621 : :
622 : : // #i99268# replace the original offset from using XOutDev's SetOffset
623 : : // NOT (as tried with #i92760#) with another MapMode which gets recorded
624 : : // by the Metafile itself (what always leads to problems), but by hardly
625 : : // moving the result
626 [ + - ]: 3 : aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
627 : :
628 [ + - ]: 3 : aMtf.SetPrefMapMode( aMap );
629 [ + - ]: 3 : aMtf.SetPrefSize( aBoundRect.GetSize() );
630 : :
631 [ + - ][ + - ]: 3 : if( aMtf.GetActionSize() )
632 [ + - ][ + - ]: 3 : aRet = aMtf;
[ + - ][ + - ]
[ + - ][ + - ]
633 : : }
634 : : }
635 : :
636 : 3 : return aRet;
637 : : }
638 : :
639 : : // -----------------------------------------------------------------------------
640 : :
641 : 21 : void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const
642 : : {
643 [ + - ]: 21 : SortMarkedObjects();
644 : :
645 [ + - ]: 21 : ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
646 [ + - ]: 21 : ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
647 [ + - ]: 21 : ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
648 : 21 : const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
649 [ + - ]: 21 : const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
650 : : sal_uInt32 n, nCount;
651 : :
652 [ + + ]: 42 : for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
653 : : {
654 [ + - ]: 21 : SdrMark* pMark = GetSdrMarkByIndex( n );
655 : :
656 : : // paint objects on control layer on top of all other objects
657 [ + - ][ + - ]: 21 : if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
[ - + ]
658 [ # # ]: 0 : rObjVector2.push_back( pMark );
659 : : else
660 [ + - ]: 21 : rObjVector1.push_back( pMark );
661 : : }
662 : :
663 [ + + ]: 63 : for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
664 : : {
665 [ + - ]: 42 : ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
666 : :
667 [ + + ]: 63 : for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
668 : : {
669 [ + - ]: 21 : SdrMark* pMark = rObjVector[ i ];
670 [ + - ][ + - ]: 21 : pMark->GetMarkedSdrObj()->SingleObjectPainter( rOut );
671 : : }
672 : 21 : }
673 : 21 : }
674 : :
675 : : // -----------------------------------------------------------------------------
676 : :
677 : 0 : SdrModel* SdrExchangeView::GetMarkedObjModel() const
678 : : {
679 : : // Sorting the MarkList here might be problematic in the future, so
680 : : // use a copy.
681 : 0 : SortMarkedObjects();
682 : 0 : SdrModel* pNeuMod=pMod->AllocModel();
683 : 0 : SdrPage* pNeuPag=pNeuMod->AllocPage(sal_False);
684 : 0 : pNeuMod->InsertPage(pNeuPag);
685 : :
686 [ # # ][ # # ]: 0 : if( !mxSelectionController.is() || !mxSelectionController->GetMarkedObjModel( pNeuPag ) )
[ # # ]
687 : : {
688 [ # # ]: 0 : ::std::vector< ::std::vector< SdrMark* > > aObjVectors( 2 );
689 [ # # ]: 0 : ::std::vector< SdrMark* >& rObjVector1 = aObjVectors[ 0 ];
690 [ # # ]: 0 : ::std::vector< SdrMark* >& rObjVector2 = aObjVectors[ 1 ];
691 : 0 : const SdrLayerAdmin& rLayerAdmin = pMod->GetLayerAdmin();
692 [ # # ]: 0 : const sal_uInt32 nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
693 : 0 : sal_uInt32 n, nCount, nCloneErrCnt = 0;
694 : :
695 [ # # ]: 0 : for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
696 : : {
697 [ # # ]: 0 : SdrMark* pMark = GetSdrMarkByIndex( n );
698 : :
699 : : // paint objects on control layer on top of all otherobjects
700 [ # # ][ # # ]: 0 : if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
[ # # ]
701 [ # # ]: 0 : rObjVector2.push_back( pMark );
702 : : else
703 [ # # ]: 0 : rObjVector1.push_back( pMark );
704 : : }
705 : :
706 : : // #i13033#
707 : : // New mechanism to re-create the connections of cloned connectors
708 [ # # ]: 0 : CloneList aCloneList;
709 : :
710 [ # # ]: 0 : for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
711 : : {
712 [ # # ]: 0 : ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
713 : :
714 [ # # ]: 0 : for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
715 : : {
716 [ # # ]: 0 : const SdrMark* pMark = rObjVector[ i ];
717 [ # # ]: 0 : const SdrObject* pObj = pMark->GetMarkedSdrObj();
718 : : SdrObject* pNeuObj;
719 : :
720 [ # # ][ # # ]: 0 : if( pObj->ISA( SdrPageObj ) )
[ # # ]
721 : : {
722 : : // convert SdrPageObj's to a graphic representation, because
723 : : // virtual connection to referenced page gets lost in new model
724 [ # # ][ # # ]: 0 : pNeuObj = new SdrGrafObj( GetObjGraphic( pMod, pObj ), pObj->GetLogicRect() );
[ # # ][ # # ]
[ # # ]
725 [ # # ]: 0 : pNeuObj->SetPage( pNeuPag );
726 [ # # ]: 0 : pNeuObj->SetModel( pNeuMod );
727 : : }
728 : : else
729 : : {
730 [ # # ]: 0 : pNeuObj = pObj->Clone();
731 [ # # ]: 0 : pNeuObj->SetPage( pNeuPag );
732 [ # # ]: 0 : pNeuObj->SetModel( pNeuMod );
733 : : }
734 : :
735 [ # # ]: 0 : if( pNeuObj )
736 : : {
737 : 0 : SdrInsertReason aReason(SDRREASON_VIEWCALL);
738 [ # # ]: 0 : pNeuPag->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
739 : :
740 : : // #i13033#
741 [ # # ]: 0 : aCloneList.AddPair(pObj, pNeuObj);
742 : : }
743 : : else
744 : 0 : nCloneErrCnt++;
745 : : }
746 : : }
747 : :
748 : : // #i13033#
749 : : // New mechanism to re-create the connections of cloned connectors
750 [ # # ]: 0 : aCloneList.CopyConnections();
751 : :
752 : : if(0L != nCloneErrCnt)
753 : : {
754 : : #ifdef DBG_UTIL
755 : : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
756 : : "SdrExchangeView::GetMarkedObjModel(): Error when cloning "));
757 : :
758 : : if(nCloneErrCnt == 1)
759 : : {
760 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(
761 : : "a drawing object."));
762 : : }
763 : : else
764 : : {
765 : : aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
766 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
767 : : }
768 : :
769 : : aStr.append(RTL_CONSTASCII_STRINGPARAM(
770 : : " Not copying object connectors."));
771 : :
772 : : OSL_FAIL(aStr.getStr());
773 : : #endif
774 : 0 : }
775 : : }
776 : 0 : return pNeuMod;
777 : : }
778 : :
779 : : // -----------------------------------------------------------------------------
780 : :
781 : 0 : sal_Bool SdrExchangeView::Cut( sal_uIntPtr /*nFormat */)
782 : : {
783 : : OSL_FAIL( "SdrExchangeView::Cut: Not supported any more." );
784 : 0 : return sal_False;
785 : : }
786 : :
787 : : // -----------------------------------------------------------------------------
788 : :
789 : 0 : sal_Bool SdrExchangeView::Yank(sal_uIntPtr /*nFormat*/)
790 : : {
791 : : OSL_FAIL( "SdrExchangeView::Yank: Not supported any more." );
792 : 0 : return sal_False;
793 : : }
794 : :
795 : : // -----------------------------------------------------------------------------
796 : :
797 : 0 : sal_Bool SdrExchangeView::Paste(Window* /*pWin*/, sal_uIntPtr /*nFormat*/)
798 : : {
799 : : OSL_FAIL( "SdrExchangeView::Paste: Not supported any more." );
800 : 0 : return sal_False;
801 : : }
802 : :
803 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|