1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdglev.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/svdglev.hxx>
37 #include <svx/svdundo.hxx>
38 #include "svdstr.hrc" // Namen aus der Resource
39 #include "svdglob.hxx" // StringCache
40 #include <svx/svdpagv.hxx>
41 #include <svx/svdglue.hxx>
42 #include <svx/svdtrans.hxx>
43 #include <svx/svdobj.hxx>
45 ////////////////////////////////////////////////////////////////////////////////////////////////////
47 void SdrGlueEditView::ImpClearVars()
51 SdrGlueEditView::SdrGlueEditView(SdrModel
* pModel1
, OutputDevice
* pOut
):
52 SdrPolyEditView(pModel1
,pOut
)
57 SdrGlueEditView::~SdrGlueEditView()
61 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc
, BOOL bConst
, const void* p1
, const void* p2
, const void* p3
, const void* p4
, const void* p5
)
65 ULONG nMarkAnz
=GetMarkedObjectCount();
66 for (ULONG nm
=0; nm
<nMarkAnz
; nm
++) {
67 SdrMark
* pM
=GetSdrMarkByIndex(nm
);
68 SdrObject
* pObj
=pM
->GetMarkedSdrObj();
69 const SdrUShortCont
* pPts
=pM
->GetMarkedGluePoints();
70 ULONG nPtAnz
=pPts
==NULL
? 0 : pPts
->GetCount();
72 SdrGluePointList
* pGPL
=NULL
;
74 const SdrGluePointList
* pConstGPL
=pObj
->GetGluePointList();
75 pGPL
=(SdrGluePointList
*)pConstGPL
;
77 pGPL
=pObj
->ForceGluePointList();
81 if(!bConst
&& IsUndoEnabled() )
82 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
84 for (ULONG nPtNum
=0; nPtNum
<nPtAnz
; nPtNum
++)
86 USHORT nPtId
=pPts
->GetObject(nPtNum
);
87 USHORT nGlueIdx
=pGPL
->FindGluePoint(nPtId
);
88 if (nGlueIdx
!=SDRGLUEPOINT_NOTFOUND
)
90 SdrGluePoint
& rGP
=(*pGPL
)[nGlueIdx
];
91 (*pDoFunc
)(rGP
,pObj
,p1
,p2
,p3
,p4
,p5
);
97 pObj
->BroadcastObjectChange();
102 if (!bConst
&& nMarkAnz
!=0) pMod
->SetChanged();
105 ////////////////////////////////////////////////////////////////////////////////////////////////////
107 static void ImpGetEscDir(SdrGluePoint
& rGP
, const SdrObject
* /*pObj*/, const void* pbFirst
, const void* pnThisEsc
, const void* pnRet
, const void*, const void*)
109 USHORT
& nRet
=*(USHORT
*)pnRet
;
110 BOOL
& bFirst
=*(BOOL
*)pbFirst
;
112 USHORT nEsc
=rGP
.GetEscDir();
113 BOOL bOn
=(nEsc
& *(USHORT
*)pnThisEsc
)!=0;
114 if (bFirst
) { nRet
=bOn
; bFirst
=FALSE
; }
115 else if (nRet
!=bOn
) nRet
=FUZZY
;
119 TRISTATE
SdrGlueEditView::IsMarkedGluePointsEscDir(USHORT nThisEsc
) const
121 ForceUndirtyMrkPnt();
124 ((SdrGlueEditView
*)this)->ImpDoMarkedGluePoints(ImpGetEscDir
,TRUE
,&bFirst
,&nThisEsc
,&nRet
);
125 return (TRISTATE
)nRet
;
128 static void ImpSetEscDir(SdrGluePoint
& rGP
, const SdrObject
* /*pObj*/, const void* pnThisEsc
, const void* pbOn
, const void*, const void*, const void*)
130 USHORT nEsc
=rGP
.GetEscDir();
131 if (*(BOOL
*)pbOn
) nEsc
|=*(USHORT
*)pnThisEsc
;
132 else nEsc
&=~*(USHORT
*)pnThisEsc
;
136 void SdrGlueEditView::SetMarkedGluePointsEscDir(USHORT nThisEsc
, BOOL bOn
)
138 ForceUndirtyMrkPnt();
139 BegUndo(ImpGetResStr(STR_EditSetGlueEscDir
),GetDescriptionOfMarkedGluePoints());
140 ImpDoMarkedGluePoints(ImpSetEscDir
,FALSE
,&nThisEsc
,&bOn
);
144 ////////////////////////////////////////////////////////////////////////////////////////////////////
146 static void ImpGetPercent(SdrGluePoint
& rGP
, const SdrObject
* /*pObj*/, const void* pbFirst
, const void* pnRet
, const void*, const void*, const void*)
148 USHORT
& nRet
=*(USHORT
*)pnRet
;
149 BOOL
& bFirst
=*(BOOL
*)pbFirst
;
151 bool bOn
=rGP
.IsPercent();
152 if (bFirst
) { nRet
=bOn
; bFirst
=FALSE
; }
153 else if ((nRet
!=0)!=bOn
) nRet
=FUZZY
;
157 TRISTATE
SdrGlueEditView::IsMarkedGluePointsPercent() const
159 ForceUndirtyMrkPnt();
162 ((SdrGlueEditView
*)this)->ImpDoMarkedGluePoints(ImpGetPercent
,TRUE
,&bFirst
,&nRet
);
163 return (TRISTATE
)nRet
;
166 static void ImpSetPercent(SdrGluePoint
& rGP
, const SdrObject
* pObj
, const void* pbOn
, const void*, const void*, const void*, const void*)
168 Point
aPos(rGP
.GetAbsolutePos(*pObj
));
169 rGP
.SetPercent(*(BOOL
*)pbOn
);
170 rGP
.SetAbsolutePos(aPos
,*pObj
);
173 void SdrGlueEditView::SetMarkedGluePointsPercent(BOOL bOn
)
175 ForceUndirtyMrkPnt();
176 BegUndo(ImpGetResStr(STR_EditSetGluePercent
),GetDescriptionOfMarkedGluePoints());
177 ImpDoMarkedGluePoints(ImpSetPercent
,FALSE
,&bOn
);
181 ////////////////////////////////////////////////////////////////////////////////////////////////////
183 static void ImpGetAlign(SdrGluePoint
& rGP
, const SdrObject
* /*pObj*/, const void* pbFirst
, const void* pbDontCare
, const void* pbVert
, const void* pnRet
, const void*)
185 USHORT
& nRet
=*(USHORT
*)pnRet
;
186 BOOL
& bFirst
=*(BOOL
*)pbFirst
;
187 BOOL
& bDontCare
=*(BOOL
*)pbDontCare
;
188 BOOL bVert
=*(BOOL
*)pbVert
;
192 nAlg
=rGP
.GetVertAlign();
194 nAlg
=rGP
.GetHorzAlign();
196 if (bFirst
) { nRet
=nAlg
; bFirst
=FALSE
; }
197 else if (nRet
!=nAlg
) {
199 nRet
=SDRVERTALIGN_DONTCARE
;
201 nRet
=SDRHORZALIGN_DONTCARE
;
208 USHORT
SdrGlueEditView::GetMarkedGluePointsAlign(BOOL bVert
) const
210 ForceUndirtyMrkPnt();
212 BOOL bDontCare
=FALSE
;
214 ((SdrGlueEditView
*)this)->ImpDoMarkedGluePoints(ImpGetAlign
,TRUE
,&bFirst
,&bDontCare
,&bVert
,&nRet
);
218 static void ImpSetAlign(SdrGluePoint
& rGP
, const SdrObject
* pObj
, const void* pbVert
, const void* pnAlign
, const void*, const void*, const void*)
220 Point
aPos(rGP
.GetAbsolutePos(*pObj
));
221 if (*(BOOL
*)pbVert
) { // bVert?
222 rGP
.SetVertAlign(*(USHORT
*)pnAlign
);
224 rGP
.SetHorzAlign(*(USHORT
*)pnAlign
);
226 rGP
.SetAbsolutePos(aPos
,*pObj
);
229 void SdrGlueEditView::SetMarkedGluePointsAlign(BOOL bVert
, USHORT nAlign
)
231 ForceUndirtyMrkPnt();
232 BegUndo(ImpGetResStr(STR_EditSetGlueAlign
),GetDescriptionOfMarkedGluePoints());
233 ImpDoMarkedGluePoints(ImpSetAlign
,FALSE
,&bVert
,&nAlign
);
237 ////////////////////////////////////////////////////////////////////////////////////////////////////
239 BOOL
SdrGlueEditView::IsDeleteMarkedGluePointsPossible() const
241 return HasMarkedGluePoints();
244 void SdrGlueEditView::DeleteMarkedGluePoints()
247 ForceUndirtyMrkPnt();
248 const bool bUndo
= IsUndoEnabled();
250 BegUndo(ImpGetResStr(STR_EditDelete
),GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_DELETE
);
252 ULONG nMarkAnz
=GetMarkedObjectCount();
253 for (ULONG nm
=0; nm
<nMarkAnz
; nm
++)
255 SdrMark
* pM
=GetSdrMarkByIndex(nm
);
256 SdrObject
* pObj
=pM
->GetMarkedSdrObj();
257 const SdrUShortCont
* pPts
=pM
->GetMarkedGluePoints();
258 ULONG nPtAnz
=pPts
==NULL
? 0 : pPts
->GetCount();
261 SdrGluePointList
* pGPL
=pObj
->ForceGluePointList();
265 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
267 for (ULONG nPtNum
=0; nPtNum
<nPtAnz
; nPtNum
++)
269 USHORT nPtId
=pPts
->GetObject(nPtNum
);
270 USHORT nGlueIdx
=pGPL
->FindGluePoint(nPtId
);
271 if (nGlueIdx
!=SDRGLUEPOINT_NOTFOUND
)
273 pGPL
->Delete(nGlueIdx
);
277 pObj
->BroadcastObjectChange();
283 UnmarkAllGluePoints();
288 ////////////////////////////////////////////////////////////////////////////////////////////////////
290 void SdrGlueEditView::ImpCopyMarkedGluePoints()
292 const bool bUndo
= IsUndoEnabled();
297 ULONG nMarkAnz
=GetMarkedObjectCount();
298 for (ULONG nm
=0; nm
<nMarkAnz
; nm
++)
300 SdrMark
* pM
=GetSdrMarkByIndex(nm
);
301 SdrObject
* pObj
=pM
->GetMarkedSdrObj();
302 SdrUShortCont
* pPts
=pM
->GetMarkedGluePoints();
303 SdrGluePointList
* pGPL
=pObj
->ForceGluePointList();
304 ULONG nPtAnz
=pPts
==NULL
? 0 : pPts
->GetCount();
305 if (nPtAnz
!=0 && pGPL
!=NULL
)
308 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
310 for (ULONG nPtNum
=0; nPtNum
<nPtAnz
; nPtNum
++)
312 USHORT nPtId
=pPts
->GetObject(nPtNum
);
313 USHORT nGlueIdx
=pGPL
->FindGluePoint(nPtId
);
314 if (nGlueIdx
!=SDRGLUEPOINT_NOTFOUND
)
316 SdrGluePoint
aNewGP((*pGPL
)[nGlueIdx
]); // GluePoint klonen
317 USHORT nNewIdx
=pGPL
->Insert(aNewGP
); // und einfuegen
318 USHORT nNewId
=(*pGPL
)[nNewIdx
].GetId(); // Id des neuen GluePoints ermitteln
319 pPts
->Replace(nNewId
,nPtNum
); // und diesen markieren (anstelle des alten)
331 ////////////////////////////////////////////////////////////////////////////////////////////////////
333 void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc
, const void* p1
, const void* p2
, const void* p3
, const void* p4
, const void* p5
)
335 ULONG nMarkAnz
=GetMarkedObjectCount();
336 for (ULONG nm
=0; nm
<nMarkAnz
; nm
++) {
337 SdrMark
* pM
=GetSdrMarkByIndex(nm
);
338 SdrObject
* pObj
=pM
->GetMarkedSdrObj();
339 const SdrUShortCont
* pPts
=pM
->GetMarkedGluePoints();
340 ULONG nPtAnz
=pPts
==NULL
? 0 : pPts
->GetCount();
342 SdrGluePointList
* pGPL
=pObj
->ForceGluePointList();
345 if( IsUndoEnabled() )
346 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
348 for (ULONG nPtNum
=0; nPtNum
<nPtAnz
; nPtNum
++) {
349 USHORT nPtId
=pPts
->GetObject(nPtNum
);
350 USHORT nGlueIdx
=pGPL
->FindGluePoint(nPtId
);
351 if (nGlueIdx
!=SDRGLUEPOINT_NOTFOUND
) {
352 SdrGluePoint
& rGP
=(*pGPL
)[nGlueIdx
];
353 Point
aPos(rGP
.GetAbsolutePos(*pObj
));
354 (*pTrFunc
)(aPos
,p1
,p2
,p3
,p4
,p5
);
355 rGP
.SetAbsolutePos(aPos
,*pObj
);
359 pObj
->BroadcastObjectChange();
363 if (nMarkAnz
!=0) pMod
->SetChanged();
366 ////////////////////////////////////////////////////////////////////////////////////////////////////
368 static void ImpMove(Point
& rPt
, const void* p1
, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
370 rPt
.X()+=((const Size
*)p1
)->Width();
371 rPt
.Y()+=((const Size
*)p1
)->Height();
374 void SdrGlueEditView::MoveMarkedGluePoints(const Size
& rSiz
, bool bCopy
)
376 ForceUndirtyMrkPnt();
377 XubString
aStr(ImpGetResStr(STR_EditMove
));
378 if (bCopy
) aStr
+=ImpGetResStr(STR_EditWithCopy
);
379 BegUndo(aStr
,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_MOVE
);
380 if (bCopy
) ImpCopyMarkedGluePoints();
381 ImpTransformMarkedGluePoints(ImpMove
,&rSiz
);
386 ////////////////////////////////////////////////////////////////////////////////////////////////////
388 static void ImpResize(Point
& rPt
, const void* p1
, const void* p2
, const void* p3
, const void* /*p4*/, const void* /*p5*/)
390 ResizePoint(rPt
,*(const Point
*)p1
,*(const Fraction
*)p2
,*(const Fraction
*)p3
);
393 void SdrGlueEditView::ResizeMarkedGluePoints(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
, bool bCopy
)
395 ForceUndirtyMrkPnt();
396 XubString
aStr(ImpGetResStr(STR_EditResize
));
397 if (bCopy
) aStr
+=ImpGetResStr(STR_EditWithCopy
);
398 BegUndo(aStr
,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_RESIZE
);
399 if (bCopy
) ImpCopyMarkedGluePoints();
400 ImpTransformMarkedGluePoints(ImpResize
,&rRef
,&xFact
,&yFact
);
405 ////////////////////////////////////////////////////////////////////////////////////////////////////
407 static void ImpRotate(Point
& rPt
, const void* p1
, const void* /*p2*/, const void* p3
, const void* p4
, const void* /*p5*/)
409 RotatePoint(rPt
,*(const Point
*)p1
,*(const double*)p3
,*(const double*)p4
);
412 void SdrGlueEditView::RotateMarkedGluePoints(const Point
& rRef
, long nWink
, bool bCopy
)
414 ForceUndirtyMrkPnt();
415 XubString
aStr(ImpGetResStr(STR_EditRotate
));
416 if (bCopy
) aStr
+=ImpGetResStr(STR_EditWithCopy
);
417 BegUndo(aStr
,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_ROTATE
);
418 if (bCopy
) ImpCopyMarkedGluePoints();
419 double nSin
=sin(nWink
*nPi180
);
420 double nCos
=cos(nWink
*nPi180
);
421 ImpTransformMarkedGluePoints(ImpRotate
,&rRef
,&nWink
,&nSin
,&nCos
);