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)
173  return;
174 
176  if (bVert) {
177  nAlg=rGP.GetVertAlign();
178  } else {
179  nAlg=rGP.GetHorzAlign();
180  }
181  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
182  if (bFirst) { nRet=nAlg; bFirst=false; }
183  else if (nRet!=nAlg) {
184  if (bVert) {
186  } else {
188  }
189  bDontCare=true;
190  }
191 }
192 
194 {
196  bool bFirst=true;
197  bool bDontCare=false;
199  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
200  return nRet;
201 }
202 
203 static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*)
204 {
205  Point aPos(rGP.GetAbsolutePos(*pObj));
206  if (*static_cast<bool const *>(pbVert)) { // bVert?
207  rGP.SetVertAlign(*static_cast<SdrAlign const *>(pnAlign));
208  } else {
209  rGP.SetHorzAlign(*static_cast<SdrAlign const *>(pnAlign));
210  }
211  rGP.SetAbsolutePos(aPos,*pObj);
212 }
213 
215 {
217  BegUndo(SvxResId(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
218  ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
219  EndUndo();
220 }
221 
223 {
224  BrkAction();
226  const bool bUndo = IsUndoEnabled();
227  if( bUndo )
229 
230  const size_t nMarkCount=GetMarkedObjectCount();
231  for (size_t nm=0; nm<nMarkCount; ++nm)
232  {
233  SdrMark* pM=GetSdrMarkByIndex(nm);
234  SdrObject* pObj=pM->GetMarkedSdrObj();
235  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
236  if (!rPts.empty())
237  {
238  SdrGluePointList* pGPL=pObj->ForceGluePointList();
239  if (pGPL!=nullptr)
240  {
241  if( bUndo )
242  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
243 
244  for(sal_uInt16 nPtId : rPts)
245  {
246  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
247  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
248  {
249  pGPL->Delete(nGlueIdx);
250  }
251  }
252  pObj->SetChanged();
253  pObj->BroadcastObjectChange();
254  }
255  }
256  }
257  if( bUndo )
258  EndUndo();
260  if (nMarkCount!=0)
261  mpModel->SetChanged();
262 }
263 
264 
266 {
267  const bool bUndo = IsUndoEnabled();
268 
269  if( bUndo )
270  BegUndo();
271 
272  const size_t nMarkCount=GetMarkedObjectCount();
273  for (size_t nm=0; nm<nMarkCount; ++nm)
274  {
275  SdrMark* pM=GetSdrMarkByIndex(nm);
276  SdrObject* pObj=pM->GetMarkedSdrObj();
277  SdrUShortCont& rPts = pM->GetMarkedGluePoints();
278  SdrGluePointList* pGPL=pObj->ForceGluePointList();
279  if (!rPts.empty() && pGPL!=nullptr)
280  {
281  if( bUndo )
282  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
283 
284  SdrUShortCont aIdsToErase;
285  SdrUShortCont aIdsToInsert;
286  for(sal_uInt16 nPtId : rPts)
287  {
288  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
289  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
290  {
291  SdrGluePoint aNewGP((*pGPL)[nGlueIdx]); // clone GluePoint
292  sal_uInt16 nNewIdx=pGPL->Insert(aNewGP); // and insert it
293  sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId(); // retrieve ID of new GluePoints
294  aIdsToErase.insert(nPtId); // select it (instead of the old one)
295  aIdsToInsert.insert(nNewId);
296  }
297  }
298  for(const auto& rId : aIdsToErase)
299  rPts.erase(rId);
300  rPts.insert(aIdsToInsert.begin(), aIdsToInsert.end());
301  }
302  }
303  if( bUndo )
304  EndUndo();
305 
306  if (nMarkCount!=0)
307  mpModel->SetChanged();
308 }
309 
310 
311 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4)
312 {
313  const size_t nMarkCount=GetMarkedObjectCount();
314  for (size_t nm=0; nm<nMarkCount; ++nm) {
315  SdrMark* pM=GetSdrMarkByIndex(nm);
316  SdrObject* pObj=pM->GetMarkedSdrObj();
317  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
318  if (!rPts.empty()) {
319  SdrGluePointList* pGPL=pObj->ForceGluePointList();
320  if (pGPL!=nullptr)
321  {
322  if( IsUndoEnabled() )
323  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
324 
325  for(sal_uInt16 nPtId : rPts)
326  {
327  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
328  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
329  SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
330  Point aPos(rGP.GetAbsolutePos(*pObj));
331  (*pTrFunc)(aPos,p1,p2,p3,p4);
332  rGP.SetAbsolutePos(aPos,*pObj);
333  }
334  }
335  pObj->SetChanged();
336  pObj->BroadcastObjectChange();
337  }
338  }
339  }
340  if (nMarkCount!=0) mpModel->SetChanged();
341 }
342 
343 
344 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/)
345 {
346  rPt.AdjustX(static_cast<const Size*>(p1)->Width() );
347  rPt.AdjustY(static_cast<const Size*>(p1)->Height() );
348 }
349 
350 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
351 {
353  OUString aStr(SvxResId(STR_EditMove));
354  if (bCopy) aStr += SvxResId(STR_EditWithCopy);
356  if (bCopy) ImpCopyMarkedGluePoints();
358  EndUndo();
359  AdjustMarkHdl();
360 }
361 
362 
363 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/)
364 {
365  ResizePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const Fraction*>(p2),*static_cast<const Fraction*>(p3));
366 }
367 
368 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
369 {
371  OUString aStr(SvxResId(STR_EditResize));
372  if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
374  if (bCopy) ImpCopyMarkedGluePoints();
375  ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
376  EndUndo();
377  AdjustMarkHdl();
378 }
379 
380 
381 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4)
382 {
383  RotatePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p3),*static_cast<const double*>(p4));
384 }
385 
386 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nAngle, bool bCopy)
387 {
389  OUString aStr(SvxResId(STR_EditRotate));
390  if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
392  if (bCopy) ImpCopyMarkedGluePoints();
393  double nSin = sin(nAngle * F_PI18000);
394  double nCos = cos(nAngle * F_PI18000);
395  ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
396  EndUndo();
397  AdjustMarkHdl();
398 }
399 
400 /* 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:265
OUString const & GetDescriptionOfMarkedGluePoints() const
Definition: svdmrkv.hxx:263
std::set< sal_uInt16 > SdrUShortCont
Definition: svdmark.hxx:36
virtual void BrkAction() override
Definition: svdmrkv.cxx:332
TRISTATE_TRUE
virtual ~SdrGlueEditView() override
Definition: svdglev.cxx:38
SdrModel * mpModel
Definition: svdpntv.hxx:126
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:368
virtual const SdrGluePointList * GetGluePointList() const
Definition: svdobj.cxx:2204
static void ImpRotate(Point &rPt, const void *p1, const void *, const void *p3, const void *p4)
Definition: svdglev.cxx:381
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:222
static void ImpResize(Point &rPt, const void *p1, const void *p2, const void *p3, const void *)
Definition: svdglev.cxx:363
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:344
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:214
void RotateMarkedGluePoints(const Point &rRef, long nAngle, bool bCopy)
Definition: svdglev.cxx:386
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:2211
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:2390
void ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void *p1, const void *p2=nullptr, const void *p3=nullptr, const void *p4=nullptr)
Definition: svdglev.cxx:311
#define F_PI18000
SdrAlign GetMarkedGluePointsAlign(bool bVert) const
Definition: svdglev.cxx:193
static void ImpSetAlign(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbVert, const void *pnAlign, const void *, const void *)
Definition: svdglev.cxx:203
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:265
void SetEscDir(SdrEscapeDirection nNewEsc)
Definition: svdglue.hxx:85
aStr
void MoveMarkedGluePoints(const Size &rSiz, bool bCopy)
Definition: svdglev.cxx:350