bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / svdraw / svdglev.cxx
blob7f2faba3fa0e423ab727b9f19cd21e5d6e9b38eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/svdglev.hxx>
22 #include <math.h>
24 #include <svx/svdundo.hxx>
25 #include "svx/svdstr.hrc"
26 #include "svdglob.hxx"
27 #include <svx/svdpagv.hxx>
28 #include <svx/svdglue.hxx>
29 #include <svx/svdtrans.hxx>
30 #include <svx/svdobj.hxx>
34 SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
35 SdrPolyEditView(pModel1,pOut)
39 SdrGlueEditView::~SdrGlueEditView()
45 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
47 const size_t nMarkCount=GetMarkedObjectCount();
48 for (size_t nm=0; nm<nMarkCount; ++nm) {
49 SdrMark* pM=GetSdrMarkByIndex(nm);
50 SdrObject* pObj=pM->GetMarkedSdrObj();
51 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
52 sal_uIntPtr nPointCount=pPts==NULL ? 0 : pPts->size();
53 if (nPointCount!=0) {
54 SdrGluePointList* pGPL=NULL;
55 if (bConst) {
56 const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
57 pGPL=const_cast<SdrGluePointList*>(pConstGPL);
58 } else {
59 pGPL=pObj->ForceGluePointList();
61 if (pGPL!=NULL)
63 if(!bConst && IsUndoEnabled() )
64 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
66 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
68 sal_uInt16 nPtId=*it;
69 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
70 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
72 SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
73 (*pDoFunc)(rGP,pObj,p1,p2,p3,p4,p5);
76 if (!bConst)
78 pObj->SetChanged();
79 pObj->BroadcastObjectChange();
84 if (!bConst && nMarkCount!=0) pMod->SetChanged();
89 static void ImpGetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*, const void*)
91 sal_uInt16& nRet=*const_cast<sal_uInt16 *>(static_cast<sal_uInt16 const *>(pnRet));
92 if (nRet!=FUZZY) {
93 SdrEscapeDirection nEsc = rGP.GetEscDir();
94 bool bOn = bool(nEsc & *static_cast<SdrEscapeDirection const *>(pnThisEsc));
95 bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
96 if (bFirst) {
97 nRet = bOn ? 1 : 0;
98 bFirst = false;
100 else if (nRet != (bOn ? 1 : 0)) nRet=FUZZY;
104 SDR_TRISTATE SdrGlueEditView::IsMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc) const
106 ForceUndirtyMrkPnt();
107 bool bFirst=true;
108 sal_uInt16 nRet=0;
109 const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
110 return (SDR_TRISTATE)nRet;
113 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*, const void*)
115 SdrEscapeDirection nEsc=rGP.GetEscDir();
116 if (*static_cast<bool const *>(pbOn))
117 nEsc |= *static_cast<SdrEscapeDirection const *>(pnThisEsc);
118 else
119 nEsc &= ~*static_cast<SdrEscapeDirection const *>(pnThisEsc);
120 rGP.SetEscDir(nEsc);
123 void SdrGlueEditView::SetMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc, bool bOn)
125 ForceUndirtyMrkPnt();
126 BegUndo(ImpGetResStr(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
127 ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
128 EndUndo();
133 static void ImpGetPercent(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*, const void*)
135 sal_uInt16& nRet=*const_cast<sal_uInt16 *>(static_cast<sal_uInt16 const *>(pnRet));
136 if (nRet!=FUZZY) {
137 bool bOn=rGP.IsPercent();
138 bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
139 if (bFirst) { nRet=sal_uInt16(bOn); bFirst=false; }
140 else if ((nRet!=0)!=bOn) nRet=FUZZY;
144 SDR_TRISTATE SdrGlueEditView::IsMarkedGluePointsPercent() const
146 ForceUndirtyMrkPnt();
147 bool bFirst=true;
148 sal_uInt16 nRet=sal_uInt16(true);
149 const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
150 return (SDR_TRISTATE)nRet;
153 static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*, const void*)
155 Point aPos(rGP.GetAbsolutePos(*pObj));
156 rGP.SetPercent(*static_cast<bool const *>(pbOn));
157 rGP.SetAbsolutePos(aPos,*pObj);
160 void SdrGlueEditView::SetMarkedGluePointsPercent(bool bOn)
162 ForceUndirtyMrkPnt();
163 BegUndo(ImpGetResStr(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
164 ImpDoMarkedGluePoints(ImpSetPercent,false,&bOn);
165 EndUndo();
170 static void ImpGetAlign(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet, const void*)
172 SdrAlign& nRet=*const_cast<SdrAlign *>(static_cast<SdrAlign const *>(pnRet));
173 bool& bDontCare=*const_cast<bool *>(static_cast<bool const *>(pbDontCare));
174 bool bVert=*static_cast<bool const *>(pbVert);
175 if (!bDontCare) {
176 SdrAlign nAlg=SdrAlign::NONE;
177 if (bVert) {
178 nAlg=rGP.GetVertAlign();
179 } else {
180 nAlg=rGP.GetHorzAlign();
182 bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
183 if (bFirst) { nRet=nAlg; bFirst=false; }
184 else if (nRet!=nAlg) {
185 if (bVert) {
186 nRet=SdrAlign::VERT_DONTCARE;
187 } else {
188 nRet=SdrAlign::HORZ_DONTCARE;
190 bDontCare=true;
195 SdrAlign SdrGlueEditView::GetMarkedGluePointsAlign(bool bVert) const
197 ForceUndirtyMrkPnt();
198 bool bFirst=true;
199 bool bDontCare=false;
200 SdrAlign nRet=SdrAlign::NONE;
201 const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
202 return nRet;
205 static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*, const void*)
207 Point aPos(rGP.GetAbsolutePos(*pObj));
208 if (*static_cast<bool const *>(pbVert)) { // bVert?
209 rGP.SetVertAlign(*static_cast<SdrAlign const *>(pnAlign));
210 } else {
211 rGP.SetHorzAlign(*static_cast<SdrAlign const *>(pnAlign));
213 rGP.SetAbsolutePos(aPos,*pObj);
216 void SdrGlueEditView::SetMarkedGluePointsAlign(bool bVert, SdrAlign nAlign)
218 ForceUndirtyMrkPnt();
219 BegUndo(ImpGetResStr(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
220 ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
221 EndUndo();
224 void SdrGlueEditView::DeleteMarkedGluePoints()
226 BrkAction();
227 ForceUndirtyMrkPnt();
228 const bool bUndo = IsUndoEnabled();
229 if( bUndo )
230 BegUndo(ImpGetResStr(STR_EditDelete),GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_DELETE);
232 const size_t nMarkCount=GetMarkedObjectCount();
233 for (size_t nm=0; nm<nMarkCount; ++nm)
235 SdrMark* pM=GetSdrMarkByIndex(nm);
236 SdrObject* pObj=pM->GetMarkedSdrObj();
237 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
238 sal_uIntPtr nPointCount=pPts==NULL ? 0 : pPts->size();
239 if (nPointCount!=0)
241 SdrGluePointList* pGPL=pObj->ForceGluePointList();
242 if (pGPL!=NULL)
244 if( bUndo )
245 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
247 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
249 sal_uInt16 nPtId=*it;
250 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
251 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
253 pGPL->Delete(nGlueIdx);
256 pObj->SetChanged();
257 pObj->BroadcastObjectChange();
261 if( bUndo )
262 EndUndo();
263 UnmarkAllGluePoints();
264 if (nMarkCount!=0)
265 pMod->SetChanged();
270 void SdrGlueEditView::ImpCopyMarkedGluePoints()
272 const bool bUndo = IsUndoEnabled();
274 if( bUndo )
275 BegUndo();
277 const size_t nMarkCount=GetMarkedObjectCount();
278 for (size_t nm=0; nm<nMarkCount; ++nm)
280 SdrMark* pM=GetSdrMarkByIndex(nm);
281 SdrObject* pObj=pM->GetMarkedSdrObj();
282 SdrUShortCont* pPts=pM->GetMarkedGluePoints();
283 SdrGluePointList* pGPL=pObj->ForceGluePointList();
284 sal_uIntPtr nPointCount=pPts==NULL ? 0 : pPts->size();
285 if (nPointCount!=0 && pGPL!=NULL)
287 if( bUndo )
288 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
290 SdrUShortCont aIdsToErase;
291 SdrUShortCont aIdsToInsert;
292 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
294 sal_uInt16 nPtId=*it;
295 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
296 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
298 SdrGluePoint aNewGP((*pGPL)[nGlueIdx]); // clone GluePoint
299 sal_uInt16 nNewIdx=pGPL->Insert(aNewGP); // and insert it
300 sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId(); // retrieve ID of new GluePoints
301 aIdsToErase.insert(nPtId); // select it (instead of the old one)
302 aIdsToInsert.insert(nNewId);
305 for(SdrUShortCont::const_iterator it = aIdsToErase.begin(); it != aIdsToErase.end(); ++it)
306 pPts->erase(*it);
307 pPts->insert(aIdsToInsert.begin(), aIdsToInsert.end());
311 if( bUndo )
312 EndUndo();
314 if (nMarkCount!=0)
315 pMod->SetChanged();
320 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
322 const size_t nMarkCount=GetMarkedObjectCount();
323 for (size_t nm=0; nm<nMarkCount; ++nm) {
324 SdrMark* pM=GetSdrMarkByIndex(nm);
325 SdrObject* pObj=pM->GetMarkedSdrObj();
326 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
327 sal_uIntPtr nPointCount=pPts==NULL ? 0 : pPts->size();
328 if (nPointCount!=0) {
329 SdrGluePointList* pGPL=pObj->ForceGluePointList();
330 if (pGPL!=NULL)
332 if( IsUndoEnabled() )
333 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
335 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
337 sal_uInt16 nPtId=*it;
338 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
339 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
340 SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
341 Point aPos(rGP.GetAbsolutePos(*pObj));
342 (*pTrFunc)(aPos,p1,p2,p3,p4,p5);
343 rGP.SetAbsolutePos(aPos,*pObj);
346 pObj->SetChanged();
347 pObj->BroadcastObjectChange();
351 if (nMarkCount!=0) pMod->SetChanged();
356 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
358 rPt.X()+=static_cast<const Size*>(p1)->Width();
359 rPt.Y()+=static_cast<const Size*>(p1)->Height();
362 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
364 ForceUndirtyMrkPnt();
365 OUString aStr(ImpGetResStr(STR_EditMove));
366 if (bCopy) aStr += ImpGetResStr(STR_EditWithCopy);
367 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_MOVE);
368 if (bCopy) ImpCopyMarkedGluePoints();
369 ImpTransformMarkedGluePoints(ImpMove,&rSiz);
370 EndUndo();
371 AdjustMarkHdl();
376 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/, const void* /*p5*/)
378 ResizePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const Fraction*>(p2),*static_cast<const Fraction*>(p3));
381 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
383 ForceUndirtyMrkPnt();
384 OUString aStr(ImpGetResStr(STR_EditResize));
385 if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
386 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_RESIZE);
387 if (bCopy) ImpCopyMarkedGluePoints();
388 ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
389 EndUndo();
390 AdjustMarkHdl();
395 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4, const void* /*p5*/)
397 RotatePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p3),*static_cast<const double*>(p4));
400 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nAngle, bool bCopy)
402 ForceUndirtyMrkPnt();
403 OUString aStr(ImpGetResStr(STR_EditRotate));
404 if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
405 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_ROTATE);
406 if (bCopy) ImpCopyMarkedGluePoints();
407 double nSin=sin(nAngle*nPi180);
408 double nCos=cos(nAngle*nPi180);
409 ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
410 EndUndo();
411 AdjustMarkHdl();
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */