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