update credits
[LibreOffice.git] / svx / source / svdraw / svdglev.cxx
blob359b413b3c962a541d15bf3ace29cbc2dac69edc
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" // names taken from the resource
26 #include "svx/svdglob.hxx" // StringCache
27 #include <svx/svdpagv.hxx>
28 #include <svx/svdglue.hxx>
29 #include <svx/svdtrans.hxx>
30 #include <svx/svdobj.hxx>
32 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 void SdrGlueEditView::ImpClearVars()
38 SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
39 SdrPolyEditView(pModel1,pOut)
41 ImpClearVars();
44 SdrGlueEditView::~SdrGlueEditView()
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, sal_Bool bConst, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
52 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
53 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
54 SdrMark* pM=GetSdrMarkByIndex(nm);
55 SdrObject* pObj=pM->GetMarkedSdrObj();
56 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
57 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
58 if (nPtAnz!=0) {
59 SdrGluePointList* pGPL=NULL;
60 if (bConst) {
61 const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
62 pGPL=(SdrGluePointList*)pConstGPL;
63 } else {
64 pGPL=pObj->ForceGluePointList();
66 if (pGPL!=NULL)
68 if(!bConst && IsUndoEnabled() )
69 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
71 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
73 sal_uInt16 nPtId=*it;
74 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
75 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
77 SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
78 (*pDoFunc)(rGP,pObj,p1,p2,p3,p4,p5);
81 if (!bConst)
83 pObj->SetChanged();
84 pObj->BroadcastObjectChange();
89 if (!bConst && nMarkAnz!=0) pMod->SetChanged();
92 ////////////////////////////////////////////////////////////////////////////////////////////////////
94 static void ImpGetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*, const void*)
96 sal_uInt16& nRet=*(sal_uInt16*)pnRet;
97 sal_Bool& bFirst=*(sal_Bool*)pbFirst;
98 if (nRet!=FUZZY) {
99 sal_uInt16 nEsc=rGP.GetEscDir();
100 sal_Bool bOn=(nEsc & *(sal_uInt16*)pnThisEsc)!=0;
101 if (bFirst) { nRet=bOn; bFirst=sal_False; }
102 else if (nRet!=bOn) nRet=FUZZY;
106 TRISTATE SdrGlueEditView::IsMarkedGluePointsEscDir(sal_uInt16 nThisEsc) const
108 ForceUndirtyMrkPnt();
109 sal_Bool bFirst=sal_True;
110 sal_uInt16 nRet=0;
111 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetEscDir,sal_True,&bFirst,&nThisEsc,&nRet);
112 return (TRISTATE)nRet;
115 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*, const void*)
117 sal_uInt16 nEsc=rGP.GetEscDir();
118 if (*(sal_Bool*)pbOn) nEsc|=*(sal_uInt16*)pnThisEsc;
119 else nEsc&=~*(sal_uInt16*)pnThisEsc;
120 rGP.SetEscDir(nEsc);
123 void SdrGlueEditView::SetMarkedGluePointsEscDir(sal_uInt16 nThisEsc, sal_Bool bOn)
125 ForceUndirtyMrkPnt();
126 BegUndo(ImpGetResStr(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
127 ImpDoMarkedGluePoints(ImpSetEscDir,sal_False,&nThisEsc,&bOn);
128 EndUndo();
131 ////////////////////////////////////////////////////////////////////////////////////////////////////
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=*(sal_uInt16*)pnRet;
136 sal_Bool& bFirst=*(sal_Bool*)pbFirst;
137 if (nRet!=FUZZY) {
138 bool bOn=rGP.IsPercent();
139 if (bFirst) { nRet=bOn; bFirst=sal_False; }
140 else if ((nRet!=0)!=bOn) nRet=FUZZY;
144 TRISTATE SdrGlueEditView::IsMarkedGluePointsPercent() const
146 ForceUndirtyMrkPnt();
147 sal_Bool bFirst=sal_True;
148 sal_uInt16 nRet=sal_True;
149 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetPercent,sal_True,&bFirst,&nRet);
150 return (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(*(sal_Bool*)pbOn);
157 rGP.SetAbsolutePos(aPos,*pObj);
160 void SdrGlueEditView::SetMarkedGluePointsPercent(sal_Bool bOn)
162 ForceUndirtyMrkPnt();
163 BegUndo(ImpGetResStr(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
164 ImpDoMarkedGluePoints(ImpSetPercent,sal_False,&bOn);
165 EndUndo();
168 ////////////////////////////////////////////////////////////////////////////////////////////////////
170 static void ImpGetAlign(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet, const void*)
172 sal_uInt16& nRet=*(sal_uInt16*)pnRet;
173 sal_Bool& bFirst=*(sal_Bool*)pbFirst;
174 sal_Bool& bDontCare=*(sal_Bool*)pbDontCare;
175 sal_Bool bVert=*(sal_Bool*)pbVert;
176 if (!bDontCare) {
177 sal_uInt16 nAlg=0;
178 if (bVert) {
179 nAlg=rGP.GetVertAlign();
180 } else {
181 nAlg=rGP.GetHorzAlign();
183 if (bFirst) { nRet=nAlg; bFirst=sal_False; }
184 else if (nRet!=nAlg) {
185 if (bVert) {
186 nRet=SDRVERTALIGN_DONTCARE;
187 } else {
188 nRet=SDRHORZALIGN_DONTCARE;
190 bDontCare=sal_True;
195 sal_uInt16 SdrGlueEditView::GetMarkedGluePointsAlign(sal_Bool bVert) const
197 ForceUndirtyMrkPnt();
198 sal_Bool bFirst=sal_True;
199 sal_Bool bDontCare=sal_False;
200 sal_uInt16 nRet=0;
201 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetAlign,sal_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 (*(sal_Bool*)pbVert) { // bVert?
209 rGP.SetVertAlign(*(sal_uInt16*)pnAlign);
210 } else {
211 rGP.SetHorzAlign(*(sal_uInt16*)pnAlign);
213 rGP.SetAbsolutePos(aPos,*pObj);
216 void SdrGlueEditView::SetMarkedGluePointsAlign(sal_Bool bVert, sal_uInt16 nAlign)
218 ForceUndirtyMrkPnt();
219 BegUndo(ImpGetResStr(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
220 ImpDoMarkedGluePoints(ImpSetAlign,sal_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 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
233 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
235 SdrMark* pM=GetSdrMarkByIndex(nm);
236 SdrObject* pObj=pM->GetMarkedSdrObj();
237 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
238 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
239 if (nPtAnz!=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 (nMarkAnz!=0)
265 pMod->SetChanged();
268 ////////////////////////////////////////////////////////////////////////////////////////////////////
270 void SdrGlueEditView::ImpCopyMarkedGluePoints()
272 const bool bUndo = IsUndoEnabled();
274 if( bUndo )
275 BegUndo();
277 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
278 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
280 SdrMark* pM=GetSdrMarkByIndex(nm);
281 SdrObject* pObj=pM->GetMarkedSdrObj();
282 SdrUShortCont* pPts=pM->GetMarkedGluePoints();
283 SdrGluePointList* pGPL=pObj->ForceGluePointList();
284 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
285 if (nPtAnz!=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 (nMarkAnz!=0)
315 pMod->SetChanged();
318 ////////////////////////////////////////////////////////////////////////////////////////////////////
320 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
322 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
323 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
324 SdrMark* pM=GetSdrMarkByIndex(nm);
325 SdrObject* pObj=pM->GetMarkedSdrObj();
326 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
327 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
328 if (nPtAnz!=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 (nMarkAnz!=0) pMod->SetChanged();
354 ////////////////////////////////////////////////////////////////////////////////////////////////////
356 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
358 rPt.X()+=((const Size*)p1)->Width();
359 rPt.Y()+=((const Size*)p1)->Height();
362 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
364 ForceUndirtyMrkPnt();
365 XubString 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();
374 ////////////////////////////////////////////////////////////////////////////////////////////////////
376 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/, const void* /*p5*/)
378 ResizePoint(rPt,*(const Point*)p1,*(const Fraction*)p2,*(const Fraction*)p3);
381 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
383 ForceUndirtyMrkPnt();
384 XubString 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();
393 ////////////////////////////////////////////////////////////////////////////////////////////////////
395 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4, const void* /*p5*/)
397 RotatePoint(rPt,*(const Point*)p1,*(const double*)p3,*(const double*)p4);
400 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nWink, bool bCopy)
402 ForceUndirtyMrkPnt();
403 XubString 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(nWink*nPi180);
408 double nCos=cos(nWink*nPi180);
409 ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nWink,&nSin,&nCos);
410 EndUndo();
411 AdjustMarkHdl();
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */