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/svdpagv.hxx>
28 #include <svx/svdglue.hxx>
29 #include <svx/svdtrans.hxx>
30 #include <svx/svdobj.hxx>
31 
33  SdrModel& rSdrModel,
34  OutputDevice* pOut)
35 : SdrPolyEditView(rSdrModel, pOut)
36 {
37 }
38 
40 {
41 }
42 
43 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4)
44 {
45  const size_t nMarkCount=GetMarkedObjectCount();
46  for (size_t nm=0; nm<nMarkCount; ++nm) {
47  SdrMark* pM=GetSdrMarkByIndex(nm);
48  SdrObject* pObj=pM->GetMarkedSdrObj();
49  const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
50  if (!rPts.empty())
51  {
52  SdrGluePointList* pGPL=nullptr;
53  if (bConst) {
54  const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
55  pGPL=const_cast<SdrGluePointList*>(pConstGPL);
56  } else {
57  pGPL=pObj->ForceGluePointList();
58  }
59  if (pGPL!=nullptr)
60  {
61  if(!bConst && IsUndoEnabled() )
62  AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
63 
64  for(sal_uInt16 nPtId : rPts)
65  {
66  sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
67  if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
68  {
69  SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
70  (*pDoFunc)(rGP,pObj,p1,p2,p3,p4);
71  }
72  }
73  if (!bConst)
74  {
75  pObj->SetChanged();
76  pObj->BroadcastObjectChange();
77  }
78  }
79  }
80  }
81  if (!bConst && nMarkCount!=0) mpModel->SetChanged();
82 }
83 
84 
85 static void ImpGetEscDir(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*)
86 {
87  TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
88  if (nRet!=TRISTATE_INDET) {
89  SdrEscapeDirection nEsc = rGP.GetEscDir();
90  bool bOn = bool(nEsc & *static_cast<SdrEscapeDirection const *>(pnThisEsc));
91  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
92  if (bFirst) {
93  nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
94  bFirst = false;
95  }
96  else if (nRet != (bOn ? TRISTATE_TRUE : TRISTATE_FALSE)) nRet=TRISTATE_INDET;
97  }
98 }
99 
101 {
103  bool bFirst=true;
105  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
106  return nRet;
107 }
108 
109 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*)
110 {
111  SdrEscapeDirection nEsc=rGP.GetEscDir();
112  if (*static_cast<bool const *>(pbOn))
113  nEsc |= *static_cast<SdrEscapeDirection const *>(pnThisEsc);
114  else
115  nEsc &= ~*static_cast<SdrEscapeDirection const *>(pnThisEsc);
116  rGP.SetEscDir(nEsc);
117 }
118 
120 {
122  BegUndo(SvxResId(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
123  ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
124  EndUndo();
125 }
126 
127 
128 static void ImpGetPercent(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*)
129 {
130  TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
131  if (nRet!=TRISTATE_INDET) {
132  bool bOn=rGP.IsPercent();
133  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
134  if (bFirst) {
135  nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
136  bFirst = false;
137  }
138  else if ((nRet!=TRISTATE_FALSE)!=bOn)
139  nRet=TRISTATE_INDET;
140  }
141 }
142 
144 {
146  bool bFirst=true;
147  TriState nRet = TRISTATE_TRUE;
148  const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
149  return nRet;
150 }
151 
152 static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*)
153 {
154  Point aPos(rGP.GetAbsolutePos(*pObj));
155  rGP.SetPercent(*static_cast<bool const *>(pbOn));
156  rGP.SetAbsolutePos(aPos,*pObj);
157 }
158 
160 {
162  BegUndo(SvxResId(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
164  EndUndo();
165 }
166 
167 
168 static void ImpGetAlign(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet)
169 {
170  SdrAlign& nRet=*const_cast<SdrAlign *>(static_cast<SdrAlign const *>(pnRet));
171  bool& bDontCare=*const_cast<bool *>(static_cast<bool const *>(pbDontCare));
172  bool bVert=*static_cast<bool const *>(pbVert);
173  if (!bDontCare) {
175  if (bVert) {
176  nAlg=rGP.GetVertAlign();
177  } else {
178  nAlg=rGP.GetHorzAlign();
179  }
180  bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
181  if (bFirst) { nRet=nAlg; bFirst=false; }
182  else if (nRet!=nAlg) {
183  if (bVert) {
185  } else {
187  }
188  bDontCare=true;
189  }
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:128
const SdrUShortCont & GetMarkedGluePoints() const
Definition: svdmark.hxx:114
static void ImpSetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pnThisEsc, const void *pbOn, const void *, const void *)
Definition: svdglev.cxx:109
bool UnmarkAllGluePoints()
Definition: svdmrkv.hxx:382
long AdjustX(long nHorzMove)
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:100
SdrEscapeDirection
Definition: svdglue.hxx:35
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1031
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:254
std::set< sal_uInt16 > SdrUShortCont
Definition: svdmark.hxx:35
virtual void BrkAction() override
Definition: svdmrkv.cxx:304
TRISTATE_TRUE
virtual ~SdrGlueEditView() override
Definition: svdglev.cxx:39
SdrModel * mpModel
Definition: svdpntv.hxx:132
TriState IsMarkedGluePointsPercent() const
Definition: svdglev.cxx:143
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void ForceUndirtyMrkPnt() const
Definition: svdmrkv.hxx:158
SdrAlign GetHorzAlign() const
Definition: svdglue.hxx:99
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1274
TRISTATE_INDET
void EndUndo()
Definition: svdedtv.cxx:278
SdrEscapeDirection GetEscDir() const
Definition: svdglue.hxx:84
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:67
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:43
static void ImpSetPercent(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbOn, const void *, const void *, const void *)
Definition: svdglev.cxx:152
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:2225
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:43
long AdjustY(long nVertMove)
#define SDRGLUEPOINT_NOTFOUND
Definition: svdglue.hxx:116
bool IsPercent() const
Definition: svdglue.hxx:88
size_t GetMarkedObjectCount() const
Definition: svdmrkv.hxx:249
void BroadcastObjectChange() const
Definition: svdobj.cxx:932
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:168
Abstract DrawObject.
Definition: svdobj.hxx:312
void SetMarkedGluePointsPercent(bool bOn)
Definition: svdglev.cxx:159
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:336
sal_uInt16 Insert(const SdrGluePoint &rGP)
Definition: svdglue.cxx:297
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:119
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:114
void Delete(sal_uInt16 nPos)
Definition: svdglue.hxx:130
virtual SdrGluePointList * ForceGluePointList()
Definition: svdobj.cxx:2232
static void ImpGetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnThisEsc, const void *pnRet, const void *)
Definition: svdglev.cxx:85
SdrGlueEditView(SdrModel &rSdrModel, OutputDevice *pOut)
Definition: svdglev.cxx:32
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
Definition: svdmrkv.cxx:2343
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:247
virtual void SetChanged()
Definition: svdobj.cxx:956
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:350