Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / svdraw / svdglev.cxx
blob0ea7c0b2c98561c9a99984620a771659241e2f71
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 void SdrGlueEditView::ImpClearVars()
38 SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
39 SdrPolyEditView(pModel1,pOut)
41 ImpClearVars();
44 SdrGlueEditView::~SdrGlueEditView()
50 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, 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();
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 bool& bFirst=*(bool*)pbFirst;
98 if (nRet!=FUZZY) {
99 sal_uInt16 nEsc = rGP.GetEscDir();
100 bool bOn = (nEsc & *(sal_uInt16*)pnThisEsc) != 0;
101 if (bFirst) {
102 nRet = bOn ? 1 : 0;
103 bFirst = false;
105 else if (nRet != (bOn ? 1 : 0)) nRet=FUZZY;
109 TRISTATE SdrGlueEditView::IsMarkedGluePointsEscDir(sal_uInt16 nThisEsc) const
111 ForceUndirtyMrkPnt();
112 bool bFirst=true;
113 sal_uInt16 nRet=0;
114 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
115 return (TRISTATE)nRet;
118 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*, const void*)
120 sal_uInt16 nEsc=rGP.GetEscDir();
121 if (*(bool*)pbOn) nEsc|=*(sal_uInt16*)pnThisEsc;
122 else nEsc&=~*(sal_uInt16*)pnThisEsc;
123 rGP.SetEscDir(nEsc);
126 void SdrGlueEditView::SetMarkedGluePointsEscDir(sal_uInt16 nThisEsc, bool bOn)
128 ForceUndirtyMrkPnt();
129 BegUndo(ImpGetResStr(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
130 ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
131 EndUndo();
136 static void ImpGetPercent(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*, const void*)
138 sal_uInt16& nRet=*(sal_uInt16*)pnRet;
139 bool& bFirst=*(bool*)pbFirst;
140 if (nRet!=FUZZY) {
141 bool bOn=rGP.IsPercent();
142 if (bFirst) { nRet=sal_uInt16(bOn); bFirst=false; }
143 else if ((nRet!=0)!=bOn) nRet=FUZZY;
147 TRISTATE SdrGlueEditView::IsMarkedGluePointsPercent() const
149 ForceUndirtyMrkPnt();
150 bool bFirst=true;
151 sal_uInt16 nRet=sal_True;
152 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
153 return (TRISTATE)nRet;
156 static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*, const void*)
158 Point aPos(rGP.GetAbsolutePos(*pObj));
159 rGP.SetPercent(*(bool*)pbOn);
160 rGP.SetAbsolutePos(aPos,*pObj);
163 void SdrGlueEditView::SetMarkedGluePointsPercent(bool bOn)
165 ForceUndirtyMrkPnt();
166 BegUndo(ImpGetResStr(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
167 ImpDoMarkedGluePoints(ImpSetPercent,false,&bOn);
168 EndUndo();
173 static void ImpGetAlign(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet, const void*)
175 sal_uInt16& nRet=*(sal_uInt16*)pnRet;
176 bool& bFirst=*(bool*)pbFirst;
177 bool& bDontCare=*(bool*)pbDontCare;
178 bool bVert=*(bool*)pbVert;
179 if (!bDontCare) {
180 sal_uInt16 nAlg=0;
181 if (bVert) {
182 nAlg=rGP.GetVertAlign();
183 } else {
184 nAlg=rGP.GetHorzAlign();
186 if (bFirst) { nRet=nAlg; bFirst=false; }
187 else if (nRet!=nAlg) {
188 if (bVert) {
189 nRet=SDRVERTALIGN_DONTCARE;
190 } else {
191 nRet=SDRHORZALIGN_DONTCARE;
193 bDontCare=true;
198 sal_uInt16 SdrGlueEditView::GetMarkedGluePointsAlign(bool bVert) const
200 ForceUndirtyMrkPnt();
201 bool bFirst=true;
202 bool bDontCare=false;
203 sal_uInt16 nRet=0;
204 ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
205 return nRet;
208 static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*, const void*)
210 Point aPos(rGP.GetAbsolutePos(*pObj));
211 if (*(bool*)pbVert) { // bVert?
212 rGP.SetVertAlign(*(sal_uInt16*)pnAlign);
213 } else {
214 rGP.SetHorzAlign(*(sal_uInt16*)pnAlign);
216 rGP.SetAbsolutePos(aPos,*pObj);
219 void SdrGlueEditView::SetMarkedGluePointsAlign(bool bVert, sal_uInt16 nAlign)
221 ForceUndirtyMrkPnt();
222 BegUndo(ImpGetResStr(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
223 ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
224 EndUndo();
227 void SdrGlueEditView::DeleteMarkedGluePoints()
229 BrkAction();
230 ForceUndirtyMrkPnt();
231 const bool bUndo = IsUndoEnabled();
232 if( bUndo )
233 BegUndo(ImpGetResStr(STR_EditDelete),GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_DELETE);
235 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
236 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
238 SdrMark* pM=GetSdrMarkByIndex(nm);
239 SdrObject* pObj=pM->GetMarkedSdrObj();
240 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
241 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
242 if (nPtAnz!=0)
244 SdrGluePointList* pGPL=pObj->ForceGluePointList();
245 if (pGPL!=NULL)
247 if( bUndo )
248 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
250 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
252 sal_uInt16 nPtId=*it;
253 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
254 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
256 pGPL->Delete(nGlueIdx);
259 pObj->SetChanged();
260 pObj->BroadcastObjectChange();
264 if( bUndo )
265 EndUndo();
266 UnmarkAllGluePoints();
267 if (nMarkAnz!=0)
268 pMod->SetChanged();
273 void SdrGlueEditView::ImpCopyMarkedGluePoints()
275 const bool bUndo = IsUndoEnabled();
277 if( bUndo )
278 BegUndo();
280 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
281 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
283 SdrMark* pM=GetSdrMarkByIndex(nm);
284 SdrObject* pObj=pM->GetMarkedSdrObj();
285 SdrUShortCont* pPts=pM->GetMarkedGluePoints();
286 SdrGluePointList* pGPL=pObj->ForceGluePointList();
287 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
288 if (nPtAnz!=0 && pGPL!=NULL)
290 if( bUndo )
291 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
293 SdrUShortCont aIdsToErase;
294 SdrUShortCont aIdsToInsert;
295 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
297 sal_uInt16 nPtId=*it;
298 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
299 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
301 SdrGluePoint aNewGP((*pGPL)[nGlueIdx]); // clone GluePoint
302 sal_uInt16 nNewIdx=pGPL->Insert(aNewGP); // and insert it
303 sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId(); // retrieve ID of new GluePoints
304 aIdsToErase.insert(nPtId); // select it (instead of the old one)
305 aIdsToInsert.insert(nNewId);
308 for(SdrUShortCont::const_iterator it = aIdsToErase.begin(); it != aIdsToErase.end(); ++it)
309 pPts->erase(*it);
310 pPts->insert(aIdsToInsert.begin(), aIdsToInsert.end());
314 if( bUndo )
315 EndUndo();
317 if (nMarkAnz!=0)
318 pMod->SetChanged();
323 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
325 sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
326 for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
327 SdrMark* pM=GetSdrMarkByIndex(nm);
328 SdrObject* pObj=pM->GetMarkedSdrObj();
329 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
330 sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
331 if (nPtAnz!=0) {
332 SdrGluePointList* pGPL=pObj->ForceGluePointList();
333 if (pGPL!=NULL)
335 if( IsUndoEnabled() )
336 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
338 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
340 sal_uInt16 nPtId=*it;
341 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
342 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
343 SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
344 Point aPos(rGP.GetAbsolutePos(*pObj));
345 (*pTrFunc)(aPos,p1,p2,p3,p4,p5);
346 rGP.SetAbsolutePos(aPos,*pObj);
349 pObj->SetChanged();
350 pObj->BroadcastObjectChange();
354 if (nMarkAnz!=0) pMod->SetChanged();
359 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
361 rPt.X()+=((const Size*)p1)->Width();
362 rPt.Y()+=((const Size*)p1)->Height();
365 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
367 ForceUndirtyMrkPnt();
368 OUString aStr(ImpGetResStr(STR_EditMove));
369 if (bCopy) aStr += ImpGetResStr(STR_EditWithCopy);
370 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_MOVE);
371 if (bCopy) ImpCopyMarkedGluePoints();
372 ImpTransformMarkedGluePoints(ImpMove,&rSiz);
373 EndUndo();
374 AdjustMarkHdl();
379 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/, const void* /*p5*/)
381 ResizePoint(rPt,*(const Point*)p1,*(const Fraction*)p2,*(const Fraction*)p3);
384 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
386 ForceUndirtyMrkPnt();
387 OUString aStr(ImpGetResStr(STR_EditResize));
388 if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
389 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_RESIZE);
390 if (bCopy) ImpCopyMarkedGluePoints();
391 ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
392 EndUndo();
393 AdjustMarkHdl();
398 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4, const void* /*p5*/)
400 RotatePoint(rPt,*(const Point*)p1,*(const double*)p3,*(const double*)p4);
403 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nWink, bool bCopy)
405 ForceUndirtyMrkPnt();
406 OUString aStr(ImpGetResStr(STR_EditRotate));
407 if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
408 BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_ROTATE);
409 if (bCopy) ImpCopyMarkedGluePoints();
410 double nSin=sin(nWink*nPi180);
411 double nCos=cos(nWink*nPi180);
412 ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nWink,&nSin,&nCos);
413 EndUndo();
414 AdjustMarkHdl();
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */