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
42void 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) {
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() )
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();
76 }
77 }
78 }
79 }
80 if (!bConst && nMarkCount!=0)
82}
83
84
85static 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
109static 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
128static 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
152static 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
168static 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)
174 return;
175
177 if (bVert) {
178 nAlg=rGP.GetVertAlign();
179 } else {
180 nAlg=rGP.GetHorzAlign();
181 }
182 bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
183 if (bFirst) { nRet=nAlg; bFirst=false; }
184 else if (nRet!=nAlg) {
185 if (bVert) {
187 } else {
189 }
190 bDontCare=true;
191 }
192}
193
195{
197 bool bFirst=true;
198 bool bDontCare=false;
200 const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
201 return nRet;
202}
203
204static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*)
205{
206 Point aPos(rGP.GetAbsolutePos(*pObj));
207 if (*static_cast<bool const *>(pbVert)) { // bVert?
208 rGP.SetVertAlign(*static_cast<SdrAlign const *>(pnAlign));
209 } else {
210 rGP.SetHorzAlign(*static_cast<SdrAlign const *>(pnAlign));
211 }
212 rGP.SetAbsolutePos(aPos,*pObj);
213}
214
216{
218 BegUndo(SvxResId(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
219 ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
220 EndUndo();
221}
222
224{
225 BrkAction();
227 const bool bUndo = IsUndoEnabled();
228 if( bUndo )
230
231 const size_t nMarkCount=GetMarkedObjectCount();
232 for (size_t nm=0; nm<nMarkCount; ++nm)
233 {
235 SdrObject* pObj=pM->GetMarkedSdrObj();
236 const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
237 if (!rPts.empty())
238 {
240 if (pGPL!=nullptr)
241 {
242 if( bUndo )
243 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
244
245 for(sal_uInt16 nPtId : rPts)
246 {
247 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
248 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
249 {
250 pGPL->Delete(nGlueIdx);
251 }
252 }
253 pObj->SetChanged();
254 pObj->BroadcastObjectChange();
255 }
256 }
257 }
258 if( bUndo )
259 EndUndo();
261 if (nMarkCount!=0)
263}
264
265
267{
268 const bool bUndo = IsUndoEnabled();
269
270 if( bUndo )
271 BegUndo();
272
273 const size_t nMarkCount=GetMarkedObjectCount();
274 for (size_t nm=0; nm<nMarkCount; ++nm)
275 {
277 SdrObject* pObj=pM->GetMarkedSdrObj();
280 if (!rPts.empty() && pGPL!=nullptr)
281 {
282 if( bUndo )
283 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
284
285 SdrUShortCont aIdsToErase;
286 SdrUShortCont aIdsToInsert;
287 for(sal_uInt16 nPtId : rPts)
288 {
289 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
290 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
291 {
292 SdrGluePoint aNewGP((*pGPL)[nGlueIdx]); // clone GluePoint
293 sal_uInt16 nNewIdx=pGPL->Insert(aNewGP); // and insert it
294 sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId(); // retrieve ID of new GluePoints
295 aIdsToErase.insert(nPtId); // select it (instead of the old one)
296 aIdsToInsert.insert(nNewId);
297 }
298 }
299 for(const auto& rId : aIdsToErase)
300 rPts.erase(rId);
301 rPts.insert(aIdsToInsert);
302 }
303 }
304 if( bUndo )
305 EndUndo();
306
307 if (nMarkCount!=0)
309}
310
311
312void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4)
313{
314 const size_t nMarkCount=GetMarkedObjectCount();
315 for (size_t nm=0; nm<nMarkCount; ++nm) {
317 SdrObject* pObj=pM->GetMarkedSdrObj();
318 const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
319 if (!rPts.empty()) {
321 if (pGPL!=nullptr)
322 {
323 if( IsUndoEnabled() )
324 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
325
326 for(sal_uInt16 nPtId : rPts)
327 {
328 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
329 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
330 SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
331 Point aPos(rGP.GetAbsolutePos(*pObj));
332 (*pTrFunc)(aPos,p1,p2,p3,p4);
333 rGP.SetAbsolutePos(aPos,*pObj);
334 }
335 }
336 pObj->SetChanged();
337 pObj->BroadcastObjectChange();
338 }
339 }
340 }
341 if (nMarkCount!=0)
343}
344
345
346static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/)
347{
348 rPt.AdjustX(static_cast<const Size*>(p1)->Width() );
349 rPt.AdjustY(static_cast<const Size*>(p1)->Height() );
350}
351
352void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
353{
355 OUString aStr(SvxResId(STR_EditMove));
356 if (bCopy) aStr += SvxResId(STR_EditWithCopy);
358 if (bCopy) ImpCopyMarkedGluePoints();
360 EndUndo();
362}
363
364
365static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/)
366{
367 ResizePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const Fraction*>(p2),*static_cast<const Fraction*>(p3));
368}
369
370void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
371{
373 OUString aStr(SvxResId(STR_EditResize));
374 if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
376 if (bCopy) ImpCopyMarkedGluePoints();
377 ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
378 EndUndo();
380}
381
382
383static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4)
384{
385 RotatePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p3),*static_cast<const double*>(p4));
386}
387
388void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, Degree100 nAngle, bool bCopy)
389{
391 OUString aStr(SvxResId(STR_EditRotate));
392 if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
394 if (bCopy) ImpCopyMarkedGluePoints();
395 double nSin = sin(toRadians(nAngle));
396 double nCos = cos(toRadians(nAngle));
397 ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
398 EndUndo();
400}
401
402/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1056
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:196
void BegUndo()
Definition: svdedtv.hxx:178
void EndUndo()
Definition: svdedtv.cxx:295
void SetMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc, bool bOn)
Definition: svdglev.cxx:119
void SetMarkedGluePointsPercent(bool bOn)
Definition: svdglev.cxx:159
SdrAlign GetMarkedGluePointsAlign(bool bVert) const
Definition: svdglev.cxx:194
void ImpCopyMarkedGluePoints()
Definition: svdglev.cxx:266
void MoveMarkedGluePoints(const Size &rSiz, bool bCopy)
Definition: svdglev.cxx:352
void SetMarkedGluePointsAlign(bool bVert, SdrAlign nAlign)
Definition: svdglev.cxx:215
void ResizeMarkedGluePoints(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bCopy)
Definition: svdglev.cxx:370
void ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void *p1, const void *p2=nullptr, const void *p3=nullptr, const void *p4=nullptr)
Definition: svdglev.cxx:312
TriState IsMarkedGluePointsPercent() const
Definition: svdglev.cxx:143
virtual ~SdrGlueEditView() override
Definition: svdglev.cxx:38
void DeleteMarkedGluePoints()
Definition: svdglev.cxx:223
TriState IsMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc) const
Definition: svdglev.cxx:100
SdrGlueEditView(SdrModel &rSdrModel, OutputDevice *pOut)
Definition: svdglev.cxx:31
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
void RotateMarkedGluePoints(const Point &rRef, Degree100 nAngle, bool bCopy)
Definition: svdglev.cxx:388
sal_uInt16 Insert(const SdrGluePoint &rGP)
Definition: svdglue.cxx:295
sal_uInt16 FindGluePoint(sal_uInt16 nId) const
Definition: svdglue.cxx:336
void Delete(sal_uInt16 nPos)
Definition: svdglue.hxx:201
bool IsPercent() const
Definition: svdglue.hxx:120
void SetPercent(bool bOn)
Definition: svdglue.hxx:124
Point GetAbsolutePos(const SdrObject &rObj) const
Definition: svdglue.cxx:48
void SetEscDir(SdrEscapeDirection nNewEsc)
Definition: svdglue.hxx:108
void SetVertAlign(SdrAlign nAlg)
Definition: svdglue.hxx:162
SdrEscapeDirection GetEscDir() const
Definition: svdglue.hxx:104
void SetHorzAlign(SdrAlign nAlg)
Definition: svdglue.hxx:153
SdrAlign GetVertAlign() const
Definition: svdglue.hxx:158
SdrAlign GetHorzAlign() const
Definition: svdglue.hxx:149
void SetAbsolutePos(const Point &rNewPos, const SdrObject &rObj)
Definition: svdglue.cxx:89
size_t GetMarkedObjectCount() const
Definition: svdmrkv.hxx:264
void ForceUndirtyMrkPnt() const
Definition: svdmrkv.hxx:170
SdrMark * GetSdrMarkByIndex(size_t nNum) const
Definition: svdmrkv.hxx:262
virtual void BrkAction() override
Definition: svdmrkv.cxx:339
bool UnmarkAllGluePoints()
Definition: svdmrkv.hxx:398
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
Definition: svdmrkv.cxx:2614
OUString const & GetDescriptionOfMarkedGluePoints() const
Definition: svdmrkv.hxx:269
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:45
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
const SdrUShortCont & GetMarkedGluePoints() const
Definition: svdmark.hxx:115
virtual void SetChanged(bool bFlg=true)
Definition: svdmodel.cxx:1143
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1915
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual SdrGluePointList * ForceGluePointList()
Definition: svdobj.cxx:2319
void BroadcastObjectChange() const
Definition: svdobj.cxx:1018
virtual void SetChanged()
Definition: svdobj.cxx:1042
virtual const SdrGluePointList * GetGluePointList() const
Definition: svdobj.cxx:2312
SdrModel & GetModel() const
Definition: svdpntv.hxx:282
virtual std::unique_ptr< SdrUndoAction > CreateUndoGeoObject(SdrObject &rObject)
Definition: svdundo.cxx:1668
bool empty() const
std::pair< const_iterator, bool > insert(Value &&x)
double toRadians(D x)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
TriState
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
aStr
static void ImpSetPercent(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbOn, const void *, const void *, const void *)
Definition: svdglev.cxx:152
static void ImpGetAlign(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pbDontCare, const void *pbVert, const void *pnRet)
Definition: svdglev.cxx:168
static void ImpSetAlign(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbVert, const void *pnAlign, const void *, const void *)
Definition: svdglev.cxx:204
static void ImpRotate(Point &rPt, const void *p1, const void *, const void *p3, const void *p4)
Definition: svdglev.cxx:383
static void ImpGetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnThisEsc, const void *pnRet, const void *)
Definition: svdglev.cxx:85
static void ImpResize(Point &rPt, const void *p1, const void *p2, const void *p3, const void *)
Definition: svdglev.cxx:365
static void ImpGetPercent(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnRet, const void *, const void *)
Definition: svdglev.cxx:128
static void ImpSetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pnThisEsc, const void *pbOn, const void *, const void *)
Definition: svdglev.cxx:109
static void ImpMove(Point &rPt, const void *p1, const void *, const void *, const void *)
Definition: svdglev.cxx:346
SdrAlign
Definition: svdglue.hxx:51
SdrEscapeDirection
Definition: svdglue.hxx:35
#define SDRGLUEPOINT_NOTFOUND
Definition: svdglue.hxx:181
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:101
void ResizePoint(Point &rPnt, const Point &rRef, const Fraction &xFract, const Fraction &yFract)
Definition: svdtrans.hxx:93
oslFileHandle & pOut