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) mpModel->SetChanged();
81}
82
83
84static 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
108static 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
127static 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
151static 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
167static 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
203static 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 {
234 SdrObject* pObj=pM->GetMarkedSdrObj();
235 const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
236 if (!rPts.empty())
237 {
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)
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 {
276 SdrObject* pObj=pM->GetMarkedSdrObj();
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);
301 }
302 }
303 if( bUndo )
304 EndUndo();
305
306 if (nMarkCount!=0)
308}
309
310
311void 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) {
316 SdrObject* pObj=pM->GetMarkedSdrObj();
317 const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
318 if (!rPts.empty()) {
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
344static 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
350void 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();
360}
361
362
363static 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
368void 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();
378}
379
380
381static 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
386void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, Degree100 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(toRadians(nAngle));
394 double nCos = cos(toRadians(nAngle));
395 ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
396 EndUndo();
398}
399
400/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1059
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:182
void BegUndo()
Definition: svdedtv.hxx:178
void EndUndo()
Definition: svdedtv.cxx:295
void SetMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc, bool bOn)
Definition: svdglev.cxx:118
void SetMarkedGluePointsPercent(bool bOn)
Definition: svdglev.cxx:158
SdrAlign GetMarkedGluePointsAlign(bool bVert) const
Definition: svdglev.cxx:193
void ImpCopyMarkedGluePoints()
Definition: svdglev.cxx:265
void MoveMarkedGluePoints(const Size &rSiz, bool bCopy)
Definition: svdglev.cxx:350
void SetMarkedGluePointsAlign(bool bVert, SdrAlign nAlign)
Definition: svdglev.cxx:214
void ResizeMarkedGluePoints(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bCopy)
Definition: svdglev.cxx:368
void ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void *p1, const void *p2=nullptr, const void *p3=nullptr, const void *p4=nullptr)
Definition: svdglev.cxx:311
TriState IsMarkedGluePointsPercent() const
Definition: svdglev.cxx:142
virtual ~SdrGlueEditView() override
Definition: svdglev.cxx:38
void DeleteMarkedGluePoints()
Definition: svdglev.cxx:222
TriState IsMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc) const
Definition: svdglev.cxx:99
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:386
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:340
bool UnmarkAllGluePoints()
Definition: svdmrkv.hxx:398
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
Definition: svdmrkv.cxx:2612
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:1146
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1845
Abstract DrawObject.
Definition: svdobj.hxx:261
virtual SdrGluePointList * ForceGluePointList()
Definition: svdobj.cxx:2322
void BroadcastObjectChange() const
Definition: svdobj.cxx:978
virtual void SetChanged()
Definition: svdobj.cxx:1002
virtual const SdrGluePointList * GetGluePointList() const
Definition: svdobj.cxx:2315
SdrModel * GetModel() const
Definition: svdpntv.hxx:261
SdrModel * mpModel
Definition: svdpntv.hxx:125
virtual std::unique_ptr< SdrUndoAction > CreateUndoGeoObject(SdrObject &rObject)
Definition: svdundo.cxx:1643
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:151
static void ImpGetAlign(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pbDontCare, const void *pbVert, const void *pnRet)
Definition: svdglev.cxx:167
static void ImpSetAlign(SdrGluePoint &rGP, const SdrObject *pObj, const void *pbVert, const void *pnAlign, const void *, const void *)
Definition: svdglev.cxx:203
static void ImpRotate(Point &rPt, const void *p1, const void *, const void *p3, const void *p4)
Definition: svdglev.cxx:381
static void ImpGetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnThisEsc, const void *pnRet, const void *)
Definition: svdglev.cxx:84
static void ImpResize(Point &rPt, const void *p1, const void *p2, const void *p3, const void *)
Definition: svdglev.cxx:363
static void ImpGetPercent(SdrGluePoint &rGP, const SdrObject *, const void *pbFirst, const void *pnRet, const void *, const void *)
Definition: svdglev.cxx:127
static void ImpSetEscDir(SdrGluePoint &rGP, const SdrObject *, const void *pnThisEsc, const void *pbOn, const void *, const void *)
Definition: svdglev.cxx:108
static void ImpMove(Point &rPt, const void *p1, const void *, const void *, const void *)
Definition: svdglev.cxx:344
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