xref: /AOO41X/main/svx/source/svdraw/svdglev.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svdglev.hxx>
28 #include <math.h>
29 
30 #include <svx/svdundo.hxx>
31 #include "svx/svdstr.hrc"   // Namen aus der Resource
32 #include "svx/svdglob.hxx"  // StringCache
33 #include <svx/svdpagv.hxx>
34 #include <svx/svdglue.hxx>
35 #include <svx/svdtrans.hxx>
36 #include <svx/svdobj.hxx>
37 
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 
ImpClearVars()40 void SdrGlueEditView::ImpClearVars()
41 {
42 }
43 
SdrGlueEditView(SdrModel * pModel1,OutputDevice * pOut)44 SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
45     SdrPolyEditView(pModel1,pOut)
46 {
47     ImpClearVars();
48 }
49 
~SdrGlueEditView()50 SdrGlueEditView::~SdrGlueEditView()
51 {
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////////////////////////
55 
ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc,sal_Bool bConst,const void * p1,const void * p2,const void * p3,const void * p4,const void * p5)56 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, sal_Bool bConst, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
57 {
58     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
59     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
60         SdrMark* pM=GetSdrMarkByIndex(nm);
61         SdrObject* pObj=pM->GetMarkedSdrObj();
62         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
63         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->GetCount();
64         if (nPtAnz!=0) {
65             SdrGluePointList* pGPL=NULL;
66             if (bConst) {
67                 const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
68                 pGPL=(SdrGluePointList*)pConstGPL;
69             } else {
70                 pGPL=pObj->ForceGluePointList();
71             }
72             if (pGPL!=NULL)
73             {
74                 if(!bConst && IsUndoEnabled() )
75                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
76 
77                 for (sal_uIntPtr nPtNum=0; nPtNum<nPtAnz; nPtNum++)
78                 {
79                     sal_uInt16 nPtId=pPts->GetObject(nPtNum);
80                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
81                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
82                     {
83                         SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
84                         (*pDoFunc)(rGP,pObj,p1,p2,p3,p4,p5);
85                     }
86                 }
87                 if (!bConst)
88                 {
89                     pObj->SetChanged();
90                     pObj->BroadcastObjectChange();
91                 }
92             }
93         }
94     }
95     if (!bConst && nMarkAnz!=0) pMod->SetChanged();
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////////////////////////
99 
ImpGetEscDir(SdrGluePoint & rGP,const SdrObject *,const void * pbFirst,const void * pnThisEsc,const void * pnRet,const void *,const void *)100 static void ImpGetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*, const void*)
101 {
102     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
103     sal_Bool& bFirst=*(sal_Bool*)pbFirst;
104     if (nRet!=FUZZY) {
105         sal_uInt16 nEsc=rGP.GetEscDir();
106         sal_Bool bOn=(nEsc & *(sal_uInt16*)pnThisEsc)!=0;
107         if (bFirst) { nRet=bOn; bFirst=sal_False; }
108         else if (nRet!=bOn) nRet=FUZZY;
109     }
110 }
111 
IsMarkedGluePointsEscDir(sal_uInt16 nThisEsc) const112 TRISTATE SdrGlueEditView::IsMarkedGluePointsEscDir(sal_uInt16 nThisEsc) const
113 {
114     ForceUndirtyMrkPnt();
115     sal_Bool bFirst=sal_True;
116     sal_uInt16 nRet=sal_False;
117     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetEscDir,sal_True,&bFirst,&nThisEsc,&nRet);
118     return (TRISTATE)nRet;
119 }
120 
ImpSetEscDir(SdrGluePoint & rGP,const SdrObject *,const void * pnThisEsc,const void * pbOn,const void *,const void *,const void *)121 static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*, const void*)
122 {
123     sal_uInt16 nEsc=rGP.GetEscDir();
124     if (*(sal_Bool*)pbOn) nEsc|=*(sal_uInt16*)pnThisEsc;
125     else nEsc&=~*(sal_uInt16*)pnThisEsc;
126     rGP.SetEscDir(nEsc);
127 }
128 
SetMarkedGluePointsEscDir(sal_uInt16 nThisEsc,sal_Bool bOn)129 void SdrGlueEditView::SetMarkedGluePointsEscDir(sal_uInt16 nThisEsc, sal_Bool bOn)
130 {
131     ForceUndirtyMrkPnt();
132     BegUndo(ImpGetResStr(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
133     ImpDoMarkedGluePoints(ImpSetEscDir,sal_False,&nThisEsc,&bOn);
134     EndUndo();
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////////////////////////
138 
ImpGetPercent(SdrGluePoint & rGP,const SdrObject *,const void * pbFirst,const void * pnRet,const void *,const void *,const void *)139 static void ImpGetPercent(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*, const void*)
140 {
141     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
142     sal_Bool& bFirst=*(sal_Bool*)pbFirst;
143     if (nRet!=FUZZY) {
144         bool bOn=rGP.IsPercent();
145         if (bFirst) { nRet=bOn; bFirst=sal_False; }
146         else if ((nRet!=0)!=bOn) nRet=FUZZY;
147     }
148 }
149 
IsMarkedGluePointsPercent() const150 TRISTATE SdrGlueEditView::IsMarkedGluePointsPercent() const
151 {
152     ForceUndirtyMrkPnt();
153     sal_Bool bFirst=sal_True;
154     sal_uInt16 nRet=sal_True;
155     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetPercent,sal_True,&bFirst,&nRet);
156     return (TRISTATE)nRet;
157 }
158 
ImpSetPercent(SdrGluePoint & rGP,const SdrObject * pObj,const void * pbOn,const void *,const void *,const void *,const void *)159 static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*, const void*)
160 {
161     Point aPos(rGP.GetAbsolutePos(*pObj));
162     rGP.SetPercent(*(sal_Bool*)pbOn);
163     rGP.SetAbsolutePos(aPos,*pObj);
164 }
165 
SetMarkedGluePointsPercent(sal_Bool bOn)166 void SdrGlueEditView::SetMarkedGluePointsPercent(sal_Bool bOn)
167 {
168     ForceUndirtyMrkPnt();
169     BegUndo(ImpGetResStr(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
170     ImpDoMarkedGluePoints(ImpSetPercent,sal_False,&bOn);
171     EndUndo();
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////////////////////////
175 
ImpGetAlign(SdrGluePoint & rGP,const SdrObject *,const void * pbFirst,const void * pbDontCare,const void * pbVert,const void * pnRet,const void *)176 static void ImpGetAlign(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet, const void*)
177 {
178     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
179     sal_Bool& bFirst=*(sal_Bool*)pbFirst;
180     sal_Bool& bDontCare=*(sal_Bool*)pbDontCare;
181     sal_Bool bVert=*(sal_Bool*)pbVert;
182     if (!bDontCare) {
183         sal_uInt16 nAlg=0;
184         if (bVert) {
185             nAlg=rGP.GetVertAlign();
186         } else {
187             nAlg=rGP.GetHorzAlign();
188         }
189         if (bFirst) { nRet=nAlg; bFirst=sal_False; }
190         else if (nRet!=nAlg) {
191             if (bVert) {
192                 nRet=SDRVERTALIGN_DONTCARE;
193             } else {
194                 nRet=SDRHORZALIGN_DONTCARE;
195             }
196             bDontCare=sal_True;
197         }
198     }
199 }
200 
GetMarkedGluePointsAlign(sal_Bool bVert) const201 sal_uInt16 SdrGlueEditView::GetMarkedGluePointsAlign(sal_Bool bVert) const
202 {
203     ForceUndirtyMrkPnt();
204     sal_Bool bFirst=sal_True;
205     sal_Bool bDontCare=sal_False;
206     sal_uInt16 nRet=0;
207     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetAlign,sal_True,&bFirst,&bDontCare,&bVert,&nRet);
208     return nRet;
209 }
210 
ImpSetAlign(SdrGluePoint & rGP,const SdrObject * pObj,const void * pbVert,const void * pnAlign,const void *,const void *,const void *)211 static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*, const void*)
212 {
213     Point aPos(rGP.GetAbsolutePos(*pObj));
214     if (*(sal_Bool*)pbVert) { // bVert?
215         rGP.SetVertAlign(*(sal_uInt16*)pnAlign);
216     } else {
217         rGP.SetHorzAlign(*(sal_uInt16*)pnAlign);
218     }
219     rGP.SetAbsolutePos(aPos,*pObj);
220 }
221 
SetMarkedGluePointsAlign(sal_Bool bVert,sal_uInt16 nAlign)222 void SdrGlueEditView::SetMarkedGluePointsAlign(sal_Bool bVert, sal_uInt16 nAlign)
223 {
224     ForceUndirtyMrkPnt();
225     BegUndo(ImpGetResStr(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
226     ImpDoMarkedGluePoints(ImpSetAlign,sal_False,&bVert,&nAlign);
227     EndUndo();
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////////////////////////
231 
IsDeleteMarkedGluePointsPossible() const232 sal_Bool SdrGlueEditView::IsDeleteMarkedGluePointsPossible() const
233 {
234     return HasMarkedGluePoints();
235 }
236 
DeleteMarkedGluePoints()237 void SdrGlueEditView::DeleteMarkedGluePoints()
238 {
239     BrkAction();
240     ForceUndirtyMrkPnt();
241     const bool bUndo = IsUndoEnabled();
242     if( bUndo )
243         BegUndo(ImpGetResStr(STR_EditDelete),GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_DELETE);
244 
245     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
246     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
247     {
248         SdrMark* pM=GetSdrMarkByIndex(nm);
249         SdrObject* pObj=pM->GetMarkedSdrObj();
250         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
251         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->GetCount();
252         if (nPtAnz!=0)
253         {
254             SdrGluePointList* pGPL=pObj->ForceGluePointList();
255             if (pGPL!=NULL)
256             {
257                 if( bUndo )
258                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
259 
260                 for (sal_uIntPtr nPtNum=0; nPtNum<nPtAnz; nPtNum++)
261                 {
262                     sal_uInt16 nPtId=pPts->GetObject(nPtNum);
263                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
264                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
265                     {
266                         pGPL->Delete(nGlueIdx);
267                     }
268                 }
269                 pObj->SetChanged();
270                 pObj->BroadcastObjectChange();
271             }
272         }
273     }
274     if( bUndo )
275         EndUndo();
276     UnmarkAllGluePoints();
277     if (nMarkAnz!=0)
278         pMod->SetChanged();
279 }
280 
281 ////////////////////////////////////////////////////////////////////////////////////////////////////
282 
ImpCopyMarkedGluePoints()283 void SdrGlueEditView::ImpCopyMarkedGluePoints()
284 {
285     const bool bUndo = IsUndoEnabled();
286 
287     if( bUndo )
288         BegUndo();
289 
290     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
291     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
292     {
293         SdrMark* pM=GetSdrMarkByIndex(nm);
294         SdrObject* pObj=pM->GetMarkedSdrObj();
295         SdrUShortCont* pPts=pM->GetMarkedGluePoints();
296         SdrGluePointList* pGPL=pObj->ForceGluePointList();
297         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->GetCount();
298         if (nPtAnz!=0 && pGPL!=NULL)
299         {
300             if( bUndo )
301                 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
302 
303             for (sal_uIntPtr nPtNum=0; nPtNum<nPtAnz; nPtNum++)
304             {
305                 sal_uInt16 nPtId=pPts->GetObject(nPtNum);
306                 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
307                 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
308                 {
309                     SdrGluePoint aNewGP((*pGPL)[nGlueIdx]);  // GluePoint klonen
310                     sal_uInt16 nNewIdx=pGPL->Insert(aNewGP);     // und einfuegen
311                     sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId();  // Id des neuen GluePoints ermitteln
312                     pPts->Replace(nNewId,nPtNum);            // und diesen markieren (anstelle des alten)
313                 }
314             }
315         }
316     }
317     if( bUndo )
318         EndUndo();
319 
320     if (nMarkAnz!=0)
321         pMod->SetChanged();
322 }
323 
324 ////////////////////////////////////////////////////////////////////////////////////////////////////
325 
ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc,const void * p1,const void * p2,const void * p3,const void * p4,const void * p5)326 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
327 {
328     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
329     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
330         SdrMark* pM=GetSdrMarkByIndex(nm);
331         SdrObject* pObj=pM->GetMarkedSdrObj();
332         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
333         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->GetCount();
334         if (nPtAnz!=0) {
335             SdrGluePointList* pGPL=pObj->ForceGluePointList();
336             if (pGPL!=NULL)
337             {
338                 if( IsUndoEnabled() )
339                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
340 
341                 for (sal_uIntPtr nPtNum=0; nPtNum<nPtAnz; nPtNum++) {
342                     sal_uInt16 nPtId=pPts->GetObject(nPtNum);
343                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
344                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
345                         SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
346                         Point aPos(rGP.GetAbsolutePos(*pObj));
347                         (*pTrFunc)(aPos,p1,p2,p3,p4,p5);
348                         rGP.SetAbsolutePos(aPos,*pObj);
349                     }
350                 }
351                 pObj->SetChanged();
352                 pObj->BroadcastObjectChange();
353             }
354         }
355     }
356     if (nMarkAnz!=0) pMod->SetChanged();
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////////////////////////
360 
ImpMove(Point & rPt,const void * p1,const void *,const void *,const void *,const void *)361 static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
362 {
363     rPt.X()+=((const Size*)p1)->Width();
364     rPt.Y()+=((const Size*)p1)->Height();
365 }
366 
MoveMarkedGluePoints(const Size & rSiz,bool bCopy)367 void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
368 {
369     ForceUndirtyMrkPnt();
370     XubString aStr(ImpGetResStr(STR_EditMove));
371     if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
372     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_MOVE);
373     if (bCopy) ImpCopyMarkedGluePoints();
374     ImpTransformMarkedGluePoints(ImpMove,&rSiz);
375     EndUndo();
376     AdjustMarkHdl();
377 }
378 
379 ////////////////////////////////////////////////////////////////////////////////////////////////////
380 
ImpResize(Point & rPt,const void * p1,const void * p2,const void * p3,const void *,const void *)381 static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/, const void* /*p5*/)
382 {
383     ResizePoint(rPt,*(const Point*)p1,*(const Fraction*)p2,*(const Fraction*)p3);
384 }
385 
ResizeMarkedGluePoints(const Point & rRef,const Fraction & xFact,const Fraction & yFact,bool bCopy)386 void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
387 {
388     ForceUndirtyMrkPnt();
389     XubString aStr(ImpGetResStr(STR_EditResize));
390     if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
391     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_RESIZE);
392     if (bCopy) ImpCopyMarkedGluePoints();
393     ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
394     EndUndo();
395     AdjustMarkHdl();
396 }
397 
398 ////////////////////////////////////////////////////////////////////////////////////////////////////
399 
ImpRotate(Point & rPt,const void * p1,const void *,const void * p3,const void * p4,const void *)400 static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4, const void* /*p5*/)
401 {
402     RotatePoint(rPt,*(const Point*)p1,*(const double*)p3,*(const double*)p4);
403 }
404 
RotateMarkedGluePoints(const Point & rRef,long nWink,bool bCopy)405 void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nWink, bool bCopy)
406 {
407     ForceUndirtyMrkPnt();
408     XubString aStr(ImpGetResStr(STR_EditRotate));
409     if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
410     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_ROTATE);
411     if (bCopy) ImpCopyMarkedGluePoints();
412     double nSin=sin(nWink*nPi180);
413     double nCos=cos(nWink*nPi180);
414     ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nWink,&nSin,&nCos);
415     EndUndo();
416     AdjustMarkHdl();
417 }
418 
419