xref: /trunk/main/svx/source/svdraw/svdxcgv.cxx (revision fe9b7f6a5f0c378e0c911bf69d0633ad596c6f08)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <vector>
26cdf0e10cSrcweir #include <editeng/editeng.hxx>
279f63b866SArmin Le Grand #include <svx/xexch.hxx>
28cdf0e10cSrcweir #include <svx/xflclit.hxx>
29cdf0e10cSrcweir #include <svx/svdxcgv.hxx>
30cdf0e10cSrcweir #include <svx/svdoutl.hxx>
319f63b866SArmin Le Grand #include <svx/svditext.hxx>
32cdf0e10cSrcweir #include <svx/svdetc.hxx>
33cdf0e10cSrcweir #include <svx/svdundo.hxx>
34cdf0e10cSrcweir #include <svx/svdograf.hxx>
35*fe9b7f6aSmseidel #include <svx/svdoole2.hxx> // für kein OLE im SdrClipboardFormat
36cdf0e10cSrcweir #include <svx/svdorect.hxx>
37*fe9b7f6aSmseidel #include <svx/svdoedge.hxx> // für Konnektoren uebers Clipboard
38*fe9b7f6aSmseidel #include <svx/svdopage.hxx> // für Konnektoren uebers Clipboard
39cdf0e10cSrcweir #include <svx/svdpage.hxx>
40cdf0e10cSrcweir #include <svx/svdpagv.hxx>
41*fe9b7f6aSmseidel #include <svx/svdtrans.hxx> // Für GetMapFactor zum umskalieren bei PasteModel
42*fe9b7f6aSmseidel #include "svx/svdstr.hrc" // Names from resource
43cdf0e10cSrcweir #include "svx/svdglob.hxx" // StringCache
44cdf0e10cSrcweir #include "svx/xoutbmp.hxx"
45cdf0e10cSrcweir #include <vcl/metaact.hxx>
46cdf0e10cSrcweir #include <svl/poolitem.hxx>
47cdf0e10cSrcweir #include <svl/itempool.hxx>
48cdf0e10cSrcweir #include <tools/bigint.hxx>
49cdf0e10cSrcweir #include <sot/formats.hxx>
50cdf0e10cSrcweir #include <clonelist.hxx>
51cdf0e10cSrcweir #include <vcl/virdev.hxx>
52cdf0e10cSrcweir #include <svl/style.hxx>
539f63b866SArmin Le Grand #include <fmobj.hxx>
549f63b866SArmin Le Grand #include <vcl/svgdata.hxx>
55958da553SArmin Le Grand #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
56958da553SArmin Le Grand #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
57958da553SArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx>
58958da553SArmin Le Grand #include <svx/sdr/contact/viewcontact.hxx>
59958da553SArmin Le Grand #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
60958da553SArmin Le Grand #include <svx/sdr/contact/displayinfo.hxx>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
63cdf0e10cSrcweir 
SdrExchangeView(SdrModel * pModel1,OutputDevice * pOut)64cdf0e10cSrcweir SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut):
65cdf0e10cSrcweir     SdrObjEditView(pModel1,pOut)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
70cdf0e10cSrcweir 
GetViewCenter(const OutputDevice * pOut) const71cdf0e10cSrcweir Point SdrExchangeView::GetViewCenter(const OutputDevice* pOut) const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     Point aCenter;
74cdf0e10cSrcweir     if (pOut==NULL)
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         pOut = GetFirstOutputDevice();
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir     if (pOut!=NULL) {
79cdf0e10cSrcweir         Point aOfs=pOut->GetMapMode().GetOrigin();
80cdf0e10cSrcweir         Size aOutSiz=pOut->GetOutputSize();
81cdf0e10cSrcweir         aOutSiz.Width()/=2;
82cdf0e10cSrcweir         aOutSiz.Height()/=2;
83cdf0e10cSrcweir         aCenter.X()=aOutSiz.Width() -aOfs.X();
84cdf0e10cSrcweir         aCenter.Y()=aOutSiz.Height()-aOfs.Y();
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir     return aCenter;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
GetPastePos(SdrObjList * pLst,OutputDevice * pOut)89cdf0e10cSrcweir Point SdrExchangeView::GetPastePos(SdrObjList* pLst, OutputDevice* pOut)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     Point aP(GetViewCenter(pOut));
92cdf0e10cSrcweir     SdrPage* pPg=NULL;
93cdf0e10cSrcweir     if (pLst!=NULL) pPg=pLst->GetPage();
94cdf0e10cSrcweir     if (pPg!=NULL) {
95cdf0e10cSrcweir         Size aSiz(pPg->GetSize());
96cdf0e10cSrcweir         aP.X()=aSiz.Width()/2;
97cdf0e10cSrcweir         aP.Y()=aSiz.Height()/2;
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir     return aP;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
ImpLimitToWorkArea(Point & rPt) const102cdf0e10cSrcweir sal_Bool SdrExchangeView::ImpLimitToWorkArea(Point& rPt) const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     sal_Bool bRet(sal_False);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     if(!aMaxWorkArea.IsEmpty())
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         if(rPt.X()<aMaxWorkArea.Left())
109cdf0e10cSrcweir         {
110cdf0e10cSrcweir             rPt.X() = aMaxWorkArea.Left();
111cdf0e10cSrcweir             bRet = sal_True;
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         if(rPt.X()>aMaxWorkArea.Right())
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             rPt.X() = aMaxWorkArea.Right();
117cdf0e10cSrcweir             bRet = sal_True;
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         if(rPt.Y()<aMaxWorkArea.Top())
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             rPt.Y() = aMaxWorkArea.Top();
123cdf0e10cSrcweir             bRet = sal_True;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         if(rPt.Y()>aMaxWorkArea.Bottom())
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             rPt.Y() = aMaxWorkArea.Bottom();
129cdf0e10cSrcweir             bRet = sal_True;
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir     return bRet;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
ImpGetPasteObjList(Point &,SdrObjList * & rpLst)135cdf0e10cSrcweir void SdrExchangeView::ImpGetPasteObjList(Point& /*rPos*/, SdrObjList*& rpLst)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     if (rpLst==NULL)
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         SdrPageView* pPV = GetSdrPageView();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         if (pPV!=NULL) {
142cdf0e10cSrcweir             rpLst=pPV->GetObjList();
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
ImpGetPasteLayer(const SdrObjList * pObjList,SdrLayerID & rLayer) const147cdf0e10cSrcweir sal_Bool SdrExchangeView::ImpGetPasteLayer(const SdrObjList* pObjList, SdrLayerID& rLayer) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     sal_Bool bRet=sal_False;
150cdf0e10cSrcweir     rLayer=0;
151cdf0e10cSrcweir     if (pObjList!=NULL) {
152cdf0e10cSrcweir         const SdrPage* pPg=pObjList->GetPage();
153cdf0e10cSrcweir         if (pPg!=NULL) {
154cdf0e10cSrcweir             rLayer=pPg->GetLayerAdmin().GetLayerID(aAktLayer,sal_True);
155cdf0e10cSrcweir             if (rLayer==SDRLAYER_NOTFOUND) rLayer=0;
156cdf0e10cSrcweir             SdrPageView* pPV = GetSdrPageView();
157cdf0e10cSrcweir             if (pPV!=NULL) {
158cdf0e10cSrcweir                 bRet=!pPV->GetLockedLayers().IsSet(rLayer) && pPV->GetVisibleLayers().IsSet(rLayer);
159cdf0e10cSrcweir             }
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir     return bRet;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
166cdf0e10cSrcweir 
Paste(const GDIMetaFile & rMtf,const Point & rPos,SdrObjList * pLst,sal_uInt32 nOptions)167cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(const GDIMetaFile& rMtf, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     Point aPos(rPos);
170cdf0e10cSrcweir     ImpGetPasteObjList(aPos,pLst);
171cdf0e10cSrcweir     ImpLimitToWorkArea( aPos );
172cdf0e10cSrcweir     if (pLst==NULL) return sal_False;
173cdf0e10cSrcweir     SdrLayerID nLayer;
174cdf0e10cSrcweir     if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
175cdf0e10cSrcweir     sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
176cdf0e10cSrcweir     if (bUnmark) UnmarkAllObj();
177cdf0e10cSrcweir     SdrGrafObj* pObj=new SdrGrafObj(Graphic(rMtf));
178cdf0e10cSrcweir     pObj->SetLayer(nLayer);
179cdf0e10cSrcweir     ImpPasteObject(pObj,*pLst,aPos,rMtf.GetPrefSize(),rMtf.GetPrefMapMode(),nOptions);
180cdf0e10cSrcweir     return sal_True;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
Paste(const Bitmap & rBmp,const Point & rPos,SdrObjList * pLst,sal_uInt32 nOptions)183cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(const Bitmap& rBmp, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     Point aPos(rPos);
186cdf0e10cSrcweir     ImpGetPasteObjList(aPos,pLst);
187cdf0e10cSrcweir     ImpLimitToWorkArea( aPos );
188cdf0e10cSrcweir     if (pLst==NULL) return sal_False;
189cdf0e10cSrcweir     SdrLayerID nLayer;
190cdf0e10cSrcweir     if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
191cdf0e10cSrcweir     sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
192cdf0e10cSrcweir     if (bUnmark) UnmarkAllObj();
193cdf0e10cSrcweir     SdrGrafObj* pObj=new SdrGrafObj(Graphic(rBmp));
194cdf0e10cSrcweir     pObj->SetLayer(nLayer);
195cdf0e10cSrcweir     ImpPasteObject(pObj,*pLst,aPos,rBmp.GetSizePixel(),MapMode(MAP_PIXEL),nOptions);
196cdf0e10cSrcweir     return sal_True;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
Paste(const XubString & rStr,const Point & rPos,SdrObjList * pLst,sal_uInt32 nOptions)199cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(const XubString& rStr, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     if(!rStr.Len())
202cdf0e10cSrcweir         return sal_False;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     Point aPos(rPos);
205cdf0e10cSrcweir     ImpGetPasteObjList(aPos,pLst);
206cdf0e10cSrcweir     ImpLimitToWorkArea( aPos );
207cdf0e10cSrcweir     if (pLst==NULL) return sal_False;
208cdf0e10cSrcweir     SdrLayerID nLayer;
209cdf0e10cSrcweir     if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
210cdf0e10cSrcweir     sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
211cdf0e10cSrcweir     if (bUnmark) UnmarkAllObj();
212cdf0e10cSrcweir     Rectangle aTextRect(0,0,500,500);
213cdf0e10cSrcweir     SdrPage* pPage=pLst->GetPage();
214cdf0e10cSrcweir     if (pPage!=NULL) {
215cdf0e10cSrcweir         aTextRect.SetSize(pPage->GetSize());
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir     SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
218cdf0e10cSrcweir     pObj->SetModel(pMod);
219cdf0e10cSrcweir     pObj->SetLayer(nLayer);
220cdf0e10cSrcweir     pObj->NbcSetText(rStr); // #32424# SetText vor SetAttr, weil SetAttr sonst unwirksam!
221cdf0e10cSrcweir     if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     pObj->SetMergedItemSet(aDefaultAttr);
224cdf0e10cSrcweir 
225*fe9b7f6aSmseidel     SfxItemSet aTempAttr(pMod->GetItemPool()); // Keine Füllung oder Linie
226cdf0e10cSrcweir     aTempAttr.Put(XLineStyleItem(XLINE_NONE));
227cdf0e10cSrcweir     aTempAttr.Put(XFillStyleItem(XFILL_NONE));
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     pObj->SetMergedItemSet(aTempAttr);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     pObj->FitFrameToTextSize();
232cdf0e10cSrcweir     Size aSiz(pObj->GetLogicRect().GetSize());
233cdf0e10cSrcweir     MapUnit eMap=pMod->GetScaleUnit();
234cdf0e10cSrcweir     Fraction aMap=pMod->GetScaleFraction();
235cdf0e10cSrcweir     ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
236cdf0e10cSrcweir     return sal_True;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
Paste(SvStream & rInput,const String & rBaseURL,sal_uInt16 eFormat,const Point & rPos,SdrObjList * pLst,sal_uInt32 nOptions)239cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(SvStream& rInput, const String& rBaseURL, sal_uInt16 eFormat, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     Point aPos(rPos);
242cdf0e10cSrcweir     ImpGetPasteObjList(aPos,pLst);
243cdf0e10cSrcweir     ImpLimitToWorkArea( aPos );
244cdf0e10cSrcweir     if (pLst==NULL) return sal_False;
245cdf0e10cSrcweir     SdrLayerID nLayer;
246cdf0e10cSrcweir     if (!ImpGetPasteLayer(pLst,nLayer)) return sal_False;
247cdf0e10cSrcweir     sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
248cdf0e10cSrcweir     if (bUnmark) UnmarkAllObj();
249cdf0e10cSrcweir     Rectangle aTextRect(0,0,500,500);
250cdf0e10cSrcweir     SdrPage* pPage=pLst->GetPage();
251cdf0e10cSrcweir     if (pPage!=NULL) {
252cdf0e10cSrcweir         aTextRect.SetSize(pPage->GetSize());
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir     SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
255cdf0e10cSrcweir     pObj->SetModel(pMod);
256cdf0e10cSrcweir     pObj->SetLayer(nLayer);
257cdf0e10cSrcweir     if (pDefaultStyleSheet!=NULL) pObj->NbcSetStyleSheet(pDefaultStyleSheet, sal_False);
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     pObj->SetMergedItemSet(aDefaultAttr);
260cdf0e10cSrcweir 
261*fe9b7f6aSmseidel     SfxItemSet aTempAttr(pMod->GetItemPool()); // Keine Füllung oder Linie
262cdf0e10cSrcweir     aTempAttr.Put(XLineStyleItem(XLINE_NONE));
263cdf0e10cSrcweir     aTempAttr.Put(XFillStyleItem(XFILL_NONE));
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     pObj->SetMergedItemSet(aTempAttr);
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     pObj->NbcSetText(rInput,rBaseURL,eFormat);
268cdf0e10cSrcweir     pObj->FitFrameToTextSize();
269cdf0e10cSrcweir     Size aSiz(pObj->GetLogicRect().GetSize());
270cdf0e10cSrcweir     MapUnit eMap=pMod->GetScaleUnit();
271cdf0e10cSrcweir     Fraction aMap=pMod->GetScaleFraction();
272cdf0e10cSrcweir     ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // b4967543
275cdf0e10cSrcweir     if(pObj && pObj->GetModel() && pObj->GetOutlinerParaObject())
276cdf0e10cSrcweir     {
277cdf0e10cSrcweir         SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner();
278cdf0e10cSrcweir         rOutliner.SetText(*pObj->GetOutlinerParaObject());
279cdf0e10cSrcweir 
280cdf0e10cSrcweir         if(1L == rOutliner.GetParagraphCount())
281cdf0e10cSrcweir         {
282cdf0e10cSrcweir             SfxStyleSheet* pCandidate = rOutliner.GetStyleSheet(0L);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir             if(pCandidate)
285cdf0e10cSrcweir             {
286cdf0e10cSrcweir                 if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool())
287cdf0e10cSrcweir                 {
288cdf0e10cSrcweir                     pObj->NbcSetStyleSheet(pCandidate, sal_True);
289cdf0e10cSrcweir                 }
290cdf0e10cSrcweir             }
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     return sal_True;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
Paste(const SdrModel & rMod,const Point & rPos,SdrObjList * pLst,sal_uInt32 nOptions)297cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(const SdrModel& rMod, const Point& rPos, SdrObjList* pLst, sal_uInt32 nOptions)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir     const SdrModel* pSrcMod=&rMod;
300cdf0e10cSrcweir     if (pSrcMod==pMod)
301cdf0e10cSrcweir         return sal_False; // na so geht's ja nun nicht
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     const bool bUndo = IsUndoEnabled();
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     if( bUndo )
306cdf0e10cSrcweir         BegUndo(ImpGetResStr(STR_ExchangePaste));
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     if( mxSelectionController.is() && mxSelectionController->PasteObjModel( rMod ) )
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         if( bUndo )
311cdf0e10cSrcweir             EndUndo();
312cdf0e10cSrcweir         return sal_True;
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     Point aPos(rPos);
316cdf0e10cSrcweir     ImpGetPasteObjList(aPos,pLst);
317cdf0e10cSrcweir     SdrPageView* pMarkPV=NULL;
318cdf0e10cSrcweir     SdrPageView* pPV = GetSdrPageView();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     if(pPV)
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir         if ( pPV->GetObjList() == pLst )
323cdf0e10cSrcweir             pMarkPV=pPV;
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     ImpLimitToWorkArea( aPos );
327cdf0e10cSrcweir     if (pLst==NULL)
328cdf0e10cSrcweir         return sal_False;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     sal_Bool bUnmark=(nOptions&(SDRINSERT_DONTMARK|SDRINSERT_ADDMARK))==0 && !IsTextEdit();
331cdf0e10cSrcweir     if (bUnmark)
332cdf0e10cSrcweir         UnmarkAllObj();
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     // evtl. umskalieren bei unterschiedlicher MapUnit am Model
335*fe9b7f6aSmseidel     // Dafür erstmal die Faktoren berechnen
336cdf0e10cSrcweir     MapUnit eSrcUnit=pSrcMod->GetScaleUnit();
337cdf0e10cSrcweir     MapUnit eDstUnit=pMod->GetScaleUnit();
338cdf0e10cSrcweir     sal_Bool bResize=eSrcUnit!=eDstUnit;
339cdf0e10cSrcweir     Fraction xResize,yResize;
340cdf0e10cSrcweir     Point aPt0;
341cdf0e10cSrcweir     if (bResize)
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
344cdf0e10cSrcweir         xResize=aResize.X();
345cdf0e10cSrcweir         yResize=aResize.Y();
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir     SdrObjList*  pDstLst=pLst;
348cdf0e10cSrcweir     sal_uInt16 nPg,nPgAnz=pSrcMod->GetPageCount();
349cdf0e10cSrcweir     for (nPg=0; nPg<nPgAnz; nPg++)
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         const SdrPage* pSrcPg=pSrcMod->GetPage(nPg);
352cdf0e10cSrcweir 
353cdf0e10cSrcweir         // #104148# Use SnapRect, not BoundRect here
354cdf0e10cSrcweir         Rectangle aR=pSrcPg->GetAllObjSnapRect();
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         if (bResize)
357cdf0e10cSrcweir             ResizeRect(aR,aPt0,xResize,yResize);
358cdf0e10cSrcweir         Point aDist(aPos-aR.Center());
359cdf0e10cSrcweir         Size  aSiz(aDist.X(),aDist.Y());
360cdf0e10cSrcweir         //sal_uIntPtr nDstObjAnz0=pDstLst->GetObjCount();
361cdf0e10cSrcweir         sal_uIntPtr nCloneErrCnt=0;
362cdf0e10cSrcweir         sal_uIntPtr nOb,nObAnz=pSrcPg->GetObjCount();
363cdf0e10cSrcweir         sal_Bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir         // #i13033#
366cdf0e10cSrcweir         // New mechanism to re-create the connections of cloned connectors
367cdf0e10cSrcweir         CloneList aCloneList;
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         for (nOb=0; nOb<nObAnz; nOb++)
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
372cdf0e10cSrcweir 
373cdf0e10cSrcweir             // #116235#
374*fe9b7f6aSmseidel             SdrObject* pNewObj = pSrcOb->Clone();
375cdf0e10cSrcweir 
376*fe9b7f6aSmseidel             if (pNewObj!=NULL)
377cdf0e10cSrcweir             {
378cdf0e10cSrcweir                 if(bResize)
379cdf0e10cSrcweir                 {
380*fe9b7f6aSmseidel                     pNewObj->GetModel()->SetPasteResize(sal_True); // #51139#
381*fe9b7f6aSmseidel                     pNewObj->NbcResize(aPt0,xResize,yResize);
382*fe9b7f6aSmseidel                     pNewObj->GetModel()->SetPasteResize(sal_False); // #51139#
383cdf0e10cSrcweir                 }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir                 // #i39861#
386*fe9b7f6aSmseidel                 pNewObj->SetModel(pDstLst->GetModel());
387*fe9b7f6aSmseidel                 pNewObj->SetPage(pDstLst->GetPage());
388cdf0e10cSrcweir 
389*fe9b7f6aSmseidel                 pNewObj->NbcMove(aSiz);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                 const SdrPage* pPg = pDstLst->GetPage();
392cdf0e10cSrcweir 
393cdf0e10cSrcweir                 if(pPg)
394cdf0e10cSrcweir                 {
395cdf0e10cSrcweir                     // #i72535#
396cdf0e10cSrcweir                     const SdrLayerAdmin& rAd = pPg->GetLayerAdmin();
397cdf0e10cSrcweir                     SdrLayerID nLayer(0);
398cdf0e10cSrcweir 
399*fe9b7f6aSmseidel                     if(pNewObj->ISA(FmFormObj))
400cdf0e10cSrcweir                     {
401cdf0e10cSrcweir                         // for FormControls, force to form layer
402cdf0e10cSrcweir                         nLayer = rAd.GetLayerID(rAd.GetControlLayerName(), true);
403cdf0e10cSrcweir                     }
404cdf0e10cSrcweir                     else
405cdf0e10cSrcweir                     {
406cdf0e10cSrcweir                         nLayer = rAd.GetLayerID(aAktLayer, sal_True);
407cdf0e10cSrcweir                     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir                     if(SDRLAYER_NOTFOUND == nLayer)
410cdf0e10cSrcweir                     {
411cdf0e10cSrcweir                         nLayer = 0;
412cdf0e10cSrcweir                     }
413cdf0e10cSrcweir 
414*fe9b7f6aSmseidel                     pNewObj->SetLayer(nLayer);
415cdf0e10cSrcweir                 }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir                 SdrInsertReason aReason(SDRREASON_VIEWCALL);
418*fe9b7f6aSmseidel                 pDstLst->InsertObject(pNewObj,CONTAINER_APPEND,&aReason);
419cdf0e10cSrcweir 
420cdf0e10cSrcweir                 if( bUndo )
421*fe9b7f6aSmseidel                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));
422cdf0e10cSrcweir 
423cdf0e10cSrcweir                 if (bMark) {
424cdf0e10cSrcweir                     // Markhandles noch nicht sofort setzen!
425cdf0e10cSrcweir                     // Das erledigt das ModelHasChanged der MarkView.
426*fe9b7f6aSmseidel                     MarkObj(pNewObj,pMarkPV,sal_False,sal_True);
427cdf0e10cSrcweir                 }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir                 // #i13033#
430*fe9b7f6aSmseidel                 aCloneList.AddPair(pSrcOb, pNewObj);
431cdf0e10cSrcweir             }
432cdf0e10cSrcweir             else
433cdf0e10cSrcweir             {
434cdf0e10cSrcweir                 nCloneErrCnt++;
435cdf0e10cSrcweir             }
436cdf0e10cSrcweir         }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir         // #i13033#
439cdf0e10cSrcweir         // New mechanism to re-create the connections of cloned connectors
440cdf0e10cSrcweir         aCloneList.CopyConnections();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         if(0L != nCloneErrCnt)
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir #ifdef DBG_UTIL
445cdf0e10cSrcweir             ByteString aStr("SdrExchangeView::Paste(): Fehler beim Clonen ");
446cdf0e10cSrcweir 
447cdf0e10cSrcweir             if(nCloneErrCnt == 1)
448cdf0e10cSrcweir             {
449cdf0e10cSrcweir                 aStr += "eines Zeichenobjekts.";
450cdf0e10cSrcweir             }
451cdf0e10cSrcweir             else
452cdf0e10cSrcweir             {
453cdf0e10cSrcweir                 aStr += "von ";
454cdf0e10cSrcweir                 aStr += ByteString::CreateFromInt32( nCloneErrCnt );
455cdf0e10cSrcweir                 aStr += " Zeichenobjekten.";
456cdf0e10cSrcweir             }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir             aStr += " Objektverbindungen werden nicht mitkopiert.";
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             DBG_ERROR(aStr.GetBuffer());
461cdf0e10cSrcweir #endif
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     if( bUndo )
466cdf0e10cSrcweir         EndUndo();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     return sal_True;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
IsExchangeFormatSupported(sal_uIntPtr nFormat) const471cdf0e10cSrcweir sal_Bool SdrExchangeView::IsExchangeFormatSupported(sal_uIntPtr nFormat) const
472cdf0e10cSrcweir {
473cdf0e10cSrcweir     return( FORMAT_PRIVATE == nFormat ||
474cdf0e10cSrcweir             FORMAT_GDIMETAFILE == nFormat ||
475cdf0e10cSrcweir             FORMAT_BITMAP == nFormat ||
476cdf0e10cSrcweir             FORMAT_RTF == nFormat ||
477cdf0e10cSrcweir             FORMAT_STRING == nFormat ||
478cdf0e10cSrcweir             SOT_FORMATSTR_ID_DRAWING == nFormat ||
479cdf0e10cSrcweir             SOT_FORMATSTR_ID_EDITENGINE == nFormat );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
ImpPasteObject(SdrObject * pObj,SdrObjList & rLst,const Point & rCenter,const Size & rSiz,const MapMode & rMap,sal_uInt32 nOptions)482cdf0e10cSrcweir void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Point& rCenter, const Size& rSiz, const MapMode& rMap, sal_uInt32 nOptions)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     BigInt nSizX(rSiz.Width());
485cdf0e10cSrcweir     BigInt nSizY(rSiz.Height());
486cdf0e10cSrcweir     MapUnit eSrcMU=rMap.GetMapUnit();
487cdf0e10cSrcweir     MapUnit eDstMU=pMod->GetScaleUnit();
488cdf0e10cSrcweir     FrPair aMapFact(GetMapFactor(eSrcMU,eDstMU));
489cdf0e10cSrcweir     Fraction aDstFr(pMod->GetScaleFraction());
490cdf0e10cSrcweir     nSizX*=aMapFact.X().GetNumerator();
491cdf0e10cSrcweir     nSizX*=rMap.GetScaleX().GetNumerator();
492cdf0e10cSrcweir     nSizX*=aDstFr.GetDenominator();
493cdf0e10cSrcweir     nSizX/=aMapFact.X().GetDenominator();
494cdf0e10cSrcweir     nSizX/=rMap.GetScaleX().GetDenominator();
495cdf0e10cSrcweir     nSizX/=aDstFr.GetNumerator();
496cdf0e10cSrcweir     nSizY*=aMapFact.Y().GetNumerator();
497cdf0e10cSrcweir     nSizY*=rMap.GetScaleY().GetNumerator();
498cdf0e10cSrcweir     nSizX*=aDstFr.GetDenominator();
499cdf0e10cSrcweir     nSizY/=aMapFact.Y().GetDenominator();
500cdf0e10cSrcweir     nSizY/=rMap.GetScaleY().GetDenominator();
501cdf0e10cSrcweir     nSizY/=aDstFr.GetNumerator();
502cdf0e10cSrcweir     long xs=nSizX;
503cdf0e10cSrcweir     long ys=nSizY;
504cdf0e10cSrcweir     Point aPos(rCenter.X()-xs/2,rCenter.Y()-ys/2);
505cdf0e10cSrcweir     Rectangle aR(aPos.X(),aPos.Y(),aPos.X()+xs,aPos.Y()+ys);
506cdf0e10cSrcweir     pObj->SetLogicRect(aR);
507cdf0e10cSrcweir     SdrInsertReason aReason(SDRREASON_VIEWCALL);
508cdf0e10cSrcweir     rLst.InsertObject(pObj,CONTAINER_APPEND,&aReason);
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     if( IsUndoEnabled() )
511cdf0e10cSrcweir         AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     SdrPageView* pMarkPV=NULL;
514cdf0e10cSrcweir     SdrPageView* pPV = GetSdrPageView();
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     if(pPV)
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         if (pPV->GetObjList()==&rLst)
519cdf0e10cSrcweir             pMarkPV=pPV;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     sal_Bool bMark=pMarkPV!=NULL && !IsTextEdit() && (nOptions&SDRINSERT_DONTMARK)==0;
523cdf0e10cSrcweir     if (bMark)
524cdf0e10cSrcweir     { // Obj in der ersten gefundenen PageView markieren
525cdf0e10cSrcweir         MarkObj(pObj,pMarkPV);
526cdf0e10cSrcweir     }
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked) const529bb18ee55SArmin Le Grand BitmapEx SdrExchangeView::GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked) const
530cdf0e10cSrcweir {
531ddde725dSArmin Le Grand     BitmapEx aBmp;
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     if( AreObjectsMarked() )
534cdf0e10cSrcweir     {
535ddde725dSArmin Le Grand         if(1 == GetMarkedObjectCount())
536ddde725dSArmin Le Grand         {
537cdf0e10cSrcweir             if(bNoVDevIfOneBmpMarked)
538cdf0e10cSrcweir             {
539cdf0e10cSrcweir                 SdrObject*  pGrafObjTmp = GetMarkedObjectByIndex( 0 );
540cdf0e10cSrcweir                 SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() == 1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
541cdf0e10cSrcweir 
542cdf0e10cSrcweir                 if( pGrafObj && ( pGrafObj->GetGraphicType() == GRAPHIC_BITMAP ) )
543ddde725dSArmin Le Grand                 {
544ddde725dSArmin Le Grand                     aBmp = pGrafObj->GetTransformedGraphic().GetBitmapEx();
545ddde725dSArmin Le Grand                 }
546ddde725dSArmin Le Grand             }
547ddde725dSArmin Le Grand             else
548ddde725dSArmin Le Grand             {
549ddde725dSArmin Le Grand                 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(GetMarkedObjectByIndex(0));
550ddde725dSArmin Le Grand 
551ddde725dSArmin Le Grand                 if(pSdrGrafObj && pSdrGrafObj->isEmbeddedSvg())
552ddde725dSArmin Le Grand                 {
553ddde725dSArmin Le Grand                     aBmp = pSdrGrafObj->GetGraphic().getSvgData()->getReplacement();
554ddde725dSArmin Le Grand                 }
555ddde725dSArmin Le Grand             }
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir         if( !aBmp )
559cdf0e10cSrcweir         {
560958da553SArmin Le Grand             // choose conversion directly using primitives to bitmap to avoid
561958da553SArmin Le Grand             // rendering errors with tiled bitmap fills (these will be tiled in a
562958da553SArmin Le Grand             // in-between metafile, but tend to show 'gaps' since the target is *no*
563958da553SArmin Le Grand             // bitmap rendering)
564958da553SArmin Le Grand             ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
565958da553SArmin Le Grand             const sal_uInt32 nCount(aSdrObjects.size());
566cdf0e10cSrcweir 
567958da553SArmin Le Grand             if(nCount)
568958da553SArmin Le Grand             {
569958da553SArmin Le Grand                 // collect sub-primitives as group objects, thus no expensive append
570958da553SArmin Le Grand                 // to existing sequence is needed
571958da553SArmin Le Grand                 drawinglayer::primitive2d::Primitive2DSequence xPrimitives(nCount);
572958da553SArmin Le Grand 
573958da553SArmin Le Grand                 for(sal_uInt32 a(0); a < nCount; a++)
574958da553SArmin Le Grand                 {
5750cd7e32bSArmin Le Grand                     SdrObject* pCandidate = aSdrObjects[a];
5760cd7e32bSArmin Le Grand                     SdrGrafObj* pSdrGrafObj = dynamic_cast< SdrGrafObj* >(pCandidate);
5770cd7e32bSArmin Le Grand 
5780cd7e32bSArmin Le Grand                     if(pSdrGrafObj)
5790cd7e32bSArmin Le Grand                     {
58086e1cf34SPedro Giffuni                         // #122753# To ensure existence of graphic content, force swap in
5810cd7e32bSArmin Le Grand                         pSdrGrafObj->ForceSwapIn();
5820cd7e32bSArmin Le Grand                     }
5830cd7e32bSArmin Le Grand 
584958da553SArmin Le Grand                     xPrimitives[a] = new drawinglayer::primitive2d::GroupPrimitive2D(
5850cd7e32bSArmin Le Grand                         pCandidate->GetViewContact().getViewIndependentPrimitive2DSequence());
586958da553SArmin Le Grand                 }
587958da553SArmin Le Grand 
588958da553SArmin Le Grand                 // get logic range
589958da553SArmin Le Grand                 const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
590958da553SArmin Le Grand                 const basegfx::B2DRange aRange(
591958da553SArmin Le Grand                     drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(
592958da553SArmin Le Grand                         xPrimitives,
593958da553SArmin Le Grand                         aViewInformation2D));
594958da553SArmin Le Grand 
595958da553SArmin Le Grand                 if(!aRange.isEmpty())
596958da553SArmin Le Grand                 {
597958da553SArmin Le Grand                     // if we have geometry and it has a range, convert to BitmapEx using
598958da553SArmin Le Grand                     // common tooling
599958da553SArmin Le Grand                     aBmp = convertPrimitive2DSequenceToBitmapEx(
600958da553SArmin Le Grand                         xPrimitives,
601958da553SArmin Le Grand                         aRange,
602958da553SArmin Le Grand                         500000);
603958da553SArmin Le Grand                 }
604958da553SArmin Le Grand             }
605cdf0e10cSrcweir         }
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     return aBmp;
609cdf0e10cSrcweir }
610cdf0e10cSrcweir 
611cdf0e10cSrcweir // -----------------------------------------------------------------------------
612cdf0e10cSrcweir 
GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked) const613bb18ee55SArmin Le Grand GDIMetaFile SdrExchangeView::GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked) const
614cdf0e10cSrcweir {
615cdf0e10cSrcweir     GDIMetaFile aMtf;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     if( AreObjectsMarked() )
618cdf0e10cSrcweir     {
619cdf0e10cSrcweir         Rectangle   aBound( GetMarkedObjBoundRect() );
620cdf0e10cSrcweir         Size        aBoundSize( aBound.GetWidth(), aBound.GetHeight() );
621cdf0e10cSrcweir         MapMode     aMap( pMod->GetScaleUnit(), Point(), pMod->GetScaleFraction(), pMod->GetScaleFraction() );
622cdf0e10cSrcweir 
623cdf0e10cSrcweir         if( bNoVDevIfOneMtfMarked )
624cdf0e10cSrcweir         {
625cdf0e10cSrcweir             SdrObject*  pGrafObjTmp = GetMarkedObjectByIndex( 0 );
626cdf0e10cSrcweir             SdrGrafObj* pGrafObj = ( GetMarkedObjectCount() ==1 ) ? PTR_CAST( SdrGrafObj, pGrafObjTmp ) : NULL;
627cdf0e10cSrcweir 
628cdf0e10cSrcweir             if( pGrafObj )
629cdf0e10cSrcweir             {
630cdf0e10cSrcweir                 Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
631cdf0e10cSrcweir 
632*fe9b7f6aSmseidel                 // #119735# just use GetGDIMetaFile, it will create a buffered version of contained bitmap now automatically
633cdf0e10cSrcweir                 aMtf = aGraphic.GetGDIMetaFile();
634cdf0e10cSrcweir             }
635cdf0e10cSrcweir         }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir         if( !aMtf.GetActionCount() )
638cdf0e10cSrcweir         {
639cdf0e10cSrcweir             VirtualDevice aOut;
64047a7c0c1SArmin Le Grand             const Size aDummySize(2, 2);
641cdf0e10cSrcweir 
642cdf0e10cSrcweir             aOut.SetOutputSizePixel(aDummySize);
64347a7c0c1SArmin Le Grand             aOut.EnableOutput(false);
644cdf0e10cSrcweir             aOut.SetMapMode(aMap);
645cdf0e10cSrcweir             aMtf.Clear();
646cdf0e10cSrcweir             aMtf.Record(&aOut);
647cdf0e10cSrcweir 
648cdf0e10cSrcweir             DrawMarkedObj(aOut);
649cdf0e10cSrcweir 
650cdf0e10cSrcweir             aMtf.Stop();
651cdf0e10cSrcweir             aMtf.WindStart();
65247a7c0c1SArmin Le Grand 
65347a7c0c1SArmin Le Grand             // moving the result is more reliable then setting a relative MapMode at the VDev (used
65447a7c0c1SArmin Le Grand             // before), also see #i99268# in GetObjGraphic() below. Some draw actions at
65547a7c0c1SArmin Le Grand             // the OutDev are simply not handled correctly when a MapMode is set at the
656*fe9b7f6aSmseidel             // target device, e.g. MetaFloatTransparentAction. Even the Move for this action
65747a7c0c1SArmin Le Grand             // was missing the manipulation of the embedded Metafile
65847a7c0c1SArmin Le Grand             aMtf.Move(-aBound.Left(), -aBound.Top());
65947a7c0c1SArmin Le Grand 
660cdf0e10cSrcweir             aMtf.SetPrefMapMode( aMap );
661cdf0e10cSrcweir 
662*fe9b7f6aSmseidel             // removed PrefSize extension. It is principally wrong to set a reduced size at
66386e1cf34SPedro Giffuni             // the created MetaFile. The mentioned errors occur at output time since the integer
664cdf0e10cSrcweir             // MapModes from VCL lead to errors. It is now corrected in the VCLRenderer for
665cdf0e10cSrcweir             // primitives (and may later be done in breaking up a MetaFile to primitives)
666cdf0e10cSrcweir             aMtf.SetPrefSize(aBoundSize);
667cdf0e10cSrcweir         }
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir     return aMtf;
671cdf0e10cSrcweir }
672cdf0e10cSrcweir 
673cdf0e10cSrcweir // -----------------------------------------------------------------------------
674cdf0e10cSrcweir 
GetAllMarkedGraphic() const675cdf0e10cSrcweir Graphic SdrExchangeView::GetAllMarkedGraphic() const
676cdf0e10cSrcweir {
677cdf0e10cSrcweir     Graphic aRet;
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     if( AreObjectsMarked() )
680cdf0e10cSrcweir     {
681cdf0e10cSrcweir         if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
682cdf0e10cSrcweir             aRet = SdrExchangeView::GetObjGraphic( pMod, GetMarkedObjectByIndex( 0 ) );
683cdf0e10cSrcweir         else
684bb18ee55SArmin Le Grand             aRet = GetMarkedObjMetaFile(false);
685cdf0e10cSrcweir     }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir     return aRet;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir // -----------------------------------------------------------------------------
691cdf0e10cSrcweir 
GetObjGraphic(const SdrModel * pModel,const SdrObject * pObj)692cdf0e10cSrcweir Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir     Graphic aRet;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     if( pModel && pObj )
697cdf0e10cSrcweir     {
698cdf0e10cSrcweir         // try to get a graphic from the object first
699cdf0e10cSrcweir         const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
700cdf0e10cSrcweir         const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
701cdf0e10cSrcweir 
702cdf0e10cSrcweir         if(pSdrGrafObj)
703cdf0e10cSrcweir         {
704ddde725dSArmin Le Grand             if(pSdrGrafObj->isEmbeddedSvg())
705ddde725dSArmin Le Grand             {
706ddde725dSArmin Le Grand                 // get Metafile for Svg content
707ddde725dSArmin Le Grand                 aRet = pSdrGrafObj->getMetafileFromEmbeddedSvg();
708ddde725dSArmin Le Grand             }
709ddde725dSArmin Le Grand             else
710ddde725dSArmin Le Grand             {
711*fe9b7f6aSmseidel                 // #110981# Make behavior coherent with metafile
712cdf0e10cSrcweir                 // recording below (which of course also takes
713cdf0e10cSrcweir                 // view-transformed objects)
714cdf0e10cSrcweir                 aRet = pSdrGrafObj->GetTransformedGraphic();
715cdf0e10cSrcweir             }
716ddde725dSArmin Le Grand         }
717cdf0e10cSrcweir         else if(pSdrOle2Obj)
718cdf0e10cSrcweir         {
719cdf0e10cSrcweir             if ( pSdrOle2Obj->GetGraphic() )
720cdf0e10cSrcweir                 aRet = *pSdrOle2Obj->GetGraphic();
721cdf0e10cSrcweir         }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir         // if graphic could not be retrieved => go the hard way and create a MetaFile
724cdf0e10cSrcweir         if( ( GRAPHIC_NONE == aRet.GetType() ) || ( GRAPHIC_DEFAULT == aRet.GetType() ) )
725cdf0e10cSrcweir         {
726cdf0e10cSrcweir             VirtualDevice   aOut;
727cdf0e10cSrcweir             GDIMetaFile     aMtf;
728cdf0e10cSrcweir             const Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
729cdf0e10cSrcweir             const MapMode   aMap( pModel->GetScaleUnit(),
730cdf0e10cSrcweir                                   Point(),
731cdf0e10cSrcweir                                   pModel->GetScaleFraction(),
732cdf0e10cSrcweir                                   pModel->GetScaleFraction() );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir             aOut.EnableOutput( sal_False );
735cdf0e10cSrcweir             aOut.SetMapMode( aMap );
736cdf0e10cSrcweir             aMtf.Record( &aOut );
737cdf0e10cSrcweir             pObj->SingleObjectPainter( aOut ); // #110094#-17
738cdf0e10cSrcweir             aMtf.Stop();
739cdf0e10cSrcweir             aMtf.WindStart();
740cdf0e10cSrcweir 
741cdf0e10cSrcweir             // #i99268# replace the original offset from using XOutDev's SetOffset
742cdf0e10cSrcweir             // NOT (as tried with #i92760#) with another MapMode which gets recorded
74347a7c0c1SArmin Le Grand             // by the Metafile itself (what always leads to problems), but by
74447a7c0c1SArmin Le Grand             // moving the result directly
745cdf0e10cSrcweir             aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
746cdf0e10cSrcweir 
747cdf0e10cSrcweir             aMtf.SetPrefMapMode( aMap );
748cdf0e10cSrcweir             aMtf.SetPrefSize( aBoundRect.GetSize() );
749cdf0e10cSrcweir 
750cdf0e10cSrcweir             if( aMtf.GetActionCount() )
751cdf0e10cSrcweir                 aRet = aMtf;
752cdf0e10cSrcweir         }
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir     return aRet;
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir // -----------------------------------------------------------------------------
759cdf0e10cSrcweir 
GetMarkedObjects() const760958da553SArmin Le Grand ::std::vector< SdrObject* > SdrExchangeView::GetMarkedObjects() const
761cdf0e10cSrcweir {
762cdf0e10cSrcweir     SortMarkedObjects();
763958da553SArmin Le Grand     ::std::vector< SdrObject* > aRetval;
764cdf0e10cSrcweir 
765cdf0e10cSrcweir     ::std::vector< ::std::vector< SdrMark* > >  aObjVectors( 2 );
766cdf0e10cSrcweir     ::std::vector< SdrMark* >&                  rObjVector1 = aObjVectors[ 0 ];
767cdf0e10cSrcweir     ::std::vector< SdrMark* >&                  rObjVector2 = aObjVectors[ 1 ];
768cdf0e10cSrcweir     const SdrLayerAdmin&                        rLayerAdmin = pMod->GetLayerAdmin();
769cdf0e10cSrcweir     const sal_uInt32                            nControlLayerId = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName(), sal_False );
770cdf0e10cSrcweir     sal_uInt32                                  n, nCount;
771cdf0e10cSrcweir 
772cdf0e10cSrcweir     for( n = 0, nCount = GetMarkedObjectCount(); n < nCount; n++ )
773cdf0e10cSrcweir     {
774cdf0e10cSrcweir         SdrMark* pMark = GetSdrMarkByIndex( n );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir         // paint objects on control layer on top of all other objects
777cdf0e10cSrcweir         if( nControlLayerId == pMark->GetMarkedSdrObj()->GetLayer() )
778cdf0e10cSrcweir             rObjVector2.push_back( pMark );
779cdf0e10cSrcweir         else
780cdf0e10cSrcweir             rObjVector1.push_back( pMark );
781cdf0e10cSrcweir     }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir     for( n = 0, nCount = aObjVectors.size(); n < nCount; n++ )
784cdf0e10cSrcweir     {
785cdf0e10cSrcweir         ::std::vector< SdrMark* >& rObjVector = aObjVectors[ n ];
786cdf0e10cSrcweir 
787cdf0e10cSrcweir         for( sal_uInt32 i = 0; i < rObjVector.size(); i++ )
788cdf0e10cSrcweir         {
789cdf0e10cSrcweir             SdrMark*    pMark = rObjVector[ i ];
790958da553SArmin Le Grand             aRetval.push_back(pMark->GetMarkedSdrObj());
791cdf0e10cSrcweir         }
792cdf0e10cSrcweir     }
793958da553SArmin Le Grand 
794958da553SArmin Le Grand     return aRetval;
795958da553SArmin Le Grand }
796958da553SArmin Le Grand 
797958da553SArmin Le Grand // -----------------------------------------------------------------------------
798958da553SArmin Le Grand 
DrawMarkedObj(OutputDevice & rOut) const799958da553SArmin Le Grand void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const
800958da553SArmin Le Grand {
801958da553SArmin Le Grand     ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
802958da553SArmin Le Grand 
803958da553SArmin Le Grand     if(aSdrObjects.size())
804958da553SArmin Le Grand     {
805958da553SArmin Le Grand         sdr::contact::ObjectContactOfObjListPainter aPainter(rOut, aSdrObjects, aSdrObjects[0]->GetPage());
806958da553SArmin Le Grand         sdr::contact::DisplayInfo aDisplayInfo;
807958da553SArmin Le Grand 
808958da553SArmin Le Grand         // do processing
809958da553SArmin Le Grand         aPainter.ProcessDisplay(aDisplayInfo);
810958da553SArmin Le Grand     }
811cdf0e10cSrcweir }
812cdf0e10cSrcweir 
813cdf0e10cSrcweir // -----------------------------------------------------------------------------
814cdf0e10cSrcweir 
GetMarkedObjModel() const815cdf0e10cSrcweir SdrModel* SdrExchangeView::GetMarkedObjModel() const
816cdf0e10cSrcweir {
817*fe9b7f6aSmseidel     // Wenn das sortieren der MarkList mal stören sollte,
818*fe9b7f6aSmseidel     // werde ich sie mir wohl kopieren müssen.
819cdf0e10cSrcweir     SortMarkedObjects();
820cdf0e10cSrcweir     SdrModel* pNeuMod=pMod->AllocModel();
821cdf0e10cSrcweir     SdrPage* pNeuPag=pNeuMod->AllocPage(sal_False);
822cdf0e10cSrcweir     pNeuMod->InsertPage(pNeuPag);
823cdf0e10cSrcweir 
824cdf0e10cSrcweir     if( !mxSelectionController.is() || !mxSelectionController->GetMarkedObjModel( pNeuPag ) )
825cdf0e10cSrcweir     {
826958da553SArmin Le Grand         ::std::vector< SdrObject* > aSdrObjects(GetMarkedObjects());
827cdf0e10cSrcweir 
828cdf0e10cSrcweir         // #i13033#
829cdf0e10cSrcweir         // New mechanism to re-create the connections of cloned connectors
830cdf0e10cSrcweir         CloneList aCloneList;
831958da553SArmin Le Grand         sal_uInt32 nCloneErrCnt(0);
832cdf0e10cSrcweir 
833958da553SArmin Le Grand         for( sal_uInt32 i(0); i < aSdrObjects.size(); i++ )
834cdf0e10cSrcweir         {
835958da553SArmin Le Grand             const SdrObject*    pObj = aSdrObjects[i];
836*fe9b7f6aSmseidel             SdrObject*          pNewObj;
837cdf0e10cSrcweir 
838cdf0e10cSrcweir             if( pObj->ISA( SdrPageObj ) )
839cdf0e10cSrcweir             {
840cdf0e10cSrcweir                 // convert SdrPageObj's to a graphic representation, because
841cdf0e10cSrcweir                 // virtual connection to referenced page gets lost in new model
842*fe9b7f6aSmseidel                 pNewObj = new SdrGrafObj( GetObjGraphic( pMod, pObj ), pObj->GetLogicRect() );
843*fe9b7f6aSmseidel                 pNewObj->SetPage( pNeuPag );
844*fe9b7f6aSmseidel                 pNewObj->SetModel( pNeuMod );
845cdf0e10cSrcweir             }
846cdf0e10cSrcweir             else
847cdf0e10cSrcweir             {
848cdf0e10cSrcweir                 // #116235#
849*fe9b7f6aSmseidel                 // pNewObj = pObj->Clone( pNeuPag, pNeuMod );
850*fe9b7f6aSmseidel                 pNewObj = pObj->Clone();
851*fe9b7f6aSmseidel                 pNewObj->SetPage( pNeuPag );
852*fe9b7f6aSmseidel                 pNewObj->SetModel( pNeuMod );
853cdf0e10cSrcweir             }
854cdf0e10cSrcweir 
855*fe9b7f6aSmseidel             if( pNewObj )
856cdf0e10cSrcweir             {
857cdf0e10cSrcweir                 SdrInsertReason aReason(SDRREASON_VIEWCALL);
858*fe9b7f6aSmseidel                 pNeuPag->InsertObject(pNewObj,CONTAINER_APPEND,&aReason);
859cdf0e10cSrcweir 
860cdf0e10cSrcweir                 // #i13033#
861*fe9b7f6aSmseidel                 aCloneList.AddPair(pObj, pNewObj);
862cdf0e10cSrcweir             }
863cdf0e10cSrcweir             else
864cdf0e10cSrcweir                 nCloneErrCnt++;
865cdf0e10cSrcweir         }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir         // #i13033#
868cdf0e10cSrcweir         // New mechanism to re-create the connections of cloned connectors
869cdf0e10cSrcweir         aCloneList.CopyConnections();
870cdf0e10cSrcweir 
871cdf0e10cSrcweir         if(0L != nCloneErrCnt)
872cdf0e10cSrcweir         {
873cdf0e10cSrcweir #ifdef DBG_UTIL
874cdf0e10cSrcweir             ByteString aStr("SdrExchangeView::GetMarkedObjModel(): Fehler beim Clonen ");
875cdf0e10cSrcweir 
876cdf0e10cSrcweir             if(nCloneErrCnt == 1)
877cdf0e10cSrcweir             {
878cdf0e10cSrcweir                 aStr += "eines Zeichenobjekts.";
879cdf0e10cSrcweir             }
880cdf0e10cSrcweir             else
881cdf0e10cSrcweir             {
882cdf0e10cSrcweir                 aStr += "von ";
883cdf0e10cSrcweir                 aStr += ByteString::CreateFromInt32( nCloneErrCnt );
884cdf0e10cSrcweir                 aStr += " Zeichenobjekten.";
885cdf0e10cSrcweir             }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir             aStr += " Objektverbindungen werden nicht mitkopiert.";
888cdf0e10cSrcweir 
889cdf0e10cSrcweir             DBG_ERROR(aStr.GetBuffer());
890cdf0e10cSrcweir #endif
891cdf0e10cSrcweir         }
892cdf0e10cSrcweir     }
893cdf0e10cSrcweir     return pNeuMod;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir // -----------------------------------------------------------------------------
897cdf0e10cSrcweir 
Cut(sal_uIntPtr)898cdf0e10cSrcweir sal_Bool SdrExchangeView::Cut( sal_uIntPtr /*nFormat */)
899cdf0e10cSrcweir {
900cdf0e10cSrcweir     DBG_ERROR( "SdrExchangeView::Cut: Not supported anymore" );
901cdf0e10cSrcweir     return sal_False;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir // -----------------------------------------------------------------------------
905cdf0e10cSrcweir 
CutMarked(sal_uIntPtr)906cdf0e10cSrcweir void SdrExchangeView::CutMarked( sal_uIntPtr /*nFormat */)
907cdf0e10cSrcweir {
908cdf0e10cSrcweir     DBG_ERROR( "SdrExchangeView::CutMarked: Not supported anymore" );
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir // -----------------------------------------------------------------------------
912cdf0e10cSrcweir 
Yank(sal_uIntPtr)913cdf0e10cSrcweir sal_Bool SdrExchangeView::Yank(sal_uIntPtr /*nFormat*/)
914cdf0e10cSrcweir {
915cdf0e10cSrcweir     DBG_ERROR( "SdrExchangeView::Yank: Not supported anymore" );
916cdf0e10cSrcweir     return sal_False;
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir // -----------------------------------------------------------------------------
920cdf0e10cSrcweir 
YankMarked(sal_uIntPtr)921cdf0e10cSrcweir void SdrExchangeView::YankMarked(sal_uIntPtr /*nFormat*/)
922cdf0e10cSrcweir {
923cdf0e10cSrcweir     DBG_ERROR( "YankMarked: Not supported anymore" );
924cdf0e10cSrcweir }
925cdf0e10cSrcweir 
926cdf0e10cSrcweir // -----------------------------------------------------------------------------
927cdf0e10cSrcweir 
Paste(Window *,sal_uIntPtr)928cdf0e10cSrcweir sal_Bool SdrExchangeView::Paste(Window* /*pWin*/, sal_uIntPtr /*nFormat*/)
929cdf0e10cSrcweir {
930cdf0e10cSrcweir     DBG_ERROR( "SdrExchangeView::Paste: Not supported anymore" );
931cdf0e10cSrcweir     return sal_False;
932cdf0e10cSrcweir }
9339f63b866SArmin Le Grand 
934*fe9b7f6aSmseidel /* vim: set noet sw=4 ts=4: */
935