Line data Source code
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 : #include "svddrgm1.hxx"
21 : #include <math.h>
22 :
23 : #ifndef _MATH_H
24 : #define _MATH_H
25 : #endif
26 : #include <tools/bigint.hxx>
27 : #include <vcl/svapp.hxx>
28 :
29 : #include "svx/xattr.hxx"
30 : #include <svx/xpoly.hxx>
31 : #include <svx/svdetc.hxx>
32 : #include <svx/svdtrans.hxx>
33 : #include <svx/svdundo.hxx>
34 : #include <svx/svdmark.hxx>
35 : #include <svx/svdocapt.hxx>
36 : #include <svx/svdpagv.hxx>
37 : #include "svx/svdstr.hrc" // names taken from the resource
38 : #include "svx/svdglob.hxx" // StringCache
39 : #include <svx/svddrgv.hxx>
40 : #include <svx/svdograf.hxx>
41 : #include <svx/dialogs.hrc>
42 : #include <svx/dialmgr.hxx>
43 : #include <svx/sdgcpitm.hxx>
44 : #include <basegfx/polygon/b2dpolygon.hxx>
45 : #include <basegfx/polygon/b2dpolygontools.hxx>
46 : #include <svx/sdr/overlay/overlaypolypolygon.hxx>
47 : #include <svx/sdr/overlay/overlaymanager.hxx>
48 : #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
49 : #include <svx/sdrpagewindow.hxx>
50 : #include <svx/sdrpaintwindow.hxx>
51 : #include <basegfx/matrix/b2dhommatrix.hxx>
52 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
53 : #include <svx/sdr/contact/viewobjectcontact.hxx>
54 : #include <svx/sdr/contact/viewcontact.hxx>
55 : #include <svx/sdr/contact/displayinfo.hxx>
56 : #include <svx/sdr/overlay/overlayprimitive2dsequenceobject.hxx>
57 : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
58 : #include <svx/sdr/contact/objectcontact.hxx>
59 : #include "svx/svditer.hxx"
60 : #include <svx/svdopath.hxx>
61 : #include <svx/polypolygoneditor.hxx>
62 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
63 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
64 : #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
65 : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
66 : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
67 : #include <svx/svdoole2.hxx>
68 : #include <svx/svdovirt.hxx>
69 : #include <svx/svdouno.hxx>
70 : #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
71 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
72 : #include <drawinglayer/attribute/sdrlineattribute.hxx>
73 : #include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
74 :
75 : ////////////////////////////////////////////////////////////////////////////////////////////////////
76 :
77 0 : SdrDragEntry::SdrDragEntry()
78 0 : : mbAddToTransparent(false)
79 : {
80 0 : }
81 :
82 0 : SdrDragEntry::~SdrDragEntry()
83 : {
84 0 : }
85 :
86 : ////////////////////////////////////////////////////////////////////////////////////////////////////
87 :
88 0 : SdrDragEntryPolyPolygon::SdrDragEntryPolyPolygon(const basegfx::B2DPolyPolygon& rOriginalPolyPolygon)
89 : : SdrDragEntry(),
90 0 : maOriginalPolyPolygon(rOriginalPolyPolygon)
91 : {
92 0 : }
93 :
94 0 : SdrDragEntryPolyPolygon::~SdrDragEntryPolyPolygon()
95 : {
96 0 : }
97 :
98 0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPolyPolygon::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
99 : {
100 0 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
101 :
102 0 : if(maOriginalPolyPolygon.count())
103 : {
104 0 : basegfx::B2DPolyPolygon aCopy(maOriginalPolyPolygon);
105 0 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
106 :
107 0 : rDragMethod.applyCurrentTransformationToPolyPolygon(aCopy);
108 0 : basegfx::BColor aColA(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
109 0 : basegfx::BColor aColB(aSvtOptionsDrawinglayer.GetStripeColorB().getBColor());
110 0 : const double fStripeLength(aSvtOptionsDrawinglayer.GetStripeLength());
111 :
112 0 : if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
113 : {
114 0 : aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
115 0 : aColB.invert();
116 : }
117 :
118 : drawinglayer::primitive2d::Primitive2DReference aPolyPolygonMarkerPrimitive2D(
119 0 : new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D(aCopy, aColA, aColB, fStripeLength));
120 :
121 0 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aPolyPolygonMarkerPrimitive2D, 1);
122 : }
123 :
124 0 : return aRetval;
125 : }
126 :
127 : ////////////////////////////////////////////////////////////////////////////////////////////////////
128 :
129 0 : SdrDragEntrySdrObject::SdrDragEntrySdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool bModify)
130 : : SdrDragEntry(),
131 : maOriginal(rOriginal),
132 : mpClone(0),
133 : mrObjectContact(rObjectContact),
134 0 : mbModify(bModify)
135 : {
136 : // add SdrObject parts to transparent overlay stuff
137 0 : setAddToTransparent(true);
138 0 : }
139 :
140 0 : SdrDragEntrySdrObject::~SdrDragEntrySdrObject()
141 : {
142 0 : if(mpClone)
143 : {
144 0 : SdrObject::Free(mpClone);
145 : }
146 0 : }
147 :
148 0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntrySdrObject::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
149 : {
150 : // for the moment, i need to re-create the clone in all cases. I need to figure
151 : // out when clone and original have the same class, so that i can use operator=
152 : // in those cases
153 :
154 0 : const SdrObject* pSource = &maOriginal;
155 :
156 0 : if(mpClone)
157 : {
158 0 : SdrObject::Free(mpClone);
159 0 : mpClone = 0;
160 : }
161 :
162 0 : if(mbModify)
163 : {
164 0 : if(!mpClone)
165 : {
166 0 : mpClone = maOriginal.getFullDragClone();
167 : }
168 :
169 : // apply original transformation, implemented at the DragMethods
170 0 : rDragMethod.applyCurrentTransformationToSdrObject(*mpClone);
171 :
172 : // choose source for geometry data
173 0 : pSource = mpClone;
174 : }
175 :
176 : // get VOC and Primitive2DSequence
177 0 : sdr::contact::ViewContact& rVC = pSource->GetViewContact();
178 0 : sdr::contact::ViewObjectContact& rVOC = rVC.GetViewObjectContact(mrObjectContact);
179 0 : sdr::contact::DisplayInfo aDisplayInfo;
180 :
181 : // Do not use the last ViewPort set at the OC from the last ProcessDisplay(),
182 : // here we want the complete primitive sequence without visibility clippings
183 0 : mrObjectContact.resetViewPort();
184 :
185 0 : return rVOC.getPrimitive2DSequenceHierarchy(aDisplayInfo);
186 : }
187 :
188 : ////////////////////////////////////////////////////////////////////////////////////////////////////
189 :
190 0 : SdrDragEntryPrimitive2DSequence::SdrDragEntryPrimitive2DSequence(
191 : const drawinglayer::primitive2d::Primitive2DSequence& rSequence,
192 : bool bAddToTransparent)
193 : : SdrDragEntry(),
194 0 : maPrimitive2DSequence(rSequence)
195 : {
196 : // add parts to transparent overlay stuff if necessary
197 0 : setAddToTransparent(bAddToTransparent);
198 0 : }
199 :
200 0 : SdrDragEntryPrimitive2DSequence::~SdrDragEntryPrimitive2DSequence()
201 : {
202 0 : }
203 :
204 0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPrimitive2DSequence::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
205 : {
206 : drawinglayer::primitive2d::Primitive2DReference aTransformPrimitive2D(
207 : new drawinglayer::primitive2d::TransformPrimitive2D(
208 0 : rDragMethod.getCurrentTransformation(),
209 0 : maPrimitive2DSequence));
210 :
211 0 : return drawinglayer::primitive2d::Primitive2DSequence(&aTransformPrimitive2D, 1);
212 : }
213 :
214 : ////////////////////////////////////////////////////////////////////////////////////////////////////
215 :
216 0 : SdrDragEntryPointGlueDrag::SdrDragEntryPointGlueDrag(const std::vector< basegfx::B2DPoint >& rPositions, bool bIsPointDrag)
217 : : maPositions(rPositions),
218 0 : mbIsPointDrag(bIsPointDrag)
219 : {
220 : // add SdrObject parts to transparent overlay stuff
221 0 : setAddToTransparent(true);
222 0 : }
223 :
224 0 : SdrDragEntryPointGlueDrag::~SdrDragEntryPointGlueDrag()
225 : {
226 0 : }
227 :
228 0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPointGlueDrag::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
229 : {
230 0 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
231 :
232 0 : if(!maPositions.empty())
233 : {
234 0 : basegfx::B2DPolygon aPolygon;
235 0 : sal_uInt32 a(0);
236 :
237 0 : for(a = 0; a < maPositions.size(); a++)
238 : {
239 0 : aPolygon.append(maPositions[a]);
240 : }
241 :
242 0 : basegfx::B2DPolyPolygon aPolyPolygon(aPolygon);
243 :
244 0 : rDragMethod.applyCurrentTransformationToPolyPolygon(aPolyPolygon);
245 :
246 0 : const basegfx::B2DPolygon aTransformed(aPolyPolygon.getB2DPolygon(0));
247 0 : std::vector< basegfx::B2DPoint > aTransformedPositions;
248 :
249 0 : aTransformedPositions.reserve(aTransformed.count());
250 :
251 0 : for(a = 0; a < aTransformed.count(); a++)
252 : {
253 0 : aTransformedPositions.push_back(aTransformed.getB2DPoint(a));
254 : }
255 :
256 0 : if(mbIsPointDrag)
257 : {
258 0 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
259 0 : basegfx::BColor aColor(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
260 :
261 0 : if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
262 : {
263 0 : aColor = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
264 : }
265 :
266 : drawinglayer::primitive2d::Primitive2DReference aMarkerArrayPrimitive2D(
267 : new drawinglayer::primitive2d::MarkerArrayPrimitive2D(aTransformedPositions,
268 0 : drawinglayer::primitive2d::createDefaultCross_3x3(aColor)));
269 :
270 0 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aMarkerArrayPrimitive2D, 1);
271 : }
272 : else
273 : {
274 : drawinglayer::primitive2d::Primitive2DReference aMarkerArrayPrimitive2D(
275 : new drawinglayer::primitive2d::MarkerArrayPrimitive2D(aTransformedPositions,
276 0 : SdrHdl::createGluePointBitmap()));
277 0 : aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aMarkerArrayPrimitive2D, 1);
278 0 : }
279 : }
280 :
281 0 : return aRetval;
282 : }
283 :
284 : ////////////////////////////////////////////////////////////////////////////////////////////////////
285 :
286 0 : TYPEINIT0(SdrDragMethod);
287 :
288 0 : void SdrDragMethod::resetSdrDragEntries()
289 : {
290 : // clear entries; creation is on demand
291 0 : clearSdrDragEntries();
292 0 : }
293 :
294 0 : basegfx::B2DRange SdrDragMethod::getCurrentRange() const
295 : {
296 0 : return getB2DRangeFromOverlayObjectList();
297 : }
298 :
299 0 : void SdrDragMethod::createSdrDragEntries()
300 : {
301 0 : if(getSdrDragView().GetSdrPageView() && getSdrDragView().GetSdrPageView()->HasMarkedObjPageView())
302 : {
303 0 : if(getSdrDragView().IsDraggingPoints())
304 : {
305 0 : createSdrDragEntries_PointDrag();
306 : }
307 0 : else if(getSdrDragView().IsDraggingGluePoints())
308 : {
309 0 : createSdrDragEntries_GlueDrag();
310 : }
311 : else
312 : {
313 0 : if(getSolidDraggingActive())
314 : {
315 0 : createSdrDragEntries_SolidDrag();
316 : }
317 : else
318 : {
319 0 : createSdrDragEntries_PolygonDrag();
320 : }
321 : }
322 : }
323 0 : }
324 :
325 0 : void SdrDragMethod::createSdrDragEntryForSdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool bModify)
326 : {
327 : // add full object drag; Clone() at the object has to work
328 : // for this
329 0 : addSdrDragEntry(new SdrDragEntrySdrObject(rOriginal, rObjectContact, bModify));
330 0 : }
331 :
332 0 : void SdrDragMethod::createSdrDragEntries_SolidDrag()
333 : {
334 0 : const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
335 0 : SdrPageView* pPV = getSdrDragView().GetSdrPageView();
336 :
337 0 : if(pPV)
338 : {
339 0 : for(sal_uInt32 a(0); a < nMarkAnz; a++)
340 : {
341 0 : SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(a);
342 :
343 0 : if(pM->GetPageView() == pPV)
344 : {
345 0 : const SdrObject* pObject = pM->GetMarkedSdrObj();
346 :
347 0 : if(pObject)
348 : {
349 0 : if(pPV->PageWindowCount())
350 : {
351 0 : sdr::contact::ObjectContact& rOC = pPV->GetPageWindow(0)->GetObjectContact();
352 0 : SdrObjListIter aIter(*pObject);
353 :
354 0 : while(aIter.IsMore())
355 : {
356 0 : SdrObject* pCandidate = aIter.Next();
357 :
358 0 : if(pCandidate)
359 : {
360 0 : const bool bSuppressFullDrag(!pCandidate->supportsFullDrag());
361 0 : bool bAddWireframe(bSuppressFullDrag);
362 :
363 0 : if(!bAddWireframe && !pCandidate->HasLineStyle())
364 : {
365 : // add wireframe for objects without outline
366 0 : bAddWireframe = true;
367 : }
368 :
369 0 : if(!bSuppressFullDrag)
370 : {
371 : // add full object drag; Clone() at the object has to work
372 : // for this
373 0 : createSdrDragEntryForSdrObject(*pCandidate, rOC, true);
374 : }
375 :
376 0 : if(bAddWireframe)
377 : {
378 : // when dragging a 50% transparent copy of a filled or not filled object without
379 : // outline, this is normally hard to see. Add extra wireframe in that case. This
380 : // works nice e.g. with text frames etc.
381 0 : addSdrDragEntry(new SdrDragEntryPolyPolygon(pCandidate->TakeXorPoly()));
382 : }
383 : }
384 0 : }
385 : }
386 : }
387 : }
388 : }
389 : }
390 0 : }
391 :
392 0 : void SdrDragMethod::createSdrDragEntries_PolygonDrag()
393 : {
394 0 : const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
395 0 : bool bNoPolygons(getSdrDragView().IsNoDragXorPolys() || nMarkAnz > getSdrDragView().GetDragXorPolyLimit());
396 0 : basegfx::B2DPolyPolygon aResult;
397 0 : sal_uInt32 nPointCount(0);
398 :
399 0 : for(sal_uInt32 a(0); !bNoPolygons && a < nMarkAnz; a++)
400 : {
401 0 : SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(a);
402 :
403 0 : if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
404 : {
405 0 : const basegfx::B2DPolyPolygon aNewPolyPolygon(pM->GetMarkedSdrObj()->TakeXorPoly());
406 :
407 0 : for(sal_uInt32 b(0); b < aNewPolyPolygon.count(); b++)
408 : {
409 0 : nPointCount += aNewPolyPolygon.getB2DPolygon(b).count();
410 : }
411 :
412 0 : if(nPointCount > getSdrDragView().GetDragXorPointLimit())
413 : {
414 0 : bNoPolygons = true;
415 : }
416 :
417 0 : if(!bNoPolygons)
418 : {
419 0 : aResult.append(aNewPolyPolygon);
420 0 : }
421 : }
422 : }
423 :
424 0 : if(bNoPolygons)
425 : {
426 0 : const Rectangle aR(getSdrDragView().GetSdrPageView()->MarkSnap());
427 0 : const basegfx::B2DRange aNewRectangle(aR.Left(), aR.Top(), aR.Right(), aR.Bottom());
428 0 : basegfx::B2DPolygon aNewPolygon(basegfx::tools::createPolygonFromRect(aNewRectangle));
429 :
430 0 : aResult = basegfx::B2DPolyPolygon(basegfx::tools::expandToCurve(aNewPolygon));
431 : }
432 :
433 0 : if(aResult.count())
434 : {
435 0 : addSdrDragEntry(new SdrDragEntryPolyPolygon(aResult));
436 0 : }
437 0 : }
438 :
439 0 : void SdrDragMethod::createSdrDragEntries_PointDrag()
440 : {
441 0 : const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
442 0 : std::vector< basegfx::B2DPoint > aPositions;
443 :
444 0 : for(sal_uInt32 nm(0); nm < nMarkAnz; nm++)
445 : {
446 0 : SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(nm);
447 :
448 0 : if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
449 : {
450 0 : const SdrUShortCont* pPts = pM->GetMarkedPoints();
451 :
452 0 : if(pPts && !pPts->empty())
453 : {
454 0 : const SdrObject* pObj = pM->GetMarkedSdrObj();
455 0 : const SdrPathObj* pPath = dynamic_cast< const SdrPathObj* >(pObj);
456 :
457 0 : if(pPath)
458 : {
459 0 : const basegfx::B2DPolyPolygon aPathXPP = pPath->GetPathPoly();
460 :
461 0 : if(aPathXPP.count())
462 : {
463 0 : for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
464 : {
465 : sal_uInt32 nPolyNum, nPointNum;
466 0 : const sal_uInt16 nObjPt = *it;
467 :
468 0 : if(sdr::PolyPolygonEditor::GetRelativePolyPoint(aPathXPP, nObjPt, nPolyNum, nPointNum))
469 : {
470 0 : aPositions.push_back(aPathXPP.getB2DPolygon(nPolyNum).getB2DPoint(nPointNum));
471 : }
472 : }
473 0 : }
474 : }
475 : }
476 : }
477 : }
478 :
479 0 : if(!aPositions.empty())
480 : {
481 0 : addSdrDragEntry(new SdrDragEntryPointGlueDrag(aPositions, true));
482 0 : }
483 0 : }
484 :
485 0 : void SdrDragMethod::createSdrDragEntries_GlueDrag()
486 : {
487 0 : const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
488 0 : std::vector< basegfx::B2DPoint > aPositions;
489 :
490 0 : for(sal_uInt32 nm(0); nm < nMarkAnz; nm++)
491 : {
492 0 : SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(nm);
493 :
494 0 : if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
495 : {
496 0 : const SdrUShortCont* pPts = pM->GetMarkedGluePoints();
497 :
498 0 : if(pPts && !pPts->empty())
499 : {
500 0 : const SdrObject* pObj = pM->GetMarkedSdrObj();
501 0 : const SdrGluePointList* pGPL = pObj->GetGluePointList();
502 :
503 0 : if(pGPL)
504 : {
505 0 : for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
506 : {
507 0 : const sal_uInt16 nObjPt = *it;
508 0 : const sal_uInt16 nGlueNum(pGPL->FindGluePoint(nObjPt));
509 :
510 0 : if(SDRGLUEPOINT_NOTFOUND != nGlueNum)
511 : {
512 0 : const Point aPoint((*pGPL)[nGlueNum].GetAbsolutePos(*pObj));
513 0 : aPositions.push_back(basegfx::B2DPoint(aPoint.X(), aPoint.Y()));
514 : }
515 : }
516 : }
517 : }
518 : }
519 : }
520 :
521 0 : if(!aPositions.empty())
522 : {
523 0 : addSdrDragEntry(new SdrDragEntryPointGlueDrag(aPositions, false));
524 0 : }
525 0 : }
526 :
527 0 : void SdrDragMethod::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, XubString& rStr, sal_uInt16 nVal) const
528 : {
529 0 : sal_uInt16 nOpt=0;
530 0 : if (IsDraggingPoints()) {
531 0 : nOpt=IMPSDR_POINTSDESCRIPTION;
532 0 : } else if (IsDraggingGluePoints()) {
533 0 : nOpt=IMPSDR_GLUEPOINTSDESCRIPTION;
534 : }
535 0 : getSdrDragView().ImpTakeDescriptionStr(nStrCacheID,rStr,nVal,nOpt);
536 0 : }
537 :
538 0 : SdrObject* SdrDragMethod::GetDragObj() const
539 : {
540 0 : SdrObject* pObj=NULL;
541 0 : if (getSdrDragView().pDragHdl!=NULL) pObj=getSdrDragView().pDragHdl->GetObj();
542 0 : if (pObj==NULL) pObj=getSdrDragView().pMarkedObj;
543 0 : return pObj;
544 : }
545 :
546 0 : SdrPageView* SdrDragMethod::GetDragPV() const
547 : {
548 0 : SdrPageView* pPV=NULL;
549 0 : if (getSdrDragView().pDragHdl!=NULL) pPV=getSdrDragView().pDragHdl->GetPageView();
550 0 : if (pPV==NULL) pPV=getSdrDragView().pMarkedPV;
551 0 : return pPV;
552 : }
553 :
554 0 : void SdrDragMethod::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
555 : {
556 : // the original applies the transformation using TRGetBaseGeometry/TRSetBaseGeometry.
557 : // Later this should be the only needed one for linear transforms (not for SdrDragCrook and
558 : // SdrDragDistort, those are NOT linear). Currently, this can not yet be used since the
559 : // special handling of rotate/mirror due to the not-being-able to handle it in the old
560 : // drawinglayer stuff. Text would currently not correctly be mirrored in the preview.
561 0 : basegfx::B2DHomMatrix aObjectTransform;
562 0 : basegfx::B2DPolyPolygon aObjectPolyPolygon;
563 0 : bool bPolyUsed(rTarget.TRGetBaseGeometry(aObjectTransform, aObjectPolyPolygon));
564 :
565 : // apply transform to object transform
566 0 : aObjectTransform *= getCurrentTransformation();
567 :
568 0 : if(bPolyUsed)
569 : {
570 : // do something special since the object size is in the polygon
571 : // break up matrix to get the scale
572 0 : basegfx::B2DTuple aScale;
573 0 : basegfx::B2DTuple aTranslate;
574 : double fRotate, fShearX;
575 0 : aObjectTransform.decompose(aScale, aTranslate, fRotate, fShearX);
576 :
577 : // get polygon's position and size
578 0 : const basegfx::B2DRange aPolyRange(aObjectPolyPolygon.getB2DRange());
579 :
580 : // get the scaling factors (do not mirror, this is in the object transformation)
581 0 : const double fScaleX(fabs(aScale.getX()) / (basegfx::fTools::equalZero(aPolyRange.getWidth()) ? 1.0 : aPolyRange.getWidth()));
582 0 : const double fScaleY(fabs(aScale.getY()) / (basegfx::fTools::equalZero(aPolyRange.getHeight()) ? 1.0 : aPolyRange.getHeight()));
583 :
584 : // prepare transform matrix for polygon
585 : basegfx::B2DHomMatrix aPolyTransform(basegfx::tools::createTranslateB2DHomMatrix(
586 0 : -aPolyRange.getMinX(), -aPolyRange.getMinY()));
587 0 : aPolyTransform.scale(fScaleX, fScaleY);
588 :
589 : // transform the polygon
590 0 : aObjectPolyPolygon.transform(aPolyTransform);
591 : }
592 :
593 0 : rTarget.TRSetBaseGeometry(getCurrentTransformation() * aObjectTransform, aObjectPolyPolygon);
594 0 : }
595 :
596 0 : void SdrDragMethod::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
597 : {
598 : // original uses CurrentTransformation
599 0 : rTarget.transform(getCurrentTransformation());
600 0 : }
601 :
602 0 : SdrDragMethod::SdrDragMethod(SdrDragView& rNewView)
603 : : maSdrDragEntries(),
604 : maOverlayObjectList(),
605 : mrSdrDragView(rNewView),
606 : mbMoveOnly(false),
607 0 : mbSolidDraggingActive(getSdrDragView().IsSolidDragging())
608 : {
609 0 : if(mbSolidDraggingActive && Application::GetSettings().GetStyleSettings().GetHighContrastMode())
610 : {
611 : // fallback to wireframe when high contrast is used
612 0 : mbSolidDraggingActive = false;
613 : }
614 0 : }
615 :
616 0 : SdrDragMethod::~SdrDragMethod()
617 : {
618 0 : clearSdrDragEntries();
619 0 : }
620 :
621 0 : void SdrDragMethod::Show()
622 : {
623 0 : getSdrDragView().ShowDragObj();
624 0 : }
625 :
626 0 : void SdrDragMethod::Hide()
627 : {
628 0 : getSdrDragView().HideDragObj();
629 0 : }
630 :
631 0 : basegfx::B2DHomMatrix SdrDragMethod::getCurrentTransformation()
632 : {
633 0 : return basegfx::B2DHomMatrix();
634 : }
635 :
636 0 : void SdrDragMethod::CancelSdrDrag()
637 : {
638 0 : Hide();
639 0 : }
640 :
641 0 : void SdrDragMethod::CreateOverlayGeometry(sdr::overlay::OverlayManager& rOverlayManager)
642 : {
643 : // create SdrDragEntries on demand
644 0 : if(maSdrDragEntries.empty())
645 : {
646 0 : createSdrDragEntries();
647 : }
648 :
649 : // if there are entries, derive OverlayObjects from the entries, including
650 : // modification from current interactive state
651 0 : if(!maSdrDragEntries.empty())
652 : {
653 0 : drawinglayer::primitive2d::Primitive2DSequence aResult;
654 0 : drawinglayer::primitive2d::Primitive2DSequence aResultTransparent;
655 :
656 0 : for(sal_uInt32 a(0); a < maSdrDragEntries.size(); a++)
657 : {
658 0 : SdrDragEntry* pCandidate = maSdrDragEntries[a];
659 :
660 0 : if(pCandidate)
661 : {
662 0 : const drawinglayer::primitive2d::Primitive2DSequence aCandidateResult(pCandidate->createPrimitive2DSequenceInCurrentState(*this));
663 :
664 0 : if(aCandidateResult.hasElements())
665 : {
666 0 : if(pCandidate->getAddToTransparent())
667 : {
668 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResultTransparent, aCandidateResult);
669 : }
670 : else
671 : {
672 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResult, aCandidateResult);
673 : }
674 0 : }
675 : }
676 : }
677 :
678 0 : if(DoAddConnectorOverlays())
679 : {
680 0 : const drawinglayer::primitive2d::Primitive2DSequence aConnectorOverlays(AddConnectorOverlays());
681 :
682 0 : if(aConnectorOverlays.hasElements())
683 : {
684 : // add connector overlays to transparent part
685 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResultTransparent, aConnectorOverlays);
686 0 : }
687 : }
688 :
689 0 : if(aResult.hasElements())
690 : {
691 0 : sdr::overlay::OverlayObject* pNewOverlayObject = new sdr::overlay::OverlayPrimitive2DSequenceObject(aResult);
692 0 : rOverlayManager.add(*pNewOverlayObject);
693 0 : addToOverlayObjectList(*pNewOverlayObject);
694 : }
695 :
696 0 : if(aResultTransparent.hasElements())
697 : {
698 0 : drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparencePrimitive2D(new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(aResultTransparent, 0.5));
699 0 : aResultTransparent = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparencePrimitive2D, 1);
700 :
701 0 : sdr::overlay::OverlayObject* pNewOverlayObject = new sdr::overlay::OverlayPrimitive2DSequenceObject(aResultTransparent);
702 0 : rOverlayManager.add(*pNewOverlayObject);
703 0 : addToOverlayObjectList(*pNewOverlayObject);
704 0 : }
705 : }
706 :
707 : // add DragStripes if necessary (help lines cross the page when dragging)
708 0 : if(getSdrDragView().IsDragStripes())
709 : {
710 0 : Rectangle aActionRectangle;
711 0 : getSdrDragView().TakeActionRect(aActionRectangle);
712 :
713 0 : const basegfx::B2DPoint aTopLeft(aActionRectangle.Left(), aActionRectangle.Top());
714 0 : const basegfx::B2DPoint aBottomRight(aActionRectangle.Right(), aActionRectangle.Bottom());
715 : sdr::overlay::OverlayRollingRectangleStriped* pNew = new sdr::overlay::OverlayRollingRectangleStriped(
716 0 : aTopLeft, aBottomRight, true, false);
717 :
718 0 : rOverlayManager.add(*pNew);
719 0 : addToOverlayObjectList(*pNew);
720 : }
721 0 : }
722 :
723 0 : void SdrDragMethod::destroyOverlayGeometry()
724 : {
725 0 : clearOverlayObjectList();
726 0 : }
727 :
728 0 : bool SdrDragMethod::DoAddConnectorOverlays()
729 : {
730 : // these conditions are translated from SdrDragView::ImpDrawEdgeXor
731 0 : const SdrMarkList& rMarkedNodes = getSdrDragView().GetEdgesOfMarkedNodes();
732 :
733 0 : if(!rMarkedNodes.GetMarkCount())
734 : {
735 0 : return false;
736 : }
737 :
738 0 : if(!getSdrDragView().IsRubberEdgeDragging() && !getSdrDragView().IsDetailedEdgeDragging())
739 : {
740 0 : return false;
741 : }
742 :
743 0 : if(getSdrDragView().IsDraggingPoints() || getSdrDragView().IsDraggingGluePoints())
744 : {
745 0 : return false;
746 : }
747 :
748 0 : if(!getMoveOnly() && !(
749 0 : IS_TYPE(SdrDragMove, this) || IS_TYPE(SdrDragResize, this) ||
750 0 : IS_TYPE(SdrDragRotate,this) || IS_TYPE(SdrDragMirror,this)))
751 : {
752 0 : return false;
753 : }
754 :
755 0 : const bool bDetail(getSdrDragView().IsDetailedEdgeDragging() && getMoveOnly());
756 :
757 0 : if(!bDetail && !getSdrDragView().IsRubberEdgeDragging())
758 : {
759 0 : return false;
760 : }
761 :
762 : // one more migrated from SdrEdgeObj::NspToggleEdgeXor
763 0 : if(IS_TYPE(SdrDragObjOwn, this) || IS_TYPE(SdrDragMovHdl, this))
764 : {
765 0 : return false;
766 : }
767 :
768 0 : return true;
769 : }
770 :
771 0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragMethod::AddConnectorOverlays()
772 : {
773 0 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
774 0 : const bool bDetail(getSdrDragView().IsDetailedEdgeDragging() && getMoveOnly());
775 0 : const SdrMarkList& rMarkedNodes = getSdrDragView().GetEdgesOfMarkedNodes();
776 :
777 0 : for(sal_uInt16 a(0); a < rMarkedNodes.GetMarkCount(); a++)
778 : {
779 0 : SdrMark* pEM = rMarkedNodes.GetMark(a);
780 :
781 0 : if(pEM && pEM->GetMarkedSdrObj())
782 : {
783 0 : SdrEdgeObj* pEdge = dynamic_cast< SdrEdgeObj* >(pEM->GetMarkedSdrObj());
784 :
785 0 : if(pEdge)
786 : {
787 0 : const basegfx::B2DPolygon aEdgePolygon(pEdge->ImplAddConnectorOverlay(*this, pEM->IsCon1(), pEM->IsCon2(), bDetail));
788 :
789 0 : if(aEdgePolygon.count())
790 : {
791 : // this polygon is a temporary calculated connector path, so it is not possible to fetch
792 : // the needed primitives directly from the pEdge object which does not get changed. If full
793 : // drag is on, use the SdrObjects ItemSet to create a adequate representation
794 0 : bool bUseSolidDragging(getSolidDraggingActive());
795 :
796 0 : if(bUseSolidDragging)
797 : {
798 : // switch off solid dragging if connector is not visible
799 0 : if(!pEdge->HasLineStyle())
800 : {
801 0 : bUseSolidDragging = false;
802 : }
803 : }
804 :
805 0 : if(bUseSolidDragging)
806 : {
807 0 : const SfxItemSet& rItemSet = pEdge->GetMergedItemSet();
808 : const drawinglayer::attribute::SdrLineAttribute aLine(
809 0 : drawinglayer::primitive2d::createNewSdrLineAttribute(rItemSet));
810 :
811 0 : if(!aLine.isDefault())
812 : {
813 : const drawinglayer::attribute::SdrLineStartEndAttribute aLineStartEnd(
814 : drawinglayer::primitive2d::createNewSdrLineStartEndAttribute(
815 : rItemSet,
816 0 : aLine.getWidth()));
817 :
818 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
819 : aRetval, drawinglayer::primitive2d::createPolygonLinePrimitive(
820 : aEdgePolygon,
821 : basegfx::B2DHomMatrix(),
822 : aLine,
823 0 : aLineStartEnd));
824 0 : }
825 : }
826 : else
827 : {
828 0 : const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
829 0 : basegfx::BColor aColA(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
830 0 : basegfx::BColor aColB(aSvtOptionsDrawinglayer.GetStripeColorB().getBColor());
831 0 : const double fStripeLength(aSvtOptionsDrawinglayer.GetStripeLength());
832 :
833 0 : if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
834 : {
835 0 : aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
836 0 : aColB.invert();
837 : }
838 :
839 : drawinglayer::primitive2d::Primitive2DReference aPolyPolygonMarkerPrimitive2D(
840 : new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D(
841 0 : basegfx::B2DPolyPolygon(aEdgePolygon), aColA, aColB, fStripeLength));
842 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aPolyPolygonMarkerPrimitive2D);
843 : }
844 0 : }
845 : }
846 : }
847 : }
848 :
849 0 : return aRetval;
850 : }
851 :
852 : ////////////////////////////////////////////////////////////////////////////////////////////////////
853 :
854 0 : TYPEINIT1(SdrDragMovHdl,SdrDragMethod);
855 :
856 0 : SdrDragMovHdl::SdrDragMovHdl(SdrDragView& rNewView)
857 0 : : SdrDragMethod(rNewView)
858 : {
859 0 : }
860 :
861 0 : void SdrDragMovHdl::createSdrDragEntries()
862 : {
863 : // SdrDragMovHdl does not use the default drags,
864 : // but creates nothing
865 0 : }
866 :
867 0 : void SdrDragMovHdl::TakeSdrDragComment(XubString& rStr) const
868 : {
869 0 : rStr=ImpGetResStr(STR_DragMethMovHdl);
870 0 : if (getSdrDragView().IsDragWithCopy()) rStr+=ImpGetResStr(STR_EditWithCopy);
871 0 : }
872 :
873 0 : bool SdrDragMovHdl::BeginSdrDrag()
874 : {
875 0 : if( !GetDragHdl() )
876 0 : return false;
877 :
878 0 : DragStat().Ref1()=GetDragHdl()->GetPos();
879 0 : DragStat().SetShown(!DragStat().IsShown());
880 0 : SdrHdlKind eKind=GetDragHdl()->GetKind();
881 0 : SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
882 0 : SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
883 :
884 0 : if (eKind==HDL_MIRX)
885 : {
886 0 : if (pH1==NULL || pH2==NULL)
887 : {
888 : OSL_FAIL("SdrDragMovHdl::BeginSdrDrag(): Moving the axis of reflection: reference handles not found.");
889 0 : return false;
890 : }
891 :
892 0 : DragStat().SetActionRect(Rectangle(pH1->GetPos(),pH2->GetPos()));
893 : }
894 : else
895 : {
896 0 : Point aPt(GetDragHdl()->GetPos());
897 0 : DragStat().SetActionRect(Rectangle(aPt,aPt));
898 : }
899 :
900 0 : return true;
901 : }
902 :
903 0 : void SdrDragMovHdl::MoveSdrDrag(const Point& rNoSnapPnt)
904 : {
905 0 : Point aPnt(rNoSnapPnt);
906 :
907 0 : if ( GetDragHdl() && DragStat().CheckMinMoved(rNoSnapPnt))
908 : {
909 0 : if (GetDragHdl()->GetKind()==HDL_MIRX)
910 : {
911 0 : SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
912 0 : SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
913 :
914 0 : if (pH1==NULL || pH2==NULL)
915 0 : return;
916 :
917 0 : if (!DragStat().IsNoSnap())
918 : {
919 0 : long nBestXSnap=0;
920 0 : long nBestYSnap=0;
921 0 : bool bXSnapped=false;
922 0 : bool bYSnapped=false;
923 0 : Point aDif(aPnt-DragStat().GetStart());
924 0 : getSdrDragView().CheckSnap(Ref1()+aDif,NULL,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
925 0 : getSdrDragView().CheckSnap(Ref2()+aDif,NULL,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
926 0 : aPnt.X()+=nBestXSnap;
927 0 : aPnt.Y()+=nBestYSnap;
928 : }
929 :
930 0 : if (aPnt!=DragStat().GetNow())
931 : {
932 0 : Hide();
933 0 : DragStat().NextMove(aPnt);
934 0 : Point aDif(DragStat().GetNow()-DragStat().GetStart());
935 0 : pH1->SetPos(Ref1()+aDif);
936 0 : pH2->SetPos(Ref2()+aDif);
937 :
938 0 : SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
939 :
940 0 : if(pHM)
941 0 : pHM->Touch();
942 :
943 0 : Show();
944 0 : DragStat().SetActionRect(Rectangle(pH1->GetPos(),pH2->GetPos()));
945 : }
946 : }
947 : else
948 : {
949 0 : if (!DragStat().IsNoSnap()) SnapPos(aPnt);
950 0 : long nSA=0;
951 :
952 0 : if (getSdrDragView().IsAngleSnapEnabled())
953 0 : nSA=getSdrDragView().GetSnapAngle();
954 :
955 0 : if (getSdrDragView().IsMirrorAllowed(true,true))
956 : { // limited
957 0 : if (!getSdrDragView().IsMirrorAllowed(false,false)) nSA=4500;
958 0 : if (!getSdrDragView().IsMirrorAllowed(true,false)) nSA=9000;
959 : }
960 :
961 0 : if (getSdrDragView().IsOrtho() && nSA!=9000)
962 0 : nSA=4500;
963 :
964 0 : if (nSA!=0)
965 : { // angle snapping
966 0 : SdrHdlKind eRef=HDL_REF1;
967 :
968 0 : if (GetDragHdl()->GetKind()==HDL_REF1)
969 0 : eRef=HDL_REF2;
970 :
971 0 : SdrHdl* pH=GetHdlList().GetHdl(eRef);
972 :
973 0 : if (pH!=NULL)
974 : {
975 0 : Point aRef(pH->GetPos());
976 0 : long nWink=NormAngle360(GetAngle(aPnt-aRef));
977 0 : long nNeuWink=nWink;
978 0 : nNeuWink+=nSA/2;
979 0 : nNeuWink/=nSA;
980 0 : nNeuWink*=nSA;
981 0 : nNeuWink=NormAngle360(nNeuWink);
982 0 : double a=(nNeuWink-nWink)*nPi180;
983 0 : double nSin=sin(a);
984 0 : double nCos=cos(a);
985 0 : RotatePoint(aPnt,aRef,nSin,nCos);
986 :
987 : // eliminate rounding errors for certain values
988 0 : if (nSA==9000)
989 : {
990 0 : if (nNeuWink==0 || nNeuWink==18000) aPnt.Y()=aRef.Y();
991 0 : if (nNeuWink==9000 || nNeuWink==27000) aPnt.X()=aRef.X();
992 : }
993 :
994 0 : if (nSA==4500)
995 0 : OrthoDistance8(aRef,aPnt,true);
996 : }
997 : }
998 :
999 0 : if (aPnt!=DragStat().GetNow())
1000 : {
1001 0 : Hide();
1002 0 : DragStat().NextMove(aPnt);
1003 0 : GetDragHdl()->SetPos(DragStat().GetNow());
1004 0 : SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
1005 :
1006 0 : if(pHM)
1007 0 : pHM->Touch();
1008 :
1009 0 : Show();
1010 0 : DragStat().SetActionRect(Rectangle(aPnt,aPnt));
1011 : }
1012 : }
1013 : }
1014 : }
1015 :
1016 0 : bool SdrDragMovHdl::EndSdrDrag(bool /*bCopy*/)
1017 : {
1018 0 : if( GetDragHdl() )
1019 : {
1020 0 : switch (GetDragHdl()->GetKind())
1021 : {
1022 : case HDL_REF1:
1023 0 : Ref1()=DragStat().GetNow();
1024 0 : break;
1025 :
1026 : case HDL_REF2:
1027 0 : Ref2()=DragStat().GetNow();
1028 0 : break;
1029 :
1030 : case HDL_MIRX:
1031 0 : Ref1()+=DragStat().GetNow()-DragStat().GetStart();
1032 0 : Ref2()+=DragStat().GetNow()-DragStat().GetStart();
1033 0 : break;
1034 :
1035 0 : default: break;
1036 : }
1037 : }
1038 :
1039 0 : return true;
1040 : }
1041 :
1042 0 : void SdrDragMovHdl::CancelSdrDrag()
1043 : {
1044 0 : Hide();
1045 :
1046 0 : SdrHdl* pHdl = GetDragHdl();
1047 0 : if( pHdl )
1048 0 : pHdl->SetPos(DragStat().GetRef1());
1049 :
1050 0 : SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
1051 :
1052 0 : if(pHM)
1053 0 : pHM->Touch();
1054 0 : }
1055 :
1056 0 : Pointer SdrDragMovHdl::GetSdrDragPointer() const
1057 : {
1058 0 : const SdrHdl* pHdl = GetDragHdl();
1059 :
1060 0 : if (pHdl!=NULL)
1061 : {
1062 0 : return pHdl->GetPointer();
1063 : }
1064 :
1065 0 : return Pointer(POINTER_REFHAND);
1066 : }
1067 :
1068 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1069 :
1070 0 : TYPEINIT1(SdrDragObjOwn,SdrDragMethod);
1071 :
1072 0 : SdrDragObjOwn::SdrDragObjOwn(SdrDragView& rNewView)
1073 : : SdrDragMethod(rNewView),
1074 0 : mpClone(0)
1075 : {
1076 0 : const SdrObject* pObj = GetDragObj();
1077 :
1078 0 : if(pObj)
1079 : {
1080 : // suppress full drag for some object types
1081 0 : setSolidDraggingActive(pObj->supportsFullDrag());
1082 : }
1083 0 : }
1084 :
1085 0 : SdrDragObjOwn::~SdrDragObjOwn()
1086 : {
1087 0 : if(mpClone)
1088 : {
1089 0 : SdrObject::Free(mpClone);
1090 : }
1091 0 : }
1092 :
1093 0 : void SdrDragObjOwn::createSdrDragEntries()
1094 : {
1095 0 : if(mpClone)
1096 : {
1097 0 : basegfx::B2DPolyPolygon aDragPolyPolygon;
1098 0 : bool bAddWireframe(true);
1099 :
1100 0 : if(getSolidDraggingActive())
1101 : {
1102 0 : SdrPageView* pPV = getSdrDragView().GetSdrPageView();
1103 :
1104 0 : if(pPV && pPV->PageWindowCount())
1105 : {
1106 0 : sdr::contact::ObjectContact& rOC = pPV->GetPageWindow(0)->GetObjectContact();
1107 0 : addSdrDragEntry(new SdrDragEntrySdrObject(*mpClone, rOC, false));
1108 :
1109 : // potentially no wireframe needed, full drag works
1110 0 : bAddWireframe = false;
1111 : }
1112 : }
1113 :
1114 0 : if(!bAddWireframe)
1115 : {
1116 : // check for extra conditions for wireframe, e.g. no border at
1117 : // objects
1118 0 : if(!mpClone->HasLineStyle())
1119 : {
1120 0 : bAddWireframe = true;
1121 : }
1122 : }
1123 :
1124 0 : if(bAddWireframe)
1125 : {
1126 : // use wireframe poly when full drag is off or did not work
1127 0 : aDragPolyPolygon = mpClone->TakeXorPoly();
1128 : }
1129 :
1130 : // add evtl. extra DragPolyPolygon
1131 0 : const basegfx::B2DPolyPolygon aSpecialDragPolyPolygon(mpClone->getSpecialDragPoly(DragStat()));
1132 :
1133 0 : if(aSpecialDragPolyPolygon.count())
1134 : {
1135 0 : aDragPolyPolygon.append(aSpecialDragPolyPolygon);
1136 : }
1137 :
1138 0 : if(aDragPolyPolygon.count())
1139 : {
1140 0 : addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragPolyPolygon));
1141 0 : }
1142 : }
1143 0 : }
1144 :
1145 0 : void SdrDragObjOwn::TakeSdrDragComment(XubString& rStr) const
1146 : {
1147 : // #i103058# get info string from the clone preferred, the original will
1148 : // not be changed. For security, use original as fallback
1149 0 : if(mpClone)
1150 : {
1151 0 : rStr = mpClone->getSpecialDragComment(DragStat());
1152 : }
1153 : else
1154 : {
1155 0 : const SdrObject* pObj = GetDragObj();
1156 :
1157 0 : if(pObj)
1158 : {
1159 0 : rStr = pObj->getSpecialDragComment(DragStat());
1160 : }
1161 : }
1162 0 : }
1163 :
1164 0 : bool SdrDragObjOwn::BeginSdrDrag()
1165 : {
1166 0 : if(!mpClone)
1167 : {
1168 0 : const SdrObject* pObj = GetDragObj();
1169 :
1170 0 : if(pObj && !pObj->IsResizeProtect())
1171 : {
1172 0 : if(pObj->beginSpecialDrag(DragStat()))
1173 : {
1174 : // create initial clone to have a start visualization
1175 0 : mpClone = pObj->getFullDragClone();
1176 0 : mpClone->applySpecialDrag(DragStat());
1177 :
1178 0 : return true;
1179 : }
1180 : }
1181 : }
1182 :
1183 0 : return false;
1184 : }
1185 :
1186 0 : void SdrDragObjOwn::MoveSdrDrag(const Point& rNoSnapPnt)
1187 : {
1188 0 : const SdrObject* pObj = GetDragObj();
1189 :
1190 0 : if(pObj)
1191 : {
1192 0 : Point aPnt(rNoSnapPnt);
1193 0 : SdrPageView* pPV = GetDragPV();
1194 :
1195 0 : if(pPV)
1196 : {
1197 0 : if(!DragStat().IsNoSnap())
1198 : {
1199 0 : SnapPos(aPnt);
1200 : }
1201 :
1202 0 : if(getSdrDragView().IsOrtho())
1203 : {
1204 0 : if (DragStat().IsOrtho8Possible())
1205 : {
1206 0 : OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
1207 : }
1208 0 : else if (DragStat().IsOrtho4Possible())
1209 : {
1210 0 : OrthoDistance4(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
1211 : }
1212 : }
1213 :
1214 0 : if(DragStat().CheckMinMoved(rNoSnapPnt))
1215 : {
1216 0 : if(aPnt != DragStat().GetNow())
1217 : {
1218 0 : Hide();
1219 0 : DragStat().NextMove(aPnt);
1220 :
1221 : // since SdrDragObjOwn currently supports no transformation of
1222 : // existing SdrDragEntries but only their recreation, a recreation
1223 : // after every move is needed in this mode. Delete existing
1224 : // SdrDragEntries here to force their recreation in the following Show().
1225 0 : clearSdrDragEntries();
1226 :
1227 : // delete current clone (after the last reference to it is deleted above)
1228 0 : if(mpClone)
1229 : {
1230 0 : SdrObject::Free(mpClone);
1231 0 : mpClone = 0;
1232 : }
1233 :
1234 : // create a new clone and modify to current drag state
1235 0 : if(!mpClone)
1236 : {
1237 0 : mpClone = pObj->getFullDragClone();
1238 0 : mpClone->applySpecialDrag(DragStat());
1239 : }
1240 :
1241 0 : Show();
1242 : }
1243 : }
1244 : }
1245 : }
1246 0 : }
1247 :
1248 0 : bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/)
1249 : {
1250 0 : Hide();
1251 0 : SdrUndoAction* pUndo = NULL;
1252 0 : SdrUndoAction* pUndo2 = NULL;
1253 0 : std::vector< SdrUndoAction* > vConnectorUndoActions;
1254 0 : bool bRet = false;
1255 0 : SdrObject* pObj = GetDragObj();
1256 :
1257 0 : if(pObj)
1258 : {
1259 0 : const bool bUndo = getSdrDragView().IsUndoEnabled();
1260 :
1261 0 : if( bUndo )
1262 : {
1263 0 : if(!getSdrDragView().IsInsObjPoint() && pObj->IsInserted() )
1264 : {
1265 0 : if (DragStat().IsEndDragChangesAttributes())
1266 : {
1267 0 : pUndo=getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pObj);
1268 :
1269 0 : if (DragStat().IsEndDragChangesGeoAndAttributes())
1270 : {
1271 0 : vConnectorUndoActions = getSdrDragView().CreateConnectorUndo( *pObj );
1272 0 : pUndo2 = getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj);
1273 : }
1274 : }
1275 : else
1276 : {
1277 0 : vConnectorUndoActions = getSdrDragView().CreateConnectorUndo( *pObj );
1278 0 : pUndo= getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj);
1279 : }
1280 : }
1281 :
1282 0 : if( pUndo )
1283 : {
1284 0 : getSdrDragView().BegUndo( pUndo->GetComment() );
1285 : }
1286 : else
1287 : {
1288 0 : getSdrDragView().BegUndo();
1289 : }
1290 : }
1291 :
1292 : // Maybe use operator = for setting changed object data (do not change selection in
1293 : // view, this will destroy the interactor). This is possible since a clone is now
1294 : // directly modified by the modifiers. Only SdrTableObj is adding own UNDOs
1295 : // in its SdrTableObj::endSpecialDrag, so currently not possible. OTOH it uses
1296 : // a CreateUndoGeoObject(), so maybe setting SetEndDragChangesAttributes is okay. I
1297 : // will test this now
1298 0 : Rectangle aBoundRect0;
1299 :
1300 0 : if(pObj->GetUserCall())
1301 : {
1302 0 : aBoundRect0 = pObj->GetLastBoundRect();
1303 : }
1304 :
1305 0 : bRet = pObj->applySpecialDrag(DragStat());
1306 :
1307 0 : if(bRet)
1308 : {
1309 0 : pObj->SetChanged();
1310 0 : pObj->BroadcastObjectChange();
1311 0 : pObj->SendUserCall( SDRUSERCALL_RESIZE, aBoundRect0 );
1312 : }
1313 :
1314 0 : if(bRet)
1315 : {
1316 0 : if( bUndo )
1317 : {
1318 0 : getSdrDragView().AddUndoActions( vConnectorUndoActions );
1319 :
1320 0 : if ( pUndo )
1321 : {
1322 0 : getSdrDragView().AddUndo(pUndo);
1323 : }
1324 :
1325 0 : if ( pUndo2 )
1326 : {
1327 0 : getSdrDragView().AddUndo(pUndo2);
1328 : }
1329 : }
1330 : }
1331 : else
1332 : {
1333 0 : if( bUndo )
1334 : {
1335 0 : std::vector< SdrUndoAction* >::iterator vConnectorUndoIter( vConnectorUndoActions.begin() );
1336 :
1337 0 : while( vConnectorUndoIter != vConnectorUndoActions.end() )
1338 : {
1339 0 : delete *vConnectorUndoIter++;
1340 : }
1341 :
1342 0 : delete pUndo;
1343 0 : delete pUndo2;
1344 : }
1345 : }
1346 :
1347 0 : if( bUndo )
1348 0 : getSdrDragView().EndUndo();
1349 : }
1350 :
1351 0 : return bRet;
1352 : }
1353 :
1354 0 : Pointer SdrDragObjOwn::GetSdrDragPointer() const
1355 : {
1356 0 : const SdrHdl* pHdl=GetDragHdl();
1357 :
1358 0 : if (pHdl)
1359 : {
1360 0 : return pHdl->GetPointer();
1361 : }
1362 :
1363 0 : return Pointer(POINTER_MOVE);
1364 : }
1365 :
1366 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1367 :
1368 0 : TYPEINIT1(SdrDragMove,SdrDragMethod);
1369 :
1370 0 : void SdrDragMove::createSdrDragEntryForSdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool /*bModify*/)
1371 : {
1372 : // for SdrDragMove, use current Primitive2DSequence of SdrObject visualization
1373 : // in given ObjectContact directly
1374 0 : sdr::contact::ViewContact& rVC = rOriginal.GetViewContact();
1375 0 : sdr::contact::ViewObjectContact& rVOC = rVC.GetViewObjectContact(rObjectContact);
1376 0 : sdr::contact::DisplayInfo aDisplayInfo;
1377 :
1378 : // Do not use the last ViewPort set at the OC from the last ProcessDisplay(),
1379 : // here we want the complete primitive sequence without visible clippings
1380 0 : rObjectContact.resetViewPort();
1381 :
1382 0 : addSdrDragEntry(new SdrDragEntryPrimitive2DSequence(rVOC.getPrimitive2DSequenceHierarchy(aDisplayInfo), true));
1383 0 : }
1384 :
1385 0 : void SdrDragMove::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
1386 : {
1387 0 : rTarget.Move(Size(DragStat().GetDX(), DragStat().GetDY()));
1388 0 : }
1389 :
1390 0 : SdrDragMove::SdrDragMove(SdrDragView& rNewView)
1391 0 : : SdrDragMethod(rNewView)
1392 : {
1393 0 : setMoveOnly(true);
1394 0 : }
1395 :
1396 0 : void SdrDragMove::TakeSdrDragComment(XubString& rStr) const
1397 : {
1398 0 : rtl::OUString aStr;
1399 :
1400 0 : ImpTakeDescriptionStr(STR_DragMethMove, rStr);
1401 0 : rStr.AppendAscii(" (x=");
1402 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
1403 0 : rStr.Append(aStr);
1404 0 : rStr.AppendAscii(" y=");
1405 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
1406 0 : rStr.Append(aStr);
1407 0 : rStr += sal_Unicode(')');
1408 :
1409 0 : if(getSdrDragView().IsDragWithCopy())
1410 : {
1411 0 : if(!getSdrDragView().IsInsObjPoint() && !getSdrDragView().IsInsGluePoint())
1412 : {
1413 0 : rStr += ImpGetResStr(STR_EditWithCopy);
1414 : }
1415 0 : }
1416 0 : }
1417 :
1418 0 : bool SdrDragMove::BeginSdrDrag()
1419 : {
1420 0 : DragStat().SetActionRect(GetMarkedRect());
1421 0 : Show();
1422 :
1423 0 : return true;
1424 : }
1425 :
1426 0 : basegfx::B2DHomMatrix SdrDragMove::getCurrentTransformation()
1427 : {
1428 0 : return basegfx::tools::createTranslateB2DHomMatrix(DragStat().GetDX(), DragStat().GetDY());
1429 : }
1430 :
1431 0 : void SdrDragMove::ImpCheckSnap(const Point& rPt)
1432 : {
1433 0 : Point aPt(rPt);
1434 0 : sal_uInt16 nRet=SnapPos(aPt);
1435 0 : aPt-=rPt;
1436 :
1437 0 : if ((nRet & SDRSNAP_XSNAPPED) !=0)
1438 : {
1439 0 : if (bXSnapped)
1440 : {
1441 0 : if (Abs(aPt.X())<Abs(nBestXSnap))
1442 : {
1443 0 : nBestXSnap=aPt.X();
1444 : }
1445 : }
1446 : else
1447 : {
1448 0 : nBestXSnap=aPt.X();
1449 0 : bXSnapped=true;
1450 : }
1451 : }
1452 :
1453 0 : if ((nRet & SDRSNAP_YSNAPPED) !=0)
1454 : {
1455 0 : if (bYSnapped)
1456 : {
1457 0 : if (Abs(aPt.Y())<Abs(nBestYSnap))
1458 : {
1459 0 : nBestYSnap=aPt.Y();
1460 : }
1461 : }
1462 : else
1463 : {
1464 0 : nBestYSnap=aPt.Y();
1465 0 : bYSnapped=true;
1466 : }
1467 : }
1468 0 : }
1469 :
1470 0 : void SdrDragMove::MoveSdrDrag(const Point& rNoSnapPnt_)
1471 : {
1472 0 : nBestXSnap=0;
1473 0 : nBestYSnap=0;
1474 0 : bXSnapped=false;
1475 0 : bYSnapped=false;
1476 0 : Point aNoSnapPnt(rNoSnapPnt_);
1477 0 : const Rectangle& aSR=GetMarkedRect();
1478 0 : long nMovedx=aNoSnapPnt.X()-DragStat().GetStart().X();
1479 0 : long nMovedy=aNoSnapPnt.Y()-DragStat().GetStart().Y();
1480 0 : Point aLO(aSR.TopLeft()); aLO.X()+=nMovedx; aLO.Y()+=nMovedy;
1481 0 : Point aRU(aSR.BottomRight()); aRU.X()+=nMovedx; aRU.Y()+=nMovedy;
1482 0 : Point aLU(aLO.X(),aRU.Y());
1483 0 : Point aRO(aRU.X(),aLO.Y());
1484 0 : ImpCheckSnap(aLO);
1485 :
1486 0 : if (!getSdrDragView().IsMoveSnapOnlyTopLeft())
1487 : {
1488 0 : ImpCheckSnap(aRO);
1489 0 : ImpCheckSnap(aLU);
1490 0 : ImpCheckSnap(aRU);
1491 : }
1492 :
1493 0 : Point aPnt(aNoSnapPnt.X()+nBestXSnap,aNoSnapPnt.Y()+nBestYSnap);
1494 0 : bool bOrtho=getSdrDragView().IsOrtho();
1495 :
1496 0 : if (bOrtho)
1497 0 : OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
1498 :
1499 0 : if (DragStat().CheckMinMoved(aNoSnapPnt))
1500 : {
1501 0 : Point aPt1(aPnt);
1502 0 : Rectangle aLR(getSdrDragView().GetWorkArea());
1503 0 : bool bWorkArea=!aLR.IsEmpty();
1504 0 : bool bDragLimit=IsDragLimit();
1505 :
1506 0 : if (bDragLimit || bWorkArea)
1507 : {
1508 0 : Rectangle aSR2(GetMarkedRect());
1509 0 : Point aD(aPt1-DragStat().GetStart());
1510 :
1511 0 : if (bDragLimit)
1512 : {
1513 0 : Rectangle aR2(GetDragLimitRect());
1514 :
1515 0 : if (bWorkArea)
1516 0 : aLR.Intersection(aR2);
1517 : else
1518 0 : aLR=aR2;
1519 : }
1520 :
1521 0 : if (aSR2.Left()>aLR.Left() || aSR2.Right()<aLR.Right())
1522 : { // any space to move to?
1523 0 : aSR2.Move(aD.X(),0);
1524 :
1525 0 : if (aSR2.Left()<aLR.Left())
1526 : {
1527 0 : aPt1.X()-=aSR2.Left()-aLR.Left();
1528 : }
1529 0 : else if (aSR2.Right()>aLR.Right())
1530 : {
1531 0 : aPt1.X()-=aSR2.Right()-aLR.Right();
1532 : }
1533 : }
1534 : else
1535 0 : aPt1.X()=DragStat().GetStart().X(); // no space to move to
1536 :
1537 0 : if (aSR2.Top()>aLR.Top() || aSR2.Bottom()<aLR.Bottom())
1538 : { // any space to move to?
1539 0 : aSR2.Move(0,aD.Y());
1540 :
1541 0 : if (aSR2.Top()<aLR.Top())
1542 : {
1543 0 : aPt1.Y()-=aSR2.Top()-aLR.Top();
1544 : }
1545 0 : else if (aSR2.Bottom()>aLR.Bottom())
1546 : {
1547 0 : aPt1.Y()-=aSR2.Bottom()-aLR.Bottom();
1548 : }
1549 : }
1550 : else
1551 0 : aPt1.Y()=DragStat().GetStart().Y(); // no space to move to
1552 : }
1553 :
1554 0 : if (getSdrDragView().IsDraggingGluePoints())
1555 : { // restrict glue points to the BoundRect of the Obj
1556 0 : aPt1-=DragStat().GetStart();
1557 0 : const SdrMarkList& rML=GetMarkedObjectList();
1558 0 : sal_uLong nMarkAnz=rML.GetMarkCount();
1559 :
1560 0 : for (sal_uLong nMarkNum=0; nMarkNum<nMarkAnz; nMarkNum++)
1561 : {
1562 0 : const SdrMark* pM=rML.GetMark(nMarkNum);
1563 0 : const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
1564 0 : sal_uLong nPtAnz=pPts==NULL ? 0 : pPts->size();
1565 :
1566 0 : if (nPtAnz!=0)
1567 : {
1568 0 : const SdrObject* pObj=pM->GetMarkedSdrObj();
1569 0 : const SdrGluePointList* pGPL=pObj->GetGluePointList();
1570 0 : Rectangle aBound(pObj->GetCurrentBoundRect());
1571 :
1572 0 : for (SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
1573 : {
1574 0 : sal_uInt16 nId = *it;
1575 0 : sal_uInt16 nGlueNum=pGPL->FindGluePoint(nId);
1576 :
1577 0 : if (nGlueNum!=SDRGLUEPOINT_NOTFOUND)
1578 : {
1579 0 : Point aPt((*pGPL)[nGlueNum].GetAbsolutePos(*pObj));
1580 0 : aPt+=aPt1; // move by this much
1581 0 : if (aPt.X()<aBound.Left() ) aPt1.X()-=aPt.X()-aBound.Left() ;
1582 0 : if (aPt.X()>aBound.Right() ) aPt1.X()-=aPt.X()-aBound.Right() ;
1583 0 : if (aPt.Y()<aBound.Top() ) aPt1.Y()-=aPt.Y()-aBound.Top() ;
1584 0 : if (aPt.Y()>aBound.Bottom()) aPt1.Y()-=aPt.Y()-aBound.Bottom();
1585 : }
1586 : }
1587 : }
1588 : }
1589 :
1590 0 : aPt1+=DragStat().GetStart();
1591 : }
1592 :
1593 0 : if (bOrtho)
1594 0 : OrthoDistance8(DragStat().GetStart(),aPt1,false);
1595 :
1596 0 : if (aPt1!=DragStat().GetNow())
1597 : {
1598 0 : Hide();
1599 0 : DragStat().NextMove(aPt1);
1600 0 : Rectangle aAction(GetMarkedRect());
1601 0 : aAction.Move(DragStat().GetDX(),DragStat().GetDY());
1602 0 : DragStat().SetActionRect(aAction);
1603 0 : Show();
1604 : }
1605 : }
1606 0 : }
1607 :
1608 0 : bool SdrDragMove::EndSdrDrag(bool bCopy)
1609 : {
1610 0 : Hide();
1611 :
1612 0 : if (getSdrDragView().IsInsObjPoint() || getSdrDragView().IsInsGluePoint())
1613 0 : bCopy=false;
1614 :
1615 0 : if (IsDraggingPoints())
1616 : {
1617 0 : getSdrDragView().MoveMarkedPoints(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
1618 : }
1619 0 : else if (IsDraggingGluePoints())
1620 : {
1621 0 : getSdrDragView().MoveMarkedGluePoints(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
1622 : }
1623 : else
1624 : {
1625 0 : getSdrDragView().MoveMarkedObj(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
1626 : }
1627 :
1628 0 : return true;
1629 : }
1630 :
1631 0 : Pointer SdrDragMove::GetSdrDragPointer() const
1632 : {
1633 0 : if (IsDraggingPoints() || IsDraggingGluePoints())
1634 : {
1635 0 : return Pointer(POINTER_MOVEPOINT);
1636 : }
1637 : else
1638 : {
1639 0 : return Pointer(POINTER_MOVE);
1640 : }
1641 : }
1642 :
1643 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1644 :
1645 0 : TYPEINIT1(SdrDragResize,SdrDragMethod);
1646 :
1647 0 : SdrDragResize::SdrDragResize(SdrDragView& rNewView)
1648 : : SdrDragMethod(rNewView),
1649 : aXFact(1,1),
1650 0 : aYFact(1,1)
1651 : {
1652 0 : }
1653 :
1654 0 : void SdrDragResize::TakeSdrDragComment(XubString& rStr) const
1655 : {
1656 0 : ImpTakeDescriptionStr(STR_DragMethResize, rStr);
1657 0 : bool bEqual(aXFact == aYFact);
1658 0 : Fraction aFact1(1,1);
1659 0 : Point aStart(DragStat().GetStart());
1660 0 : Point aRef(DragStat().GetRef1());
1661 0 : sal_Int32 nXDiv(aStart.X() - aRef.X());
1662 :
1663 0 : if(!nXDiv)
1664 0 : nXDiv = 1;
1665 :
1666 0 : sal_Int32 nYDiv(aStart.Y() - aRef.Y());
1667 :
1668 0 : if(!nYDiv)
1669 0 : nYDiv = 1;
1670 :
1671 0 : bool bX(aXFact != aFact1 && Abs(nXDiv) > 1);
1672 0 : bool bY(aYFact != aFact1 && Abs(nYDiv) > 1);
1673 :
1674 0 : if(bX || bY)
1675 : {
1676 0 : XubString aStr;
1677 :
1678 0 : rStr.AppendAscii(" (");
1679 :
1680 0 : if(bX)
1681 : {
1682 0 : if(!bEqual)
1683 0 : rStr.AppendAscii("x=");
1684 :
1685 0 : getSdrDragView().GetModel()->TakePercentStr(aXFact, aStr);
1686 0 : rStr += aStr;
1687 : }
1688 :
1689 0 : if(bY && !bEqual)
1690 : {
1691 0 : if(bX)
1692 0 : rStr += sal_Unicode(' ');
1693 :
1694 0 : rStr.AppendAscii("y=");
1695 0 : getSdrDragView().GetModel()->TakePercentStr(aYFact, aStr);
1696 0 : rStr += aStr;
1697 : }
1698 :
1699 0 : rStr += sal_Unicode(')');
1700 : }
1701 :
1702 0 : if(getSdrDragView().IsDragWithCopy())
1703 0 : rStr += ImpGetResStr(STR_EditWithCopy);
1704 0 : }
1705 :
1706 0 : bool SdrDragResize::BeginSdrDrag()
1707 : {
1708 0 : SdrHdlKind eRefHdl=HDL_MOVE;
1709 0 : SdrHdl* pRefHdl=NULL;
1710 :
1711 0 : switch (GetDragHdlKind())
1712 : {
1713 0 : case HDL_UPLFT: eRefHdl=HDL_LWRGT; break;
1714 0 : case HDL_UPPER: eRefHdl=HDL_LOWER; DragStat().SetHorFixed(true); break;
1715 0 : case HDL_UPRGT: eRefHdl=HDL_LWLFT; break;
1716 0 : case HDL_LEFT : eRefHdl=HDL_RIGHT; DragStat().SetVerFixed(true); break;
1717 0 : case HDL_RIGHT: eRefHdl=HDL_LEFT ; DragStat().SetVerFixed(true); break;
1718 0 : case HDL_LWLFT: eRefHdl=HDL_UPRGT; break;
1719 0 : case HDL_LOWER: eRefHdl=HDL_UPPER; DragStat().SetHorFixed(true); break;
1720 0 : case HDL_LWRGT: eRefHdl=HDL_UPLFT; break;
1721 0 : default: break;
1722 : }
1723 :
1724 0 : if (eRefHdl!=HDL_MOVE)
1725 0 : pRefHdl=GetHdlList().GetHdl(eRefHdl);
1726 :
1727 0 : if (pRefHdl!=NULL && !getSdrDragView().IsResizeAtCenter())
1728 : {
1729 : // Calc hack to adjust for calc grid
1730 0 : DragStat().Ref1()=pRefHdl->GetPos() - getSdrDragView().GetGridOffset();
1731 : }
1732 : else
1733 : {
1734 0 : SdrHdl* pRef1=GetHdlList().GetHdl(HDL_UPLFT);
1735 0 : SdrHdl* pRef2=GetHdlList().GetHdl(HDL_LWRGT);
1736 :
1737 0 : if (pRef1!=NULL && pRef2!=NULL)
1738 : {
1739 0 : DragStat().Ref1()=Rectangle(pRef1->GetPos(),pRef2->GetPos()).Center();
1740 : }
1741 : else
1742 : {
1743 0 : DragStat().Ref1()=GetMarkedRect().Center();
1744 : }
1745 : }
1746 :
1747 0 : Show();
1748 :
1749 0 : return true;
1750 : }
1751 :
1752 0 : basegfx::B2DHomMatrix SdrDragResize::getCurrentTransformation()
1753 : {
1754 : basegfx::B2DHomMatrix aRetval(basegfx::tools::createTranslateB2DHomMatrix(
1755 0 : -DragStat().Ref1().X(), -DragStat().Ref1().Y()));
1756 0 : aRetval.scale(aXFact, aYFact);
1757 0 : aRetval.translate(DragStat().Ref1().X(), DragStat().Ref1().Y());
1758 :
1759 0 : return aRetval;
1760 : }
1761 :
1762 0 : void SdrDragResize::MoveSdrDrag(const Point& rNoSnapPnt)
1763 : {
1764 0 : Point aPnt(GetSnapPos(rNoSnapPnt));
1765 0 : Point aStart(DragStat().GetStart());
1766 0 : Point aRef(DragStat().GetRef1());
1767 0 : Fraction aMaxFact(0x7FFFFFFF,1);
1768 0 : Rectangle aLR(getSdrDragView().GetWorkArea());
1769 0 : bool bWorkArea=!aLR.IsEmpty();
1770 0 : bool bDragLimit=IsDragLimit();
1771 :
1772 0 : if (bDragLimit || bWorkArea)
1773 : {
1774 0 : Rectangle aSR(GetMarkedRect());
1775 :
1776 0 : if (bDragLimit)
1777 : {
1778 0 : Rectangle aR2(GetDragLimitRect());
1779 :
1780 0 : if (bWorkArea)
1781 0 : aLR.Intersection(aR2);
1782 : else
1783 0 : aLR=aR2;
1784 : }
1785 :
1786 0 : if (aPnt.X()<aLR.Left())
1787 0 : aPnt.X()=aLR.Left();
1788 0 : else if (aPnt.X()>aLR.Right())
1789 0 : aPnt.X()=aLR.Right();
1790 :
1791 0 : if (aPnt.Y()<aLR.Top())
1792 0 : aPnt.Y()=aLR.Top();
1793 0 : else if (aPnt.Y()>aLR.Bottom())
1794 0 : aPnt.Y()=aLR.Bottom();
1795 :
1796 0 : if (aRef.X()>aSR.Left())
1797 : {
1798 0 : Fraction aMax(aRef.X()-aLR.Left(),aRef.X()-aSR.Left());
1799 :
1800 0 : if (aMax<aMaxFact)
1801 0 : aMaxFact=aMax;
1802 : }
1803 :
1804 0 : if (aRef.X()<aSR.Right())
1805 : {
1806 0 : Fraction aMax(aLR.Right()-aRef.X(),aSR.Right()-aRef.X());
1807 :
1808 0 : if (aMax<aMaxFact)
1809 0 : aMaxFact=aMax;
1810 : }
1811 :
1812 0 : if (aRef.Y()>aSR.Top())
1813 : {
1814 0 : Fraction aMax(aRef.Y()-aLR.Top(),aRef.Y()-aSR.Top());
1815 :
1816 0 : if (aMax<aMaxFact)
1817 0 : aMaxFact=aMax;
1818 : }
1819 :
1820 0 : if (aRef.Y()<aSR.Bottom())
1821 : {
1822 0 : Fraction aMax(aLR.Bottom()-aRef.Y(),aSR.Bottom()-aRef.Y());
1823 :
1824 0 : if (aMax<aMaxFact)
1825 0 : aMaxFact=aMax;
1826 : }
1827 : }
1828 :
1829 0 : long nXDiv=aStart.X()-aRef.X(); if (nXDiv==0) nXDiv=1;
1830 0 : long nYDiv=aStart.Y()-aRef.Y(); if (nYDiv==0) nYDiv=1;
1831 0 : long nXMul=aPnt.X()-aRef.X();
1832 0 : long nYMul=aPnt.Y()-aRef.Y();
1833 :
1834 0 : if (nXDiv<0)
1835 : {
1836 0 : nXDiv=-nXDiv;
1837 0 : nXMul=-nXMul;
1838 : }
1839 :
1840 0 : if (nYDiv<0)
1841 : {
1842 0 : nYDiv=-nYDiv;
1843 0 : nYMul=-nYMul;
1844 : }
1845 :
1846 0 : bool bXNeg=nXMul<0; if (bXNeg) nXMul=-nXMul;
1847 0 : bool bYNeg=nYMul<0; if (bYNeg) nYMul=-nYMul;
1848 0 : bool bOrtho=getSdrDragView().IsOrtho() || !getSdrDragView().IsResizeAllowed(false);
1849 :
1850 0 : if (!DragStat().IsHorFixed() && !DragStat().IsVerFixed())
1851 : {
1852 0 : if (Abs(nXDiv)<=1 || Abs(nYDiv)<=1)
1853 0 : bOrtho=false;
1854 :
1855 0 : if (bOrtho)
1856 : {
1857 0 : if ((Fraction(nXMul,nXDiv)>Fraction(nYMul,nYDiv)) !=getSdrDragView().IsBigOrtho())
1858 : {
1859 0 : nXMul=nYMul;
1860 0 : nXDiv=nYDiv;
1861 : }
1862 : else
1863 : {
1864 0 : nYMul=nXMul;
1865 0 : nYDiv=nXDiv;
1866 : }
1867 : }
1868 : }
1869 : else
1870 : {
1871 0 : if (bOrtho)
1872 : {
1873 0 : if (DragStat().IsHorFixed())
1874 : {
1875 0 : bXNeg=false;
1876 0 : nXMul=nYMul;
1877 0 : nXDiv=nYDiv;
1878 : }
1879 :
1880 0 : if (DragStat().IsVerFixed())
1881 : {
1882 0 : bYNeg=false;
1883 0 : nYMul=nXMul;
1884 0 : nYDiv=nXDiv;
1885 : }
1886 : }
1887 : else
1888 : {
1889 0 : if (DragStat().IsHorFixed())
1890 : {
1891 0 : bXNeg=false;
1892 0 : nXMul=1;
1893 0 : nXDiv=1;
1894 : }
1895 :
1896 0 : if (DragStat().IsVerFixed())
1897 : {
1898 0 : bYNeg=false;
1899 0 : nYMul=1;
1900 0 : nYDiv=1;
1901 : }
1902 : }
1903 : }
1904 :
1905 0 : Fraction aNeuXFact(nXMul,nXDiv);
1906 0 : Fraction aNeuYFact(nYMul,nYDiv);
1907 :
1908 0 : if (bOrtho)
1909 : {
1910 0 : if (aNeuXFact>aMaxFact)
1911 : {
1912 0 : aNeuXFact=aMaxFact;
1913 0 : aNeuYFact=aMaxFact;
1914 : }
1915 :
1916 0 : if (aNeuYFact>aMaxFact)
1917 : {
1918 0 : aNeuXFact=aMaxFact;
1919 0 : aNeuYFact=aMaxFact;
1920 : }
1921 : }
1922 :
1923 0 : if (bXNeg)
1924 0 : aNeuXFact=Fraction(-aNeuXFact.GetNumerator(),aNeuXFact.GetDenominator());
1925 :
1926 0 : if (bYNeg)
1927 0 : aNeuYFact=Fraction(-aNeuYFact.GetNumerator(),aNeuYFact.GetDenominator());
1928 :
1929 0 : if (DragStat().CheckMinMoved(aPnt))
1930 : {
1931 0 : if ((!DragStat().IsHorFixed() && aPnt.X()!=DragStat().GetNow().X()) ||
1932 0 : (!DragStat().IsVerFixed() && aPnt.Y()!=DragStat().GetNow().Y()))
1933 : {
1934 0 : Hide();
1935 0 : DragStat().NextMove(aPnt);
1936 0 : aXFact=aNeuXFact;
1937 0 : aYFact=aNeuYFact;
1938 0 : Show();
1939 : }
1940 : }
1941 0 : }
1942 :
1943 0 : void SdrDragResize::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
1944 : {
1945 0 : rTarget.Resize(DragStat().Ref1(),aXFact,aYFact);
1946 0 : }
1947 :
1948 0 : bool SdrDragResize::EndSdrDrag(bool bCopy)
1949 : {
1950 0 : Hide();
1951 :
1952 0 : if (IsDraggingPoints())
1953 : {
1954 0 : getSdrDragView().ResizeMarkedPoints(DragStat().Ref1(),aXFact,aYFact,bCopy);
1955 : }
1956 0 : else if (IsDraggingGluePoints())
1957 : {
1958 0 : getSdrDragView().ResizeMarkedGluePoints(DragStat().Ref1(),aXFact,aYFact,bCopy);
1959 : }
1960 : else
1961 : {
1962 0 : getSdrDragView().ResizeMarkedObj(DragStat().Ref1(),aXFact,aYFact,bCopy);
1963 : }
1964 :
1965 0 : return true;
1966 : }
1967 :
1968 0 : Pointer SdrDragResize::GetSdrDragPointer() const
1969 : {
1970 0 : const SdrHdl* pHdl=GetDragHdl();
1971 :
1972 0 : if (pHdl!=NULL)
1973 : {
1974 0 : return pHdl->GetPointer();
1975 : }
1976 :
1977 0 : return Pointer(POINTER_MOVE);
1978 : }
1979 :
1980 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1981 :
1982 0 : TYPEINIT1(SdrDragRotate,SdrDragMethod);
1983 :
1984 0 : void SdrDragRotate::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
1985 : {
1986 0 : rTarget.Rotate(DragStat().GetRef1(), nWink, sin(nWink*nPi180), cos(nWink*nPi180));
1987 0 : }
1988 :
1989 0 : SdrDragRotate::SdrDragRotate(SdrDragView& rNewView)
1990 : : SdrDragMethod(rNewView),
1991 : nSin(0.0),
1992 : nCos(1.0),
1993 : nWink0(0),
1994 : nWink(0),
1995 0 : bRight(false)
1996 : {
1997 0 : }
1998 :
1999 0 : void SdrDragRotate::TakeSdrDragComment(XubString& rStr) const
2000 : {
2001 0 : ImpTakeDescriptionStr(STR_DragMethRotate, rStr);
2002 0 : rStr.AppendAscii(" (");
2003 0 : sal_Int32 nTmpWink(NormAngle360(nWink));
2004 :
2005 0 : if(bRight && nWink)
2006 : {
2007 0 : nTmpWink -= 36000;
2008 : }
2009 :
2010 0 : rtl::OUString aStr;
2011 0 : getSdrDragView().GetModel()->TakeWinkStr(nTmpWink, aStr);
2012 0 : rStr.Append(aStr);
2013 0 : rStr += sal_Unicode(')');
2014 :
2015 0 : if(getSdrDragView().IsDragWithCopy())
2016 0 : rStr += ImpGetResStr(STR_EditWithCopy);
2017 0 : }
2018 :
2019 0 : bool SdrDragRotate::BeginSdrDrag()
2020 : {
2021 0 : SdrHdl* pH=GetHdlList().GetHdl(HDL_REF1);
2022 :
2023 0 : if (pH!=NULL)
2024 : {
2025 0 : Show();
2026 0 : DragStat().Ref1()=pH->GetPos();
2027 0 : nWink0=GetAngle(DragStat().GetStart()-DragStat().GetRef1());
2028 0 : return true;
2029 : }
2030 : else
2031 : {
2032 : OSL_FAIL("SdrDragRotate::BeginSdrDrag(): No reference point handle found.");
2033 0 : return false;
2034 : }
2035 : }
2036 :
2037 0 : basegfx::B2DHomMatrix SdrDragRotate::getCurrentTransformation()
2038 : {
2039 : return basegfx::tools::createRotateAroundPoint(
2040 0 : DragStat().GetRef1().X(), DragStat().GetRef1().Y(),
2041 0 : -atan2(nSin, nCos));
2042 : }
2043 :
2044 0 : void SdrDragRotate::MoveSdrDrag(const Point& rPnt_)
2045 : {
2046 0 : Point aPnt(rPnt_);
2047 0 : if (DragStat().CheckMinMoved(aPnt))
2048 : {
2049 0 : long nNeuWink=NormAngle360(GetAngle(aPnt-DragStat().GetRef1())-nWink0);
2050 0 : long nSA=0;
2051 :
2052 0 : if (getSdrDragView().IsAngleSnapEnabled())
2053 0 : nSA=getSdrDragView().GetSnapAngle();
2054 :
2055 0 : if (!getSdrDragView().IsRotateAllowed(false))
2056 0 : nSA=9000;
2057 :
2058 0 : if (nSA!=0)
2059 : { // angle snapping
2060 0 : nNeuWink+=nSA/2;
2061 0 : nNeuWink/=nSA;
2062 0 : nNeuWink*=nSA;
2063 : }
2064 :
2065 0 : nNeuWink=NormAngle180(nNeuWink);
2066 :
2067 0 : if (nWink!=nNeuWink)
2068 : {
2069 0 : sal_uInt16 nSekt0=GetAngleSector(nWink);
2070 0 : sal_uInt16 nSekt1=GetAngleSector(nNeuWink);
2071 :
2072 0 : if (nSekt0==0 && nSekt1==3)
2073 0 : bRight=true;
2074 :
2075 0 : if (nSekt0==3 && nSekt1==0)
2076 0 : bRight=false;
2077 :
2078 0 : nWink=nNeuWink;
2079 0 : double a=nWink*nPi180;
2080 0 : double nSin1=sin(a); // calculate now, so as little time as possible
2081 0 : double nCos1=cos(a); // passes between Hide() and Show()
2082 0 : Hide();
2083 0 : nSin=nSin1;
2084 0 : nCos=nCos1;
2085 0 : DragStat().NextMove(aPnt);
2086 0 : Show();
2087 : }
2088 : }
2089 0 : }
2090 :
2091 0 : bool SdrDragRotate::EndSdrDrag(bool bCopy)
2092 : {
2093 0 : Hide();
2094 :
2095 0 : if (nWink!=0)
2096 : {
2097 0 : if (IsDraggingPoints())
2098 : {
2099 0 : getSdrDragView().RotateMarkedPoints(DragStat().GetRef1(),nWink,bCopy);
2100 : }
2101 0 : else if (IsDraggingGluePoints())
2102 : {
2103 0 : getSdrDragView().RotateMarkedGluePoints(DragStat().GetRef1(),nWink,bCopy);
2104 : }
2105 : else
2106 : {
2107 0 : getSdrDragView().RotateMarkedObj(DragStat().GetRef1(),nWink,bCopy);
2108 : }
2109 : }
2110 0 : return true;
2111 : }
2112 :
2113 0 : Pointer SdrDragRotate::GetSdrDragPointer() const
2114 : {
2115 0 : return Pointer(POINTER_ROTATE);
2116 : }
2117 :
2118 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2119 :
2120 0 : TYPEINIT1(SdrDragShear,SdrDragMethod);
2121 :
2122 0 : SdrDragShear::SdrDragShear(SdrDragView& rNewView, bool bSlant1)
2123 : : SdrDragMethod(rNewView),
2124 : aFact(1,1),
2125 : nWink0(0),
2126 : nWink(0),
2127 : nTan(0.0),
2128 : bVertical(false),
2129 : bResize(false),
2130 : bUpSideDown(false),
2131 0 : bSlant(bSlant1)
2132 : {
2133 0 : }
2134 :
2135 0 : void SdrDragShear::TakeSdrDragComment(XubString& rStr) const
2136 : {
2137 0 : ImpTakeDescriptionStr(STR_DragMethShear, rStr);
2138 0 : rStr.AppendAscii(" (");
2139 :
2140 0 : sal_Int32 nTmpWink(nWink);
2141 :
2142 0 : if(bUpSideDown)
2143 0 : nTmpWink += 18000;
2144 :
2145 0 : nTmpWink = NormAngle180(nTmpWink);
2146 :
2147 0 : rtl::OUString aStr;
2148 0 : getSdrDragView().GetModel()->TakeWinkStr(nTmpWink, aStr);
2149 0 : rStr.Append(aStr);
2150 0 : rStr += sal_Unicode(')');
2151 :
2152 0 : if(getSdrDragView().IsDragWithCopy())
2153 0 : rStr += ImpGetResStr(STR_EditWithCopy);
2154 0 : }
2155 :
2156 0 : bool SdrDragShear::BeginSdrDrag()
2157 : {
2158 0 : SdrHdlKind eRefHdl=HDL_MOVE;
2159 0 : SdrHdl* pRefHdl=NULL;
2160 :
2161 0 : switch (GetDragHdlKind())
2162 : {
2163 0 : case HDL_UPPER: eRefHdl=HDL_LOWER; break;
2164 0 : case HDL_LOWER: eRefHdl=HDL_UPPER; break;
2165 0 : case HDL_LEFT : eRefHdl=HDL_RIGHT; bVertical=true; break;
2166 0 : case HDL_RIGHT: eRefHdl=HDL_LEFT ; bVertical=true; break;
2167 0 : default: break;
2168 : }
2169 :
2170 0 : if (eRefHdl!=HDL_MOVE)
2171 0 : pRefHdl=GetHdlList().GetHdl(eRefHdl);
2172 :
2173 0 : if (pRefHdl!=NULL)
2174 : {
2175 0 : DragStat().Ref1()=pRefHdl->GetPos();
2176 0 : nWink0=GetAngle(DragStat().GetStart()-DragStat().GetRef1());
2177 : }
2178 : else
2179 : {
2180 : OSL_FAIL("SdrDragShear::BeginSdrDrag(): No reference point handle for shearing found.");
2181 0 : return false;
2182 : }
2183 :
2184 0 : Show();
2185 0 : return true;
2186 : }
2187 :
2188 0 : basegfx::B2DHomMatrix SdrDragShear::getCurrentTransformation()
2189 : {
2190 : basegfx::B2DHomMatrix aRetval(basegfx::tools::createTranslateB2DHomMatrix(
2191 0 : -DragStat().GetRef1().X(), -DragStat().GetRef1().Y()));
2192 :
2193 0 : if (bResize)
2194 : {
2195 0 : if (bVertical)
2196 : {
2197 0 : aRetval.scale(aFact, 1.0);
2198 0 : aRetval.shearY(-nTan);
2199 : }
2200 : else
2201 : {
2202 0 : aRetval.scale(1.0, aFact);
2203 0 : aRetval.shearX(-nTan);
2204 : }
2205 : }
2206 :
2207 0 : aRetval.translate(DragStat().GetRef1().X(), DragStat().GetRef1().Y());
2208 :
2209 0 : return aRetval;
2210 : }
2211 :
2212 0 : void SdrDragShear::MoveSdrDrag(const Point& rPnt)
2213 : {
2214 0 : if (DragStat().CheckMinMoved(rPnt))
2215 : {
2216 0 : bResize=!getSdrDragView().IsOrtho();
2217 0 : long nSA=0;
2218 :
2219 0 : if (getSdrDragView().IsAngleSnapEnabled())
2220 0 : nSA=getSdrDragView().GetSnapAngle();
2221 :
2222 0 : Point aP0(DragStat().GetStart());
2223 0 : Point aPnt(rPnt);
2224 0 : Fraction aNeuFact(1,1);
2225 :
2226 : // if angle snapping not activated, snap to raster (except when using slant)
2227 0 : if (nSA==0 && !bSlant)
2228 0 : aPnt=GetSnapPos(aPnt);
2229 :
2230 0 : if (!bSlant && !bResize)
2231 : { // shear, but no resize
2232 0 : if (bVertical)
2233 0 : aPnt.X()=aP0.X();
2234 : else
2235 0 : aPnt.Y()=aP0.Y();
2236 : }
2237 :
2238 0 : Point aRef(DragStat().GetRef1());
2239 0 : Point aDif(aPnt-aRef);
2240 :
2241 0 : long nNeuWink=0;
2242 :
2243 0 : if (bSlant)
2244 : {
2245 0 : nNeuWink=NormAngle180(-(GetAngle(aDif)-nWink0));
2246 :
2247 0 : if (bVertical)
2248 0 : nNeuWink=NormAngle180(-nNeuWink);
2249 : }
2250 : else
2251 : {
2252 0 : if (bVertical)
2253 0 : nNeuWink=NormAngle180(GetAngle(aDif));
2254 : else
2255 0 : nNeuWink=NormAngle180(-(GetAngle(aDif)-9000));
2256 :
2257 0 : if (nNeuWink<-9000 || nNeuWink>9000)
2258 0 : nNeuWink=NormAngle180(nNeuWink+18000);
2259 :
2260 0 : if (bResize)
2261 : {
2262 0 : Point aPt2(aPnt);
2263 :
2264 0 : if (nSA!=0)
2265 0 : aPt2=GetSnapPos(aPnt); // snap this one in any case
2266 :
2267 0 : if (bVertical)
2268 : {
2269 0 : aNeuFact=Fraction(aPt2.X()-aRef.X(),aP0.X()-aRef.X());
2270 : }
2271 : else
2272 : {
2273 0 : aNeuFact=Fraction(aPt2.Y()-aRef.Y(),aP0.Y()-aRef.Y());
2274 : }
2275 : }
2276 : }
2277 :
2278 0 : bool bNeg=nNeuWink<0;
2279 :
2280 0 : if (bNeg)
2281 0 : nNeuWink=-nNeuWink;
2282 :
2283 0 : if (nSA!=0)
2284 : { // angle snapping
2285 0 : nNeuWink+=nSA/2;
2286 0 : nNeuWink/=nSA;
2287 0 : nNeuWink*=nSA;
2288 : }
2289 :
2290 0 : nNeuWink=NormAngle360(nNeuWink);
2291 0 : bUpSideDown=nNeuWink>9000 && nNeuWink<27000;
2292 :
2293 0 : if (bSlant)
2294 : { // calculate resize for slant
2295 : // when angle snapping is activated, disable 89 degree limit
2296 0 : long nTmpWink=nNeuWink;
2297 0 : if (bUpSideDown) nNeuWink-=18000;
2298 0 : if (bNeg) nTmpWink=-nTmpWink;
2299 0 : bResize=true;
2300 0 : double nCos=cos(nTmpWink*nPi180);
2301 0 : aNeuFact=nCos;
2302 0 : Kuerzen(aFact,10); // three decimals should be enough
2303 : }
2304 :
2305 0 : if (nNeuWink>8900)
2306 0 : nNeuWink=8900;
2307 :
2308 0 : if (bNeg)
2309 0 : nNeuWink=-nNeuWink;
2310 :
2311 0 : if (nWink!=nNeuWink || aFact!=aNeuFact)
2312 : {
2313 0 : nWink=nNeuWink;
2314 0 : aFact=aNeuFact;
2315 0 : double a=nWink*nPi180;
2316 0 : double nTan1=0.0;
2317 0 : nTan1=tan(a); // calculate now, so as little time as possible passes between Hide() and Show()
2318 0 : Hide();
2319 0 : nTan=nTan1;
2320 0 : DragStat().NextMove(rPnt);
2321 0 : Show();
2322 : }
2323 : }
2324 0 : }
2325 :
2326 0 : void SdrDragShear::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
2327 : {
2328 0 : if (bResize)
2329 : {
2330 0 : if (bVertical)
2331 : {
2332 0 : rTarget.Resize(DragStat().GetRef1(),aFact,Fraction(1,1));
2333 : }
2334 : else
2335 : {
2336 0 : rTarget.Resize(DragStat().GetRef1(),Fraction(1,1),aFact);
2337 : }
2338 : }
2339 :
2340 0 : if (nWink!=0)
2341 : {
2342 0 : rTarget.Shear(DragStat().GetRef1(),nWink,tan(nWink*nPi180),bVertical);
2343 : }
2344 0 : }
2345 :
2346 0 : bool SdrDragShear::EndSdrDrag(bool bCopy)
2347 : {
2348 0 : Hide();
2349 :
2350 0 : if (bResize && aFact==Fraction(1,1))
2351 0 : bResize=false;
2352 :
2353 0 : if (nWink!=0 || bResize)
2354 : {
2355 0 : if (nWink!=0 && bResize)
2356 : {
2357 0 : XubString aStr;
2358 0 : ImpTakeDescriptionStr(STR_EditShear,aStr);
2359 :
2360 0 : if (bCopy)
2361 0 : aStr+=ImpGetResStr(STR_EditWithCopy);
2362 :
2363 0 : getSdrDragView().BegUndo(aStr);
2364 : }
2365 :
2366 0 : if (bResize)
2367 : {
2368 0 : if (bVertical)
2369 : {
2370 0 : getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),aFact,Fraction(1,1),bCopy);
2371 : }
2372 : else
2373 : {
2374 0 : getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),Fraction(1,1),aFact,bCopy);
2375 : }
2376 :
2377 0 : bCopy=false;
2378 : }
2379 :
2380 0 : if (nWink!=0)
2381 : {
2382 0 : getSdrDragView().ShearMarkedObj(DragStat().GetRef1(),nWink,bVertical,bCopy);
2383 : }
2384 :
2385 0 : if (nWink!=0 && bResize)
2386 0 : getSdrDragView().EndUndo();
2387 :
2388 0 : return true;
2389 : }
2390 :
2391 0 : return false;
2392 : }
2393 :
2394 0 : Pointer SdrDragShear::GetSdrDragPointer() const
2395 : {
2396 0 : if (bVertical)
2397 0 : return Pointer(POINTER_VSHEAR);
2398 : else
2399 0 : return Pointer(POINTER_HSHEAR);
2400 : }
2401 :
2402 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2403 :
2404 0 : TYPEINIT1(SdrDragMirror,SdrDragMethod);
2405 :
2406 0 : void SdrDragMirror::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
2407 : {
2408 0 : if(bMirrored)
2409 : {
2410 0 : rTarget.Mirror(DragStat().GetRef1(), DragStat().GetRef2());
2411 : }
2412 0 : }
2413 :
2414 0 : SdrDragMirror::SdrDragMirror(SdrDragView& rNewView)
2415 : : SdrDragMethod(rNewView),
2416 : nWink(0),
2417 : bMirrored(false),
2418 0 : bSide0(false)
2419 : {
2420 0 : }
2421 :
2422 0 : bool SdrDragMirror::ImpCheckSide(const Point& rPnt) const
2423 : {
2424 0 : long nWink1=GetAngle(rPnt-DragStat().GetRef1());
2425 0 : nWink1-=nWink;
2426 0 : nWink1=NormAngle360(nWink1);
2427 :
2428 0 : return nWink1<18000;
2429 : }
2430 :
2431 0 : void SdrDragMirror::TakeSdrDragComment(XubString& rStr) const
2432 : {
2433 0 : if (aDif.X()==0)
2434 0 : ImpTakeDescriptionStr(STR_DragMethMirrorHori,rStr);
2435 0 : else if (aDif.Y()==0)
2436 0 : ImpTakeDescriptionStr(STR_DragMethMirrorVert,rStr);
2437 0 : else if (Abs(aDif.X())==Abs(aDif.Y()))
2438 0 : ImpTakeDescriptionStr(STR_DragMethMirrorDiag,rStr);
2439 : else
2440 0 : ImpTakeDescriptionStr(STR_DragMethMirrorFree,rStr);
2441 :
2442 0 : if (getSdrDragView().IsDragWithCopy())
2443 0 : rStr+=ImpGetResStr(STR_EditWithCopy);
2444 0 : }
2445 :
2446 0 : bool SdrDragMirror::BeginSdrDrag()
2447 : {
2448 0 : SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
2449 0 : SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
2450 :
2451 0 : if (pH1!=NULL && pH2!=NULL)
2452 : {
2453 0 : DragStat().Ref1()=pH1->GetPos();
2454 0 : DragStat().Ref2()=pH2->GetPos();
2455 0 : Ref1()=pH1->GetPos();
2456 0 : Ref2()=pH2->GetPos();
2457 0 : aDif=pH2->GetPos()-pH1->GetPos();
2458 0 : bool b90=(aDif.X()==0) || aDif.Y()==0;
2459 0 : bool b45=b90 || (Abs(aDif.X())==Abs(aDif.Y()));
2460 0 : nWink=NormAngle360(GetAngle(aDif));
2461 :
2462 0 : if (!getSdrDragView().IsMirrorAllowed(false,false) && !b45)
2463 0 : return false; // free choice of axis angle not allowed
2464 :
2465 0 : if (!getSdrDragView().IsMirrorAllowed(true,false) && !b90)
2466 0 : return false; // 45 degrees not allowed either
2467 :
2468 0 : bSide0=ImpCheckSide(DragStat().GetStart());
2469 0 : Show();
2470 0 : return true;
2471 : }
2472 : else
2473 : {
2474 : OSL_FAIL("SdrDragMirror::BeginSdrDrag(): Axis of reflection not found.");
2475 0 : return false;
2476 : }
2477 : }
2478 :
2479 0 : basegfx::B2DHomMatrix SdrDragMirror::getCurrentTransformation()
2480 : {
2481 0 : basegfx::B2DHomMatrix aRetval;
2482 :
2483 0 : if (bMirrored)
2484 : {
2485 0 : const double fDeltaX(DragStat().GetRef2().X() - DragStat().GetRef1().X());
2486 0 : const double fDeltaY(DragStat().GetRef2().Y() - DragStat().GetRef1().Y());
2487 0 : const double fRotation(atan2(fDeltaY, fDeltaX));
2488 :
2489 0 : aRetval = basegfx::tools::createTranslateB2DHomMatrix(-DragStat().GetRef1().X(), -DragStat().GetRef1().Y());
2490 0 : aRetval.rotate(-fRotation);
2491 0 : aRetval.scale(1.0, -1.0);
2492 0 : aRetval.rotate(fRotation);
2493 0 : aRetval.translate(DragStat().GetRef1().X(), DragStat().GetRef1().Y());
2494 : }
2495 :
2496 0 : return aRetval;
2497 : }
2498 :
2499 0 : void SdrDragMirror::MoveSdrDrag(const Point& rPnt)
2500 : {
2501 0 : if (DragStat().CheckMinMoved(rPnt))
2502 : {
2503 0 : bool bNeuSide=ImpCheckSide(rPnt);
2504 0 : bool bNeuMirr=bSide0!=bNeuSide;
2505 :
2506 0 : if (bMirrored!=bNeuMirr)
2507 : {
2508 0 : Hide();
2509 0 : bMirrored=bNeuMirr;
2510 0 : DragStat().NextMove(rPnt);
2511 0 : Show();
2512 : }
2513 : }
2514 0 : }
2515 :
2516 0 : bool SdrDragMirror::EndSdrDrag(bool bCopy)
2517 : {
2518 0 : Hide();
2519 :
2520 0 : if (bMirrored)
2521 : {
2522 0 : getSdrDragView().MirrorMarkedObj(DragStat().GetRef1(),DragStat().GetRef2(),bCopy);
2523 : }
2524 :
2525 0 : return true;
2526 : }
2527 :
2528 0 : Pointer SdrDragMirror::GetSdrDragPointer() const
2529 : {
2530 0 : return Pointer(POINTER_MIRROR);
2531 : }
2532 :
2533 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2534 :
2535 0 : TYPEINIT1(SdrDragGradient, SdrDragMethod);
2536 :
2537 0 : SdrDragGradient::SdrDragGradient(SdrDragView& rNewView, bool bGrad)
2538 : : SdrDragMethod(rNewView),
2539 : pIAOHandle(NULL),
2540 0 : bIsGradient(bGrad)
2541 : {
2542 0 : }
2543 :
2544 0 : void SdrDragGradient::TakeSdrDragComment(XubString& rStr) const
2545 : {
2546 0 : if(IsGradient())
2547 0 : ImpTakeDescriptionStr(STR_DragMethGradient, rStr);
2548 : else
2549 0 : ImpTakeDescriptionStr(STR_DragMethTransparence, rStr);
2550 0 : }
2551 :
2552 0 : bool SdrDragGradient::BeginSdrDrag()
2553 : {
2554 0 : bool bRetval(false);
2555 :
2556 0 : pIAOHandle = (SdrHdlGradient*)GetHdlList().GetHdl(IsGradient() ? HDL_GRAD : HDL_TRNS);
2557 :
2558 0 : if(pIAOHandle)
2559 : {
2560 : // save old values
2561 0 : DragStat().Ref1() = pIAOHandle->GetPos();
2562 0 : DragStat().Ref2() = pIAOHandle->Get2ndPos();
2563 :
2564 : // what was hit?
2565 0 : bool bHit(false);
2566 0 : SdrHdlColor* pColHdl = pIAOHandle->GetColorHdl1();
2567 :
2568 : // init handling flags
2569 0 : pIAOHandle->SetMoveSingleHandle(false);
2570 0 : pIAOHandle->SetMoveFirstHandle(false);
2571 :
2572 : // test first color handle
2573 0 : if(pColHdl)
2574 : {
2575 0 : basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
2576 :
2577 0 : if(pColHdl->getOverlayObjectList().isHitLogic(aPosition))
2578 : {
2579 0 : bHit = true;
2580 0 : pIAOHandle->SetMoveSingleHandle(true);
2581 0 : pIAOHandle->SetMoveFirstHandle(true);
2582 0 : }
2583 : }
2584 :
2585 : // test second color handle
2586 0 : pColHdl = pIAOHandle->GetColorHdl2();
2587 :
2588 0 : if(!bHit && pColHdl)
2589 : {
2590 0 : basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
2591 :
2592 0 : if(pColHdl->getOverlayObjectList().isHitLogic(aPosition))
2593 : {
2594 0 : bHit = true;
2595 0 : pIAOHandle->SetMoveSingleHandle(true);
2596 0 : }
2597 : }
2598 :
2599 : // test gradient handle itself
2600 0 : if(!bHit)
2601 : {
2602 0 : basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
2603 :
2604 0 : if(pIAOHandle->getOverlayObjectList().isHitLogic(aPosition))
2605 : {
2606 0 : bHit = true;
2607 0 : }
2608 : }
2609 :
2610 : // everything up and running :o}
2611 0 : bRetval = bHit;
2612 : }
2613 : else
2614 : {
2615 : OSL_FAIL("SdrDragGradient::BeginSdrDrag(): IAOGradient not found.");
2616 : }
2617 :
2618 0 : return bRetval;
2619 : }
2620 :
2621 0 : void SdrDragGradient::MoveSdrDrag(const Point& rPnt)
2622 : {
2623 0 : if(pIAOHandle && DragStat().CheckMinMoved(rPnt))
2624 : {
2625 0 : DragStat().NextMove(rPnt);
2626 :
2627 : // Do the Move here!!! DragStat().GetStart()
2628 0 : Point aMoveDiff = rPnt - DragStat().GetStart();
2629 :
2630 0 : if(pIAOHandle->IsMoveSingleHandle())
2631 : {
2632 0 : if(pIAOHandle->IsMoveFirstHandle())
2633 : {
2634 0 : pIAOHandle->SetPos(DragStat().Ref1() + aMoveDiff);
2635 0 : if(pIAOHandle->GetColorHdl1())
2636 0 : pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1() + aMoveDiff);
2637 : }
2638 : else
2639 : {
2640 0 : pIAOHandle->Set2ndPos(DragStat().Ref2() + aMoveDiff);
2641 0 : if(pIAOHandle->GetColorHdl2())
2642 0 : pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2() + aMoveDiff);
2643 : }
2644 : }
2645 : else
2646 : {
2647 0 : pIAOHandle->SetPos(DragStat().Ref1() + aMoveDiff);
2648 0 : pIAOHandle->Set2ndPos(DragStat().Ref2() + aMoveDiff);
2649 :
2650 0 : if(pIAOHandle->GetColorHdl1())
2651 0 : pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1() + aMoveDiff);
2652 :
2653 0 : if(pIAOHandle->GetColorHdl2())
2654 0 : pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2() + aMoveDiff);
2655 : }
2656 :
2657 : // new state
2658 0 : pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), false, false);
2659 : }
2660 0 : }
2661 :
2662 0 : bool SdrDragGradient::EndSdrDrag(bool /*bCopy*/)
2663 : {
2664 0 : Ref1() = pIAOHandle->GetPos();
2665 0 : Ref2() = pIAOHandle->Get2ndPos();
2666 :
2667 : // new state
2668 0 : pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), true, true);
2669 :
2670 0 : return true;
2671 : }
2672 :
2673 0 : void SdrDragGradient::CancelSdrDrag()
2674 : {
2675 : // restore old values
2676 0 : pIAOHandle->SetPos(DragStat().Ref1());
2677 0 : pIAOHandle->Set2ndPos(DragStat().Ref2());
2678 :
2679 0 : if(pIAOHandle->GetColorHdl1())
2680 0 : pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1());
2681 :
2682 0 : if(pIAOHandle->GetColorHdl2())
2683 0 : pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2());
2684 :
2685 : // new state
2686 0 : pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), true, false);
2687 0 : }
2688 :
2689 0 : Pointer SdrDragGradient::GetSdrDragPointer() const
2690 : {
2691 0 : return Pointer(POINTER_REFHAND);
2692 : }
2693 :
2694 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2695 :
2696 0 : TYPEINIT1(SdrDragCrook,SdrDragMethod);
2697 :
2698 0 : SdrDragCrook::SdrDragCrook(SdrDragView& rNewView)
2699 : : SdrDragMethod(rNewView),
2700 : aFact(1,1),
2701 : bContortionAllowed(false),
2702 : bNoContortionAllowed(false),
2703 : bContortion(false),
2704 : bResizeAllowed(false),
2705 : bResize(false),
2706 : bRotateAllowed(false),
2707 : bRotate(false),
2708 : bVertical(false),
2709 : bValid(false),
2710 : bLft(false),
2711 : bRgt(false),
2712 : bUpr(false),
2713 : bLwr(false),
2714 : bAtCenter(false),
2715 : nWink(0),
2716 : nMarkSize(0),
2717 0 : eMode(SDRCROOK_ROTATE)
2718 : {
2719 0 : }
2720 :
2721 0 : void SdrDragCrook::TakeSdrDragComment(XubString& rStr) const
2722 : {
2723 0 : ImpTakeDescriptionStr(!bContortion ? STR_DragMethCrook : STR_DragMethCrookContortion, rStr);
2724 :
2725 0 : if(bValid)
2726 : {
2727 0 : rStr.AppendAscii(" (");
2728 :
2729 0 : sal_Int32 nVal(nWink);
2730 :
2731 0 : if(bAtCenter)
2732 0 : nVal *= 2;
2733 :
2734 0 : nVal = Abs(nVal);
2735 0 : rtl::OUString aStr;
2736 0 : getSdrDragView().GetModel()->TakeWinkStr(nVal, aStr);
2737 0 : rStr.Append(aStr);
2738 0 : rStr += sal_Unicode(')');
2739 : }
2740 :
2741 0 : if(getSdrDragView().IsDragWithCopy())
2742 0 : rStr += ImpGetResStr(STR_EditWithCopy);
2743 0 : }
2744 :
2745 : // These defines parameterize the created raster
2746 : // for interactions
2747 : #define DRAG_CROOK_RASTER_MINIMUM (4)
2748 : #define DRAG_CROOK_RASTER_MAXIMUM (15)
2749 : #define DRAG_CROOK_RASTER_DISTANCE (30)
2750 :
2751 0 : basegfx::B2DPolyPolygon impCreateDragRaster(SdrPageView& rPageView, const Rectangle& rMarkRect)
2752 : {
2753 0 : basegfx::B2DPolyPolygon aRetval;
2754 :
2755 0 : if(rPageView.PageWindowCount())
2756 : {
2757 0 : OutputDevice& rOut = (rPageView.GetPageWindow(0)->GetPaintWindow().GetOutputDevice());
2758 0 : Rectangle aPixelSize = rOut.LogicToPixel(rMarkRect);
2759 0 : sal_uInt32 nHorDiv(aPixelSize.GetWidth() / DRAG_CROOK_RASTER_DISTANCE);
2760 0 : sal_uInt32 nVerDiv(aPixelSize.GetHeight() / DRAG_CROOK_RASTER_DISTANCE);
2761 :
2762 0 : if(nHorDiv > DRAG_CROOK_RASTER_MAXIMUM)
2763 0 : nHorDiv = DRAG_CROOK_RASTER_MAXIMUM;
2764 0 : if(nHorDiv < DRAG_CROOK_RASTER_MINIMUM)
2765 0 : nHorDiv = DRAG_CROOK_RASTER_MINIMUM;
2766 :
2767 0 : if(nVerDiv > DRAG_CROOK_RASTER_MAXIMUM)
2768 0 : nVerDiv = DRAG_CROOK_RASTER_MAXIMUM;
2769 0 : if(nVerDiv < DRAG_CROOK_RASTER_MINIMUM)
2770 0 : nVerDiv = DRAG_CROOK_RASTER_MINIMUM;
2771 :
2772 0 : const double fXLen(rMarkRect.GetWidth() / (double)nHorDiv);
2773 0 : const double fYLen(rMarkRect.GetHeight() / (double)nVerDiv);
2774 0 : double fYPos(rMarkRect.Top());
2775 : sal_uInt32 a, b;
2776 :
2777 0 : for(a = 0; a <= nVerDiv; a++)
2778 : {
2779 : // horizontal lines
2780 0 : for(b = 0; b < nHorDiv; b++)
2781 : {
2782 0 : basegfx::B2DPolygon aHorLineSegment;
2783 :
2784 0 : const double fNewX(rMarkRect.Left() + (b * fXLen));
2785 0 : aHorLineSegment.append(basegfx::B2DPoint(fNewX, fYPos));
2786 : aHorLineSegment.appendBezierSegment(
2787 : basegfx::B2DPoint(fNewX + (fXLen * (1.0 / 3.0)), fYPos),
2788 : basegfx::B2DPoint(fNewX + (fXLen * (2.0 / 3.0)), fYPos),
2789 0 : basegfx::B2DPoint(fNewX + fXLen, fYPos));
2790 0 : aRetval.append(aHorLineSegment);
2791 0 : }
2792 :
2793 : // increments
2794 0 : fYPos += fYLen;
2795 : }
2796 :
2797 0 : double fXPos(rMarkRect.Left());
2798 :
2799 0 : for(a = 0; a <= nHorDiv; a++)
2800 : {
2801 : // vertical lines
2802 0 : for(b = 0; b < nVerDiv; b++)
2803 : {
2804 0 : basegfx::B2DPolygon aVerLineSegment;
2805 :
2806 0 : const double fNewY(rMarkRect.Top() + (b * fYLen));
2807 0 : aVerLineSegment.append(basegfx::B2DPoint(fXPos, fNewY));
2808 : aVerLineSegment.appendBezierSegment(
2809 : basegfx::B2DPoint(fXPos, fNewY + (fYLen * (1.0 / 3.0))),
2810 : basegfx::B2DPoint(fXPos, fNewY + (fYLen * (2.0 / 3.0))),
2811 0 : basegfx::B2DPoint(fXPos, fNewY + fYLen));
2812 0 : aRetval.append(aVerLineSegment);
2813 0 : }
2814 :
2815 : // increments
2816 0 : fXPos += fXLen;
2817 : }
2818 : }
2819 :
2820 0 : return aRetval;
2821 : }
2822 :
2823 0 : void SdrDragCrook::createSdrDragEntries()
2824 : {
2825 : // Add extended frame raster first, so it will be behind objects
2826 0 : if(getSdrDragView().GetSdrPageView())
2827 : {
2828 0 : const basegfx::B2DPolyPolygon aDragRaster(impCreateDragRaster(*getSdrDragView().GetSdrPageView(), GetMarkedRect()));
2829 :
2830 0 : if(aDragRaster.count())
2831 : {
2832 0 : addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragRaster));
2833 0 : }
2834 : }
2835 :
2836 : // call parent
2837 0 : SdrDragMethod::createSdrDragEntries();
2838 0 : }
2839 :
2840 0 : bool SdrDragCrook::BeginSdrDrag()
2841 : {
2842 0 : bContortionAllowed=getSdrDragView().IsCrookAllowed(false);
2843 0 : bNoContortionAllowed=getSdrDragView().IsCrookAllowed(true);
2844 0 : bResizeAllowed=getSdrDragView().IsResizeAllowed(false);
2845 0 : bRotateAllowed=getSdrDragView().IsRotateAllowed(false);
2846 :
2847 0 : if (bContortionAllowed || bNoContortionAllowed)
2848 : {
2849 0 : bVertical=(GetDragHdlKind()==HDL_LOWER || GetDragHdlKind()==HDL_UPPER);
2850 0 : aMarkRect=GetMarkedRect();
2851 0 : aMarkCenter=aMarkRect.Center();
2852 0 : nMarkSize=bVertical ? (aMarkRect.GetHeight()-1) : (aMarkRect.GetWidth()-1);
2853 0 : aCenter=aMarkCenter;
2854 0 : aStart=DragStat().GetStart();
2855 0 : Show();
2856 0 : return true;
2857 : }
2858 : else
2859 : {
2860 0 : return false;
2861 : }
2862 : }
2863 :
2864 0 : void SdrDragCrook::_MovAllPoints(basegfx::B2DPolyPolygon& rTarget)
2865 : {
2866 0 : SdrPageView* pPV = getSdrDragView().GetSdrPageView();
2867 :
2868 0 : if(pPV)
2869 : {
2870 0 : XPolyPolygon aTempPolyPoly(rTarget);
2871 :
2872 0 : if (pPV->HasMarkedObjPageView())
2873 : {
2874 0 : sal_uInt16 nPolyAnz=aTempPolyPoly.Count();
2875 :
2876 0 : if (!bContortion && !getSdrDragView().IsNoDragXorPolys())
2877 : {
2878 0 : sal_uInt16 n1st=0,nLast=0;
2879 0 : Point aC(aCenter);
2880 :
2881 0 : while (n1st<nPolyAnz)
2882 : {
2883 0 : nLast=n1st;
2884 0 : while (nLast<nPolyAnz && aTempPolyPoly[nLast].GetPointCount()!=0) nLast++;
2885 0 : Rectangle aBound(aTempPolyPoly[n1st].GetBoundRect());
2886 : sal_uInt16 i;
2887 :
2888 0 : for (i=n1st+1; i<nLast; i++)
2889 : {
2890 0 : aBound.Union(aTempPolyPoly[n1st].GetBoundRect());
2891 : }
2892 :
2893 0 : Point aCtr0(aBound.Center());
2894 0 : Point aCtr1(aCtr0);
2895 :
2896 0 : if (bResize)
2897 : {
2898 0 : Fraction aFact1(1,1);
2899 :
2900 0 : if (bVertical)
2901 : {
2902 0 : ResizePoint(aCtr1,aC,aFact1,aFact);
2903 : }
2904 : else
2905 : {
2906 0 : ResizePoint(aCtr1,aC,aFact,aFact1);
2907 : }
2908 : }
2909 :
2910 0 : bool bRotOk=false;
2911 0 : double nSin=0,nCos=0;
2912 :
2913 0 : if (aRad.X()!=0 && aRad.Y()!=0)
2914 : {
2915 0 : bRotOk=bRotate;
2916 :
2917 0 : switch (eMode)
2918 : {
2919 0 : case SDRCROOK_ROTATE : CrookRotateXPoint (aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical); break;
2920 0 : case SDRCROOK_SLANT : CrookSlantXPoint (aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical); break;
2921 0 : case SDRCROOK_STRETCH: CrookStretchXPoint(aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical,aMarkRect); break;
2922 : } // switch
2923 : }
2924 :
2925 0 : aCtr1-=aCtr0;
2926 :
2927 0 : for (i=n1st; i<nLast; i++)
2928 : {
2929 0 : if (bRotOk)
2930 : {
2931 0 : RotateXPoly(aTempPolyPoly[i],aCtr0,nSin,nCos);
2932 : }
2933 :
2934 0 : aTempPolyPoly[i].Move(aCtr1.X(),aCtr1.Y());
2935 : }
2936 :
2937 0 : n1st=nLast+1;
2938 : }
2939 : }
2940 : else
2941 : {
2942 : sal_uInt16 i,j;
2943 :
2944 0 : for (j=0; j<nPolyAnz; j++)
2945 : {
2946 0 : XPolygon& aPol=aTempPolyPoly[j];
2947 0 : sal_uInt16 nPtAnz=aPol.GetPointCount();
2948 0 : i=0;
2949 :
2950 0 : while (i<nPtAnz)
2951 : {
2952 0 : Point* pPnt=&aPol[i];
2953 0 : Point* pC1=NULL;
2954 0 : Point* pC2=NULL;
2955 :
2956 0 : if (i+1<nPtAnz && aPol.IsControl(i))
2957 : { // control point on the left
2958 0 : pC1=pPnt;
2959 0 : i++;
2960 0 : pPnt=&aPol[i];
2961 : }
2962 :
2963 0 : i++;
2964 :
2965 0 : if (i<nPtAnz && aPol.IsControl(i))
2966 : { // control point on the right
2967 0 : pC2=&aPol[i];
2968 0 : i++;
2969 : }
2970 :
2971 0 : _MovCrookPoint(*pPnt,pC1,pC2);
2972 : }
2973 : }
2974 : }
2975 : }
2976 :
2977 0 : rTarget = aTempPolyPoly.getB2DPolyPolygon();
2978 : }
2979 0 : }
2980 :
2981 0 : void SdrDragCrook::_MovCrookPoint(Point& rPnt, Point* pC1, Point* pC2)
2982 : {
2983 0 : bool bVert=bVertical;
2984 0 : bool bC1=pC1!=NULL;
2985 0 : bool bC2=pC2!=NULL;
2986 0 : Point aC(aCenter);
2987 :
2988 0 : if (bResize)
2989 : {
2990 0 : Fraction aFact1(1,1);
2991 :
2992 0 : if (bVert)
2993 : {
2994 0 : ResizePoint(rPnt,aC,aFact1,aFact);
2995 :
2996 0 : if (bC1)
2997 0 : ResizePoint(*pC1,aC,aFact1,aFact);
2998 :
2999 0 : if (bC2)
3000 0 : ResizePoint(*pC2,aC,aFact1,aFact);
3001 : }
3002 : else
3003 : {
3004 0 : ResizePoint(rPnt,aC,aFact,aFact1);
3005 :
3006 0 : if (bC1)
3007 0 : ResizePoint(*pC1,aC,aFact,aFact1);
3008 :
3009 0 : if (bC2)
3010 0 : ResizePoint(*pC2,aC,aFact,aFact1);
3011 : }
3012 : }
3013 :
3014 0 : if (aRad.X()!=0 && aRad.Y()!=0)
3015 : {
3016 : double nSin,nCos;
3017 :
3018 0 : switch (eMode)
3019 : {
3020 0 : case SDRCROOK_ROTATE : CrookRotateXPoint (rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert); break;
3021 0 : case SDRCROOK_SLANT : CrookSlantXPoint (rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert); break;
3022 0 : case SDRCROOK_STRETCH: CrookStretchXPoint(rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert,aMarkRect); break;
3023 : } // switch
3024 : }
3025 0 : }
3026 :
3027 0 : void SdrDragCrook::MoveSdrDrag(const Point& rPnt)
3028 : {
3029 0 : if (DragStat().CheckMinMoved(rPnt))
3030 : {
3031 0 : Point aPnt(rPnt);
3032 0 : bool bNeuMoveOnly=getSdrDragView().IsMoveOnlyDragging();
3033 0 : bAtCenter=false;
3034 0 : SdrCrookMode eNeuMode=getSdrDragView().GetCrookMode();
3035 0 : bool bNeuContortion=!bNeuMoveOnly && ((bContortionAllowed && !getSdrDragView().IsCrookNoContortion()) || !bNoContortionAllowed);
3036 0 : bResize=!getSdrDragView().IsOrtho() && bResizeAllowed && !bNeuMoveOnly;
3037 0 : bool bNeuRotate=bRotateAllowed && !bNeuContortion && !bNeuMoveOnly && eNeuMode==SDRCROOK_ROTATE;
3038 0 : long nSA=0;
3039 :
3040 0 : if (nSA==0)
3041 0 : aPnt=GetSnapPos(aPnt);
3042 :
3043 0 : Point aNeuCenter(aMarkCenter.X(),aStart.Y());
3044 :
3045 0 : if (bVertical)
3046 : {
3047 0 : aNeuCenter.X()=aStart.X();
3048 0 : aNeuCenter.Y()=aMarkCenter.Y();
3049 : }
3050 :
3051 0 : if (!getSdrDragView().IsCrookAtCenter())
3052 : {
3053 0 : switch (GetDragHdlKind())
3054 : {
3055 0 : case HDL_UPLFT: aNeuCenter.X()=aMarkRect.Right(); bLft=true; break;
3056 0 : case HDL_UPPER: aNeuCenter.Y()=aMarkRect.Bottom(); bUpr=true; break;
3057 0 : case HDL_UPRGT: aNeuCenter.X()=aMarkRect.Left(); bRgt=true; break;
3058 0 : case HDL_LEFT : aNeuCenter.X()=aMarkRect.Right(); bLft=true; break;
3059 0 : case HDL_RIGHT: aNeuCenter.X()=aMarkRect.Left(); bRgt=true; break;
3060 0 : case HDL_LWLFT: aNeuCenter.X()=aMarkRect.Right(); bLft=true; break;
3061 0 : case HDL_LOWER: aNeuCenter.Y()=aMarkRect.Top(); bLwr=true; break;
3062 0 : case HDL_LWRGT: aNeuCenter.X()=aMarkRect.Left(); bRgt=true; break;
3063 0 : default: bAtCenter=true;
3064 : }
3065 : }
3066 : else
3067 0 : bAtCenter=true;
3068 :
3069 0 : Fraction aNeuFact(1,1);
3070 0 : long dx1=aPnt.X()-aNeuCenter.X();
3071 0 : long dy1=aPnt.Y()-aNeuCenter.Y();
3072 0 : bValid=bVertical ? dx1!=0 : dy1!=0;
3073 :
3074 0 : if (bValid)
3075 : {
3076 0 : if (bVertical)
3077 0 : bValid=Abs(dx1)*100>Abs(dy1);
3078 : else
3079 0 : bValid=Abs(dy1)*100>Abs(dx1);
3080 : }
3081 :
3082 0 : long nNeuRad=0;
3083 0 : nWink=0;
3084 :
3085 0 : if (bValid)
3086 : {
3087 0 : double a=0; // slope of the radius
3088 0 : long nPntWink=0;
3089 :
3090 0 : if (bVertical)
3091 : {
3092 0 : a=((double)dy1)/((double)dx1); // slope of the radius
3093 0 : nNeuRad=((long)(dy1*a)+dx1) /2;
3094 0 : aNeuCenter.X()+=nNeuRad;
3095 0 : nPntWink=GetAngle(aPnt-aNeuCenter);
3096 : }
3097 : else
3098 : {
3099 0 : a=((double)dx1)/((double)dy1); // slope of the radius
3100 0 : nNeuRad=((long)(dx1*a)+dy1) /2;
3101 0 : aNeuCenter.Y()+=nNeuRad;
3102 0 : nPntWink=GetAngle(aPnt-aNeuCenter)-9000;
3103 : }
3104 :
3105 0 : if (!bAtCenter)
3106 : {
3107 0 : if (nNeuRad<0)
3108 : {
3109 0 : if (bRgt) nPntWink+=18000;
3110 0 : if (bLft) nPntWink=18000-nPntWink;
3111 0 : if (bLwr) nPntWink=-nPntWink;
3112 : }
3113 : else
3114 : {
3115 0 : if (bRgt) nPntWink=-nPntWink;
3116 0 : if (bUpr) nPntWink=18000-nPntWink;
3117 0 : if (bLwr) nPntWink+=18000;
3118 : }
3119 :
3120 0 : nPntWink=NormAngle360(nPntWink);
3121 : }
3122 : else
3123 : {
3124 0 : if (nNeuRad<0) nPntWink+=18000;
3125 0 : if (bVertical) nPntWink=18000-nPntWink;
3126 0 : nPntWink=NormAngle180(nPntWink);
3127 0 : nPntWink=Abs(nPntWink);
3128 : }
3129 :
3130 0 : double nUmfang=2*Abs(nNeuRad)*nPi;
3131 :
3132 0 : if (bResize)
3133 : {
3134 0 : if (nSA!=0)
3135 : { // angle snapping
3136 0 : long nWink0=nPntWink;
3137 0 : nPntWink+=nSA/2;
3138 0 : nPntWink/=nSA;
3139 0 : nPntWink*=nSA;
3140 0 : BigInt a2(nNeuRad);
3141 0 : a2*=BigInt(nWink);
3142 0 : a2/=BigInt(nWink0);
3143 0 : nNeuRad=long(a2);
3144 :
3145 0 : if (bVertical)
3146 0 : aNeuCenter.X()=aStart.X()+nNeuRad;
3147 : else
3148 0 : aNeuCenter.Y()=aStart.Y()+nNeuRad;
3149 : }
3150 :
3151 0 : long nMul=(long)(nUmfang*NormAngle360(nPntWink)/36000);
3152 :
3153 0 : if (bAtCenter)
3154 0 : nMul*=2;
3155 :
3156 0 : aNeuFact=Fraction(nMul,nMarkSize);
3157 0 : nWink=nPntWink;
3158 : }
3159 : else
3160 : {
3161 0 : nWink=(long)((nMarkSize*360/nUmfang)*100)/2;
3162 :
3163 0 : if (nWink==0)
3164 0 : bValid=false;
3165 :
3166 0 : if (bValid && nSA!=0)
3167 : { // angle snapping
3168 0 : long nWink0=nWink;
3169 0 : nWink+=nSA/2;
3170 0 : nWink/=nSA;
3171 0 : nWink*=nSA;
3172 0 : BigInt a2(nNeuRad);
3173 0 : a2*=BigInt(nWink);
3174 0 : a2/=BigInt(nWink0);
3175 0 : nNeuRad=long(a2);
3176 :
3177 0 : if (bVertical)
3178 0 : aNeuCenter.X()=aStart.X()+nNeuRad;
3179 : else
3180 0 : aNeuCenter.Y()=aStart.Y()+nNeuRad;
3181 : }
3182 : }
3183 : }
3184 :
3185 0 : if (nWink==0 || nNeuRad==0)
3186 0 : bValid=false;
3187 :
3188 0 : if (!bValid)
3189 0 : nNeuRad=0;
3190 :
3191 0 : if (!bValid && bResize)
3192 : {
3193 0 : long nMul=bVertical ? dy1 : dx1;
3194 :
3195 0 : if (bLft || bUpr)
3196 0 : nMul=-nMul;
3197 :
3198 0 : long nDiv=nMarkSize;
3199 :
3200 0 : if (bAtCenter)
3201 : {
3202 0 : nMul*=2;
3203 0 : nMul=Abs(nMul);
3204 : }
3205 :
3206 0 : aNeuFact=Fraction(nMul,nDiv);
3207 : }
3208 :
3209 0 : if (aNeuCenter!=aCenter || bNeuContortion!=bContortion || aNeuFact!=aFact ||
3210 0 : bNeuMoveOnly != getMoveOnly() || bNeuRotate!=bRotate || eNeuMode!=eMode)
3211 : {
3212 0 : Hide();
3213 0 : setMoveOnly(bNeuMoveOnly);
3214 0 : bRotate=bNeuRotate;
3215 0 : eMode=eNeuMode;
3216 0 : bContortion=bNeuContortion;
3217 0 : aCenter=aNeuCenter;
3218 0 : aFact=aNeuFact;
3219 0 : aRad=Point(nNeuRad,nNeuRad);
3220 0 : bResize=aFact!=Fraction(1,1) && aFact.GetDenominator()!=0 && aFact.IsValid();
3221 0 : DragStat().NextMove(aPnt);
3222 0 : Show();
3223 : }
3224 : }
3225 0 : }
3226 :
3227 0 : void SdrDragCrook::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
3228 : {
3229 0 : const bool bDoResize(aFact!=Fraction(1,1));
3230 0 : const bool bDoCrook(aCenter!=aMarkCenter && aRad.X()!=0 && aRad.Y()!=0);
3231 :
3232 0 : if (bDoCrook || bDoResize)
3233 : {
3234 0 : if (bDoResize)
3235 : {
3236 0 : Fraction aFact1(1,1);
3237 :
3238 0 : if (bContortion)
3239 : {
3240 0 : if (bVertical)
3241 : {
3242 0 : rTarget.Resize(aCenter,aFact1,aFact);
3243 : }
3244 : else
3245 : {
3246 0 : rTarget.Resize(aCenter,aFact,aFact1);
3247 : }
3248 : }
3249 : else
3250 : {
3251 0 : Point aCtr0(rTarget.GetSnapRect().Center());
3252 0 : Point aCtr1(aCtr0);
3253 :
3254 0 : if (bVertical)
3255 : {
3256 0 : ResizePoint(aCtr1,aCenter,aFact1,aFact);
3257 : }
3258 : else
3259 : {
3260 0 : ResizePoint(aCtr1,aCenter,aFact,aFact1);
3261 : }
3262 :
3263 0 : Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
3264 :
3265 0 : rTarget.Move(aSiz);
3266 : }
3267 : }
3268 :
3269 0 : if (bDoCrook)
3270 : {
3271 0 : const Rectangle aLocalMarkRect(getSdrDragView().GetMarkedObjRect());
3272 0 : const bool bLocalRotate(!bContortion && eMode == SDRCROOK_ROTATE && getSdrDragView().IsRotateAllowed(false));
3273 :
3274 0 : getSdrDragView().ImpCrookObj(&rTarget,aCenter,aRad,eMode,bVertical,!bContortion,bLocalRotate,aLocalMarkRect);
3275 : }
3276 : }
3277 0 : }
3278 :
3279 0 : void SdrDragCrook::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
3280 : {
3281 : // use helper derived from old stuff
3282 0 : _MovAllPoints(rTarget);
3283 0 : }
3284 :
3285 0 : bool SdrDragCrook::EndSdrDrag(bool bCopy)
3286 : {
3287 0 : Hide();
3288 :
3289 0 : if (bResize && aFact==Fraction(1,1))
3290 0 : bResize=false;
3291 :
3292 0 : const bool bUndo = getSdrDragView().IsUndoEnabled();
3293 :
3294 0 : bool bDoCrook=aCenter!=aMarkCenter && aRad.X()!=0 && aRad.Y()!=0;
3295 :
3296 0 : if (bDoCrook || bResize)
3297 : {
3298 0 : if (bResize && bUndo)
3299 : {
3300 0 : XubString aStr;
3301 0 : ImpTakeDescriptionStr(!bContortion?STR_EditCrook:STR_EditCrookContortion,aStr);
3302 :
3303 0 : if (bCopy)
3304 0 : aStr+=ImpGetResStr(STR_EditWithCopy);
3305 :
3306 0 : getSdrDragView().BegUndo(aStr);
3307 : }
3308 :
3309 0 : if (bResize)
3310 : {
3311 0 : Fraction aFact1(1,1);
3312 :
3313 0 : if (bContortion)
3314 : {
3315 0 : if (bVertical)
3316 0 : getSdrDragView().ResizeMarkedObj(aCenter,aFact1,aFact,bCopy);
3317 : else
3318 0 : getSdrDragView().ResizeMarkedObj(aCenter,aFact,aFact1,bCopy);
3319 : }
3320 : else
3321 : {
3322 0 : if (bCopy)
3323 0 : getSdrDragView().CopyMarkedObj();
3324 :
3325 0 : sal_uLong nMarkAnz=getSdrDragView().GetMarkedObjectList().GetMarkCount();
3326 :
3327 0 : for (sal_uLong nm=0; nm<nMarkAnz; nm++)
3328 : {
3329 0 : SdrMark* pM=getSdrDragView().GetMarkedObjectList().GetMark(nm);
3330 0 : SdrObject* pO=pM->GetMarkedSdrObj();
3331 0 : Point aCtr0(pO->GetSnapRect().Center());
3332 0 : Point aCtr1(aCtr0);
3333 :
3334 0 : if (bVertical)
3335 0 : ResizePoint(aCtr1,aCenter,aFact1,aFact);
3336 : else
3337 0 : ResizePoint(aCtr1,aCenter,aFact,aFact1);
3338 :
3339 0 : Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
3340 0 : if( bUndo )
3341 0 : AddUndo(getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pO,aSiz));
3342 0 : pO->Move(aSiz);
3343 : }
3344 : }
3345 :
3346 0 : bCopy=false;
3347 : }
3348 :
3349 0 : if (bDoCrook)
3350 : {
3351 0 : getSdrDragView().CrookMarkedObj(aCenter,aRad,eMode,bVertical,!bContortion,bCopy);
3352 0 : getSdrDragView().SetLastCrookCenter(aCenter);
3353 : }
3354 :
3355 0 : if (bResize && bUndo)
3356 0 : getSdrDragView().EndUndo();
3357 :
3358 0 : return true;
3359 : }
3360 :
3361 0 : return false;
3362 : }
3363 :
3364 0 : Pointer SdrDragCrook::GetSdrDragPointer() const
3365 : {
3366 0 : return Pointer(POINTER_CROOK);
3367 : }
3368 :
3369 : ////////////////////////////////////////////////////////////////////////////////////////////////////
3370 :
3371 0 : TYPEINIT1(SdrDragDistort,SdrDragMethod);
3372 :
3373 0 : SdrDragDistort::SdrDragDistort(SdrDragView& rNewView)
3374 : : SdrDragMethod(rNewView),
3375 : nPolyPt(0),
3376 : bContortionAllowed(false),
3377 : bNoContortionAllowed(false),
3378 0 : bContortion(false)
3379 : {
3380 0 : }
3381 :
3382 0 : void SdrDragDistort::TakeSdrDragComment(XubString& rStr) const
3383 : {
3384 0 : ImpTakeDescriptionStr(STR_DragMethDistort, rStr);
3385 :
3386 0 : rtl::OUString aStr;
3387 :
3388 0 : rStr.AppendAscii(" (x=");
3389 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
3390 0 : rStr.Append(aStr);
3391 0 : rStr.AppendAscii(" y=");
3392 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
3393 0 : rStr.Append(aStr);
3394 0 : rStr += sal_Unicode(')');
3395 :
3396 0 : if(getSdrDragView().IsDragWithCopy())
3397 0 : rStr += ImpGetResStr(STR_EditWithCopy);
3398 0 : }
3399 :
3400 0 : void SdrDragDistort::createSdrDragEntries()
3401 : {
3402 : // Add extended frame raster first, so it will be behind objects
3403 0 : if(getSdrDragView().GetSdrPageView())
3404 : {
3405 0 : const basegfx::B2DPolyPolygon aDragRaster(impCreateDragRaster(*getSdrDragView().GetSdrPageView(), GetMarkedRect()));
3406 :
3407 0 : if(aDragRaster.count())
3408 : {
3409 0 : addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragRaster));
3410 0 : }
3411 : }
3412 :
3413 : // call parent
3414 0 : SdrDragMethod::createSdrDragEntries();
3415 0 : }
3416 :
3417 0 : bool SdrDragDistort::BeginSdrDrag()
3418 : {
3419 0 : bContortionAllowed=getSdrDragView().IsDistortAllowed(false);
3420 0 : bNoContortionAllowed=getSdrDragView().IsDistortAllowed(true);
3421 :
3422 0 : if (bContortionAllowed || bNoContortionAllowed)
3423 : {
3424 0 : SdrHdlKind eKind=GetDragHdlKind();
3425 0 : nPolyPt=0xFFFF;
3426 :
3427 0 : if (eKind==HDL_UPLFT) nPolyPt=0;
3428 0 : if (eKind==HDL_UPRGT) nPolyPt=1;
3429 0 : if (eKind==HDL_LWRGT) nPolyPt=2;
3430 0 : if (eKind==HDL_LWLFT) nPolyPt=3;
3431 0 : if (nPolyPt>3) return false;
3432 :
3433 0 : aMarkRect=GetMarkedRect();
3434 0 : aDistortedRect=XPolygon(aMarkRect);
3435 0 : Show();
3436 0 : return true;
3437 : }
3438 : else
3439 : {
3440 0 : return false;
3441 : }
3442 : }
3443 :
3444 0 : void SdrDragDistort::_MovAllPoints(basegfx::B2DPolyPolygon& rTarget)
3445 : {
3446 0 : if (bContortion)
3447 : {
3448 0 : SdrPageView* pPV = getSdrDragView().GetSdrPageView();
3449 :
3450 0 : if(pPV)
3451 : {
3452 0 : if (pPV->HasMarkedObjPageView())
3453 : {
3454 0 : basegfx::B2DPolyPolygon aDragPolygon(rTarget);
3455 0 : const basegfx::B2DRange aOriginalRange(aMarkRect.Left(), aMarkRect.Top(), aMarkRect.Right(), aMarkRect.Bottom());
3456 0 : const basegfx::B2DPoint aTopLeft(aDistortedRect[0].X(), aDistortedRect[0].Y());
3457 0 : const basegfx::B2DPoint aTopRight(aDistortedRect[1].X(), aDistortedRect[1].Y());
3458 0 : const basegfx::B2DPoint aBottomLeft(aDistortedRect[3].X(), aDistortedRect[3].Y());
3459 0 : const basegfx::B2DPoint aBottomRight(aDistortedRect[2].X(), aDistortedRect[2].Y());
3460 :
3461 0 : aDragPolygon = basegfx::tools::distort(aDragPolygon, aOriginalRange, aTopLeft, aTopRight, aBottomLeft, aBottomRight);
3462 0 : rTarget = aDragPolygon;
3463 : }
3464 : }
3465 : }
3466 0 : }
3467 :
3468 0 : void SdrDragDistort::MoveSdrDrag(const Point& rPnt)
3469 : {
3470 0 : if (DragStat().CheckMinMoved(rPnt))
3471 : {
3472 0 : Point aPnt(GetSnapPos(rPnt));
3473 :
3474 0 : if (getSdrDragView().IsOrtho())
3475 0 : OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
3476 :
3477 0 : bool bNeuContortion=(bContortionAllowed && !getSdrDragView().IsCrookNoContortion()) || !bNoContortionAllowed;
3478 :
3479 0 : if (bNeuContortion!=bContortion || aDistortedRect[nPolyPt]!=aPnt)
3480 : {
3481 0 : Hide();
3482 0 : aDistortedRect[nPolyPt]=aPnt;
3483 0 : bContortion=bNeuContortion;
3484 0 : DragStat().NextMove(aPnt);
3485 0 : Show();
3486 : }
3487 : }
3488 0 : }
3489 :
3490 0 : bool SdrDragDistort::EndSdrDrag(bool bCopy)
3491 : {
3492 0 : Hide();
3493 0 : bool bDoDistort=DragStat().GetDX()!=0 || DragStat().GetDY()!=0;
3494 :
3495 0 : if (bDoDistort)
3496 : {
3497 0 : getSdrDragView().DistortMarkedObj(aMarkRect,aDistortedRect,!bContortion,bCopy);
3498 0 : return true;
3499 : }
3500 :
3501 0 : return false;
3502 : }
3503 :
3504 0 : Pointer SdrDragDistort::GetSdrDragPointer() const
3505 : {
3506 0 : return Pointer(POINTER_REFHAND);
3507 : }
3508 :
3509 0 : void SdrDragDistort::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
3510 : {
3511 0 : const bool bDoDistort(DragStat().GetDX()!=0 || DragStat().GetDY()!=0);
3512 :
3513 0 : if (bDoDistort)
3514 : {
3515 0 : getSdrDragView().ImpDistortObj(&rTarget, aMarkRect, aDistortedRect, !bContortion);
3516 : }
3517 0 : }
3518 :
3519 0 : void SdrDragDistort::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
3520 : {
3521 : // use helper derived from old stuff
3522 0 : _MovAllPoints(rTarget);
3523 0 : }
3524 :
3525 : ////////////////////////////////////////////////////////////////////////////////////////////////////
3526 :
3527 0 : TYPEINIT1(SdrDragCrop,SdrDragResize);
3528 :
3529 0 : SdrDragCrop::SdrDragCrop(SdrDragView& rNewView)
3530 0 : : SdrDragResize(rNewView)
3531 : {
3532 : // switch off solid dragging for crop; it just makes no sense since showing
3533 : // a 50% transparent object above the original will not be visible
3534 0 : setSolidDraggingActive(false);
3535 0 : }
3536 :
3537 0 : void SdrDragCrop::TakeSdrDragComment(XubString& rStr) const
3538 : {
3539 0 : ImpTakeDescriptionStr(STR_DragMethCrop, rStr);
3540 :
3541 0 : rtl::OUString aStr;
3542 :
3543 0 : rStr.AppendAscii(" (x=");
3544 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
3545 0 : rStr.Append(aStr);
3546 0 : rStr.AppendAscii(" y=");
3547 0 : getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
3548 0 : rStr.Append(aStr);
3549 0 : rStr += sal_Unicode(')');
3550 :
3551 0 : if(getSdrDragView().IsDragWithCopy())
3552 0 : rStr += ImpGetResStr(STR_EditWithCopy);
3553 0 : }
3554 :
3555 0 : bool SdrDragCrop::EndSdrDrag(bool bCopy)
3556 : {
3557 0 : Hide();
3558 :
3559 0 : if( DragStat().GetDX()==0 && DragStat().GetDY()==0 )
3560 0 : return false;
3561 :
3562 0 : const SdrMarkList& rMarkList = getSdrDragView().GetMarkedObjectList();
3563 :
3564 0 : if( rMarkList.GetMarkCount() != 1 )
3565 0 : return false;
3566 :
3567 0 : SdrGrafObj* pObj = dynamic_cast<SdrGrafObj*>( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
3568 :
3569 0 : if( !pObj || (pObj->GetGraphicType() == GRAPHIC_NONE) || (pObj->GetGraphicType() == GRAPHIC_DEFAULT) )
3570 0 : return false;
3571 :
3572 0 : const GraphicObject& rGraphicObject = pObj->GetGraphicObject();
3573 0 : const MapMode aMapMode100thmm(MAP_100TH_MM);
3574 0 : Size aGraphicSize(rGraphicObject.GetPrefSize());
3575 :
3576 0 : if( MAP_PIXEL == rGraphicObject.GetPrefMapMode().GetMapUnit() )
3577 0 : aGraphicSize = Application::GetDefaultDevice()->PixelToLogic( aGraphicSize, aMapMode100thmm );
3578 : else
3579 0 : aGraphicSize = Application::GetDefaultDevice()->LogicToLogic( aGraphicSize, rGraphicObject.GetPrefMapMode(), aMapMode100thmm);
3580 :
3581 0 : if( aGraphicSize.A() == 0 || aGraphicSize.B() == 0 )
3582 0 : return false;
3583 :
3584 0 : const SdrGrafCropItem& rOldCrop = (const SdrGrafCropItem&)pObj->GetMergedItem(SDRATTR_GRAFCROP);
3585 :
3586 0 : const bool bUndo = getSdrDragView().IsUndoEnabled();
3587 :
3588 0 : if( bUndo )
3589 : {
3590 0 : String aUndoStr;
3591 0 : ImpTakeDescriptionStr(STR_DragMethCrop, aUndoStr);
3592 :
3593 0 : getSdrDragView().BegUndo( aUndoStr );
3594 0 : getSdrDragView().AddUndo( getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
3595 : }
3596 :
3597 0 : Rectangle aOldRect( pObj->GetLogicRect() );
3598 0 : getSdrDragView().ResizeMarkedObj(DragStat().Ref1(),aXFact,aYFact,bCopy);
3599 0 : Rectangle aNewRect( pObj->GetLogicRect() );
3600 :
3601 0 : double fScaleX = ( aGraphicSize.Width() - rOldCrop.GetLeft() - rOldCrop.GetRight() ) / (double)aOldRect.GetWidth();
3602 0 : double fScaleY = ( aGraphicSize.Height() - rOldCrop.GetTop() - rOldCrop.GetBottom() ) / (double)aOldRect.GetHeight();
3603 :
3604 : // to correct the never working combination of cropped images and mirroring
3605 : // I have to correct the rectangles the calculation is based on here. In the current
3606 : // core geometry stuff a vertical mirror is expressed as 180 degree rotation. All
3607 : // this can be removed again when aw080 will have cleaned up the old
3608 : // (non-)transformation mess in the core.
3609 0 : if(18000 == pObj->GetGeoStat().nDrehWink)
3610 : {
3611 : // old notation of vertical mirror, need to correct diffs since both rects
3612 : // are rotated by 180 degrees
3613 0 : aOldRect = Rectangle(aOldRect.TopLeft() - (aOldRect.BottomRight() - aOldRect.TopLeft()), aOldRect.TopLeft());
3614 0 : aNewRect = Rectangle(aNewRect.TopLeft() - (aNewRect.BottomRight() - aNewRect.TopLeft()), aNewRect.TopLeft());
3615 : }
3616 :
3617 0 : sal_Int32 nDiffLeft = aNewRect.Left() - aOldRect.Left();
3618 0 : sal_Int32 nDiffTop = aNewRect.Top() - aOldRect.Top();
3619 0 : sal_Int32 nDiffRight = aNewRect.Right() - aOldRect.Right();
3620 0 : sal_Int32 nDiffBottom = aNewRect.Bottom() - aOldRect.Bottom();
3621 :
3622 0 : sal_Int32 nLeftCrop = static_cast<sal_Int32>( rOldCrop.GetLeft() + nDiffLeft * fScaleX );
3623 0 : sal_Int32 nTopCrop = static_cast<sal_Int32>( rOldCrop.GetTop() + nDiffTop * fScaleY );
3624 0 : sal_Int32 nRightCrop = static_cast<sal_Int32>( rOldCrop.GetRight() - nDiffRight * fScaleX );
3625 0 : sal_Int32 nBottomCrop = static_cast<sal_Int32>( rOldCrop.GetBottom() - nDiffBottom * fScaleY );
3626 :
3627 0 : SfxItemPool& rPool = getSdrDragView().GetModel()->GetItemPool();
3628 0 : SfxItemSet aSet( rPool, SDRATTR_GRAFCROP, SDRATTR_GRAFCROP );
3629 0 : aSet.Put( SdrGrafCropItem( nLeftCrop, nTopCrop, nRightCrop, nBottomCrop ) );
3630 0 : getSdrDragView().SetAttributes( aSet, false );
3631 :
3632 0 : if( bUndo )
3633 0 : getSdrDragView().EndUndo();
3634 :
3635 0 : return true;
3636 : }
3637 :
3638 0 : Pointer SdrDragCrop::GetSdrDragPointer() const
3639 : {
3640 0 : return Pointer(POINTER_CROP);
3641 : }
3642 :
3643 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|