LibreOffice Module svx (master)  1
svdglev.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include <svx/svdglev.hxx>
22 #include <math.h>
23 
24 #include <svx/svdundo.hxx>
25 #include <svx/strings.hrc>
26 #include <svx/dialmgr.hxx>
27 #include <svx/svdglue.hxx>
28 #include <svx/svdtrans.hxx>
29 #include <svx/svdobj.hxx>
30 
32  SdrModel& rSdrModel,
33  OutputDevice* pOut)
34 : SdrPolyEditView(rSdrModel, pOut)
35 {
36 }
37 
39 {
40 }
41 
42 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4)
43 {
44  const size_t nMarkCount=GetMarkedObjectCount();
45  for (size_t nm=0; nm<nMarkCount; ++nm) {
46  SdrMark* pM=GetSdrMarkByIndex(nm);
47  SdrObject* pObj=pM->GetMarkedSdrObj();
48  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
49  if (!rPts.empty())
50  {
51  SdrGluePointList* pGPL=nullptr;
52  if (bConst) {
53  const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
54  pGPL=const_cast<SdrGluePointList*>(pConstGPL);
55  } else {
56  pGPL=pObj->ForceGluePointList();
57  }
58  if (pGPL!=nullptr)
59  {
60  if(!bConst && IsUndoEnabled() )
61  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
62 
63  for(sal_uInt16 nPtId : rPts)
64  {
65  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
66  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
67  {
68  SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
69  (*pDoFunc)(rGP,pObj,p1,p2,p3,p4);
70  }
71  }
72  if (!bConst)
73  {
74  pObj->SetChanged();
75  pObj->BroadcastObjectChange();
76  }
77  }
78  }
79  }
80  if (!bConst && nMarkCount!=0) mpModel->SetChanged();
81 }
82 
83 
84 static void ImpGetEscDir(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*)
85 {
86  TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
87  if (nRet!=TRISTATE_INDET) {
88  SdrEscapeDirection nEsc = rGP.GetEscDir();
89  bool bOn = bool(nEsc & *static_cast<SdrEscapeDirection const *>(pnThisEsc));
90  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
91  if (bFirst) {
92  nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
93  bFirst = false;
94  }
95  else if (nRet != (bOn ? TRISTATE_TRUE : TRISTATE_FALSE)) nRet=TRISTATE_INDET;
96  }
97 }
98 
100 {
102  bool bFirst=true;
104  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
105  return nRet;
106 }
107 
108 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*)
109 {
110  SdrEscapeDirection nEsc=rGP.GetEscDir();
111  if (*static_cast<bool const *>(pbOn))
112  nEsc |= *static_cast<SdrEscapeDirection const *>(pnThisEsc);
113  else
114  nEsc &= ~*static_cast<SdrEscapeDirection const *>(pnThisEsc);
115  rGP.SetEscDir(nEsc);
116 }
117 
119 {
121  BegUndo(SvxResId(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
122  ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
123  EndUndo();
124 }
125 
126 
127 static void ImpGetPercent(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*)
128 {
129  TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
130  if (nRet!=TRISTATE_INDET) {
131  bool bOn=rGP.IsPercent();
132  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
133  if (bFirst) {
134  nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
135  bFirst = false;
136  }
137  else if ((nRet!=TRISTATE_FALSE)!=bOn)
138  nRet=TRISTATE_INDET;
139  }
140 }
141 
143 {
145  bool bFirst=true;
146  TriState nRet = TRISTATE_TRUE;
147  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
148  return nRet;
149 }
150 
151 static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*)
152 {
153  Point aPos(rGP.GetAbsolutePos(*pObj));
154  rGP.SetPercent(*static_cast<bool const *>(pbOn));
155  rGP.SetAbsolutePos(aPos,*pObj);
156 }
157 
159 {
161  BegUndo(SvxResId(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
163  EndUndo();
164 }
165 
166 
167 static void ImpGetAlign(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet)
168 {
169  SdrAlign& nRet=*const_cast<SdrAlign *>(static_cast<SdrAlign const *>(pnRet));
170  bool& bDontCare=*const_cast<bool *>(static_cast<bool const *>(pbDontCare));
171  bool bVert=*static_cast<bool const *>(pbVert);
172  if (!bDontCare) {
174  if (bVert) {
175  nAlg=rGP.GetVertAlign();
176  } else {
177  nAlg=rGP.GetHorzAlign();
178  }
179  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
180  if (bFirst) { nRet=nAlg; bFirst=false; }
181  else if (nRet!=nAlg) {
182  if (bVert) {
184  } else {
186  }
187  bDontCare=true;
188  }
189  }
190 }
191 
193 {
195  bool bFirst=true;
196  bool bDontCare=false;
198  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
199  return nRet;
200 }
201 
202 static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*)
203 {
204  Point aPos(rGP.GetAbsolutePos(*pObj));
205  if (*static_cast<bool const *>(pbVert)) { // bVert?
206  rGP.SetVertAlign(*static_cast<SdrAlign const *>(pnAlign));
207  } else {
208  rGP.SetHorzAlign(*static_cast<SdrAlign const *>(pnAlign));
209  }
210  rGP.SetAbsolutePos(aPos,*pObj);
211 }
212 
214 {
216  BegUndo(SvxResId(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
217  ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
218  EndUndo();
219 }
220 
222 {
223  BrkAction();
225  const bool bUndo = IsUndoEnabled();
226  if( bUndo )
228 
229  const size_t nMarkCount=GetMarkedObjectCount();
230  for (size_t nm=0; nm<nMarkCount; ++nm)
231  {
232  SdrMark* pM=GetSdrMarkByIndex(nm);
233  SdrObject* pObj=pM->GetMarkedSdrObj();
234  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
235  if (!rPts.empty())
236  {
237  SdrGluePointList* pGPL=pObj->ForceGluePointList();
238  if (pGPL!=nullptr)
239  {
240  if( bUndo )
241  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
242 
243  for(sal_uInt16 nPtId : rPts)
244  {
245  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
246  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
247  {
248  pGPL->Delete(nGlueIdx);
249  }
250  }
251  pObj->SetChanged();
252  pObj->BroadcastObjectChange();
253  }
254  }
255  }
256  if( bUndo )
257  EndUndo();
259  if (nMarkCount!=0)
260  mpModel->SetChanged();
261 }
262 
263 
265 {
266  const bool bUndo = IsUndoEnabled();
267 
268  if( bUndo )
269  BegUndo();
270 
271  const size_t nMarkCount=GetMarkedObjectCount();
272  for (size_t nm=0; nm<nMarkCount; ++nm)
273  {
274  SdrMark* pM=GetSdrMarkByIndex(nm);
275  SdrObject* pObj=pM->GetMarkedSdrObj();
276  SdrUShortCont& rPts = pM->GetMarkedGluePoints();
277  SdrGluePointList* pGPL=pObj->ForceGluePointList();
278  if (!rPts.empty() && pGPL!=nullptr)
279  {
280  if( bUndo )
281  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
282 
283  SdrUShortCont aIdsToErase;
284  SdrUShortCont aIdsToInsert;
285  for(sal_uInt16 nPtId : rPts)
286  {
287  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
288  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
289  {
290  SdrGluePoint aNewGP((*pGPL)[nGlueIdx]); // clone GluePoint
291  sal_uInt16 nNewIdx=pGPL->Insert(aNewGP); // and insert it
292  sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId(); // retrieve ID of new GluePoints
293  aIdsToErase.insert(nPtId); // select it (instead of the old one)
294  aIdsToInsert.insert(nNewId);
295  }
296  }
297  for(const auto& rId : aIdsToErase)
298  rPts.erase(rId);
299  rPts.insert(aIdsToInsert.begin(), aIdsToInsert.end());
300  }
301  }
302  if( bUndo )
303  EndUndo();
304 
305  if (nMarkCount!=0)
306  mpModel->SetChanged();
307 }
308 
309 
310 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4)
311 {
312  const size_t nMarkCount=GetMarkedObjectCount();
313  for (size_t nm=0; nm<nMarkCount; ++nm) {
314  SdrMark* pM=GetSdrMarkByIndex(nm);
315  SdrObject* pObj=pM->GetMarkedSdrObj();
316  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
317  if (!rPts.empty()) {
318  SdrGluePointList* pGPL=pObj->ForceGluePointList();
319  if (pGPL!=nullptr)
320  {
321  if( IsUndoEnabled() )
322  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
323 
324  for(sal_uInt16 nPtId : rPts)
325  {
326  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
327  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
328  SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
329  Point aPos(rGP.GetAbsolutePos(*pObj));
330  (*pTrFunc)(aPos,p1,p2,p3,p4);
331  rGP.SetAbsolutePos(aPos,*pObj);
332  }
333  }
334  pObj->SetChanged();
335  pObj->BroadcastObjectChange();
336  }
337  }
338  }
339  if (nMarkCount!=0) mpModel->SetChanged();
340 }
341 
342 
343 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/)
344 {
345  rPt.AdjustX(static_cast<const Size*>(p1)->Width() );
346  rPt.AdjustY(static_cast<const Size*>(p1)->Height() );
347 }
348 
349 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
350 {
352  OUString aStr(SvxResId(STR_EditMove));
353  if (bCopy) aStr += SvxResId(STR_EditWithCopy);
355  if (bCopy) ImpCopyMarkedGluePoints();
357  EndUndo();
358  AdjustMarkHdl();
359 }
360 
361 
362 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/)
363 {
364  ResizePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const Fraction*>(p2),*static_cast<const Fraction*>(p3));
365 }
366 
367 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
368 {
370  OUString aStr(SvxResId(STR_EditResize));
371  if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
373  if (bCopy) ImpCopyMarkedGluePoints();
374  ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
375  EndUndo();
376  AdjustMarkHdl();
377 }
378 
379 
380 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4)
381 {
382  RotatePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p3),*static_cast<const double*>(p4));
383 }
384 
385 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nAngle, bool bCopy)
386 {
388  OUString aStr(SvxResId(STR_EditRotate));
389  if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
391  if (bCopy) ImpCopyMarkedGluePoints();
392  double nSin = sin(nAngle * F_PI18000);
393  double nCos = cos(nAngle * F_PI18000);
394  ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
395  EndUndo();
396  AdjustMarkHdl();
397 }
398 
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void ImpGetPercent(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnRet, const void *, const void *)
Definition: svdglev.cxx:127
const SdrUShortCont & GetMarkedGluePoints() const
Definition: svdmark.hxx:115
static void ImpSetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pnThisEsc, const void *pbOn, const void *, const void *)
Definition: svdglev.cxx:108
bool UnmarkAllGluePoints()
Definition: svdmrkv.hxx:392
SdrAlign GetVertAlign() const
Definition: svdglue.hxx:101
void ResizePoint(Point &rPnt, const Point &rRef, const Fraction &xFract, const Fraction &yFract)
Definition: svdtrans.hxx:106
TriState IsMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc) const
Definition: svdglev.cxx:99
SdrEscapeDirection
Definition: svdglue.hxx:35
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1027
void BegUndo()
Definition: svdedtv.hxx:179
void SetHorzAlign(SdrAlign nAlg)
Definition: svdglue.hxx:100
void ImpCopyMarkedGluePoints()
Definition: svdglev.cxx:264
OUString const & GetDescriptionOfMarkedGluePoints() const
Definition: svdmrkv.hxx:263
std::set< sal_uInt16 > SdrUShortCont
Definition: svdmark.hxx:36
virtual void BrkAction() override
Definition: svdmrkv.cxx:331
TRISTATE_TRUE
virtual ~SdrGlueEditView() override
Definition: svdglev.cxx:38
SdrModel * mpModel
Definition: svdpntv.hxx:132
TriState IsMarkedGluePointsPercent() const
Definition: svdglev.cxx:142
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void ForceUndirtyMrkPnt() const
Definition: svdmrkv.hxx:167
SdrAlign GetHorzAlign() const
Definition: svdglue.hxx:99
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1261
TRISTATE_INDET
void EndUndo()
Definition: svdedtv.cxx:275
SdrEscapeDirection GetEscDir() const
Definition: svdglue.hxx:84
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:44
static void ImpSetPercent(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbOn, const void *, const void *, const void *)
Definition: svdglev.cxx:151
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:183
void ResizeMarkedGluePoints(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bCopy)
Definition: svdglev.cxx:367
virtual const SdrGluePointList * GetGluePointList() const
Definition: svdobj.cxx:2203
static void ImpRotate(Point &rPt, const void *p1, const void *, const void *p3, const void *p4)
Definition: svdglev.cxx:380
void ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void *p1, const void *p2=nullptr, const void *p3=nullptr, const void *p4=nullptr)
Definition: svdglev.cxx:42
#define SDRGLUEPOINT_NOTFOUND
Definition: svdglue.hxx:116
bool IsPercent() const
Definition: svdglue.hxx:88
size_t GetMarkedObjectCount() const
Definition: svdmrkv.hxx:258
void BroadcastObjectChange() const
Definition: svdobj.cxx:905
TRISTATE_FALSE
void SetVertAlign(SdrAlign nAlg)
Definition: svdglue.hxx:102
void SetPercent(bool bOn)
Definition: svdglue.hxx:89
void SetAbsolutePos(const Point &rNewPos, const SdrObject &rObj)
Definition: svdglue.cxx:88
void DeleteMarkedGluePoints()
Definition: svdglev.cxx:221
static void ImpResize(Point &rPt, const void *p1, const void *p2, const void *p3, const void *)
Definition: svdglev.cxx:362
static void ImpGetAlign(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pbDontCare, const void *pbVert, const void *pnRet)
Definition: svdglev.cxx:167
Abstract DrawObject.
Definition: svdobj.hxx:312
void SetMarkedGluePointsPercent(bool bOn)
Definition: svdglev.cxx:158
Point GetAbsolutePos(const SdrObject &rObj) const
Definition: svdglue.cxx:47
static void ImpMove(Point &rPt, const void *p1, const void *, const void *, const void *)
Definition: svdglev.cxx:343
sal_uInt16 FindGluePoint(sal_uInt16 nId) const
Definition: svdglue.cxx:331
sal_uInt16 Insert(const SdrGluePoint &rGP)
Definition: svdglue.cxx:292
void SetMarkedGluePointsAlign(bool bVert, SdrAlign nAlign)
Definition: svdglev.cxx:213
void RotateMarkedGluePoints(const Point &rRef, long nAngle, bool bCopy)
Definition: svdglev.cxx:385
void SetMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc, bool bOn)
Definition: svdglev.cxx:118
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:114
void Delete(sal_uInt16 nPos)
Definition: svdglue.hxx:129
virtual SdrGluePointList * ForceGluePointList()
Definition: svdobj.cxx:2210
static void ImpGetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnThisEsc, const void *pnRet, const void *)
Definition: svdglev.cxx:84
SdrGlueEditView(SdrModel &rSdrModel, OutputDevice *pOut)
Definition: svdglev.cxx:31
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
Definition: svdmrkv.cxx:2387
void ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void *p1, const void *p2=nullptr, const void *p3=nullptr, const void *p4=nullptr)
Definition: svdglev.cxx:310
#define F_PI18000
SdrAlign GetMarkedGluePointsAlign(bool bVert) const
Definition: svdglev.cxx:192
static void ImpSetAlign(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbVert, const void *pnAlign, const void *, const void *)
Definition: svdglev.cxx:202
SdrMark * GetSdrMarkByIndex(size_t nNum) const
Definition: svdmrkv.hxx:256
virtual void SetChanged()
Definition: svdobj.cxx:929
TriState
SdrAlign
Definition: svdglue.hxx:51
SdrModel * GetModel() const
Definition: svdpntv.hxx:271
void SetEscDir(SdrEscapeDirection nNewEsc)
Definition: svdglue.hxx:85
aStr
void MoveMarkedGluePoints(const Size &rSiz, bool bCopy)
Definition: svdglev.cxx:349