xref: /aoo41x/main/svx/source/svdraw/svddrgv.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svddrgv.hxx>
28 #include "svx/xattr.hxx"
29 #include <svx/xpoly.hxx>
30 #include <svx/svdetc.hxx>
31 #include <svx/svdtrans.hxx>
32 #include <svx/svdundo.hxx>
33 #include <svx/svdocapt.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <svx/svdopath.hxx>
36 #include <svx/svdoedge.hxx>
37 #include "svx/svdstr.hrc"
38 #include "svx/svdglob.hxx"
39 #include "svddrgm1.hxx"
40 #include <svx/obj3d.hxx>
41 #include <svx/svdoashp.hxx>
42 #include <svx/sdrpaintwindow.hxx>
43 #include <basegfx/polygon/b2dpolypolygontools.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <svx/polypolygoneditor.hxx>
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <svx/sdr/overlay/overlaymanager.hxx>
48 
49 using namespace sdr;
50 
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 //
54 //  @@@@@  @@@@@   @@@@   @@@@   @@ @@ @@ @@@@@ @@   @@
55 //  @@  @@ @@  @@ @@  @@ @@  @@  @@ @@ @@ @@    @@   @@
56 //  @@  @@ @@  @@ @@  @@ @@      @@ @@ @@ @@    @@ @ @@
57 //  @@  @@ @@@@@  @@@@@@ @@ @@@  @@@@@ @@ @@@@  @@@@@@@
58 //  @@  @@ @@  @@ @@  @@ @@  @@   @@@  @@ @@    @@@@@@@
59 //  @@  @@ @@  @@ @@  @@ @@  @@   @@@  @@ @@    @@@ @@@
60 //  @@@@@  @@  @@ @@  @@  @@@@@    @   @@ @@@@@ @@   @@
61 //
62 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
64 
ImpClearVars()65 void SdrDragView::ImpClearVars()
66 {
67 	bFramDrag=sal_False;
68 	eDragMode=SDRDRAG_MOVE;
69 	bDragLimit=sal_False;
70 	bMarkedHitMovesAlways=sal_False;
71 	eDragHdl=HDL_MOVE;
72 	pDragHdl=NULL;
73 	bDragHdl=sal_False;
74 	bDragSpecial=sal_False;
75 	mpCurrentSdrDragMethod=NULL;
76 	bDragStripes=sal_False;
77 	bMirrRefDragObj=sal_True;
78 	bDragWithCopy=sal_False;
79 	pInsPointUndo=NULL;
80 	bInsGluePoint=sal_False;
81 	bInsObjPointMode=sal_False;
82 	bInsGluePointMode=sal_False;
83 	nDragXorPolyLimit=100;
84 	nDragXorPointLimit=500;
85 	bNoDragXorPolys=sal_False;
86 	bAutoVertexCon=sal_True;
87 	bAutoCornerCon=sal_False;
88 	bRubberEdgeDragging=sal_True;
89 	nRubberEdgeDraggingLimit=100;
90 	bDetailedEdgeDragging=sal_True;
91 	nDetailedEdgeDraggingLimit=10;
92 	bResizeAtCenter=sal_False;
93 	bCrookAtCenter=sal_False;
94 	bMouseHideWhileDraggingPoints=sal_False;
95 
96 	// init using default
97 	mbSolidDragging = getOptionsDrawinglayer().IsSolidDragCreate();
98 }
99 
ImpMakeDragAttr()100 void SdrDragView::ImpMakeDragAttr()
101 {
102 	ImpDelDragAttr();
103 }
104 
SdrDragView(SdrModel * pModel1,OutputDevice * pOut)105 SdrDragView::SdrDragView(SdrModel* pModel1, OutputDevice* pOut)
106 :	SdrExchangeView(pModel1,pOut)
107 {
108 	ImpClearVars();
109 	ImpMakeDragAttr();
110 }
111 
~SdrDragView()112 SdrDragView::~SdrDragView()
113 {
114 	ImpDelDragAttr();
115 }
116 
ImpDelDragAttr()117 void SdrDragView::ImpDelDragAttr()
118 {
119 }
120 
IsAction() const121 sal_Bool SdrDragView::IsAction() const
122 {
123 	return (mpCurrentSdrDragMethod || SdrExchangeView::IsAction());
124 }
125 
MovAction(const Point & rPnt)126 void SdrDragView::MovAction(const Point& rPnt)
127 {
128 	SdrExchangeView::MovAction(rPnt);
129 	if (mpCurrentSdrDragMethod)
130 	{
131 		MovDragObj(rPnt);
132 	}
133 }
134 
EndAction()135 void SdrDragView::EndAction()
136 {
137 	if (mpCurrentSdrDragMethod)
138 	{
139 		EndDragObj(sal_False);
140 	}
141 	SdrExchangeView::EndAction();
142 }
143 
BckAction()144 void SdrDragView::BckAction()
145 {
146 	SdrExchangeView::BckAction();
147 	BrkDragObj();
148 }
149 
BrkAction()150 void SdrDragView::BrkAction()
151 {
152 	SdrExchangeView::BrkAction();
153 	BrkDragObj();
154 }
155 
TakeActionRect(Rectangle & rRect) const156 void SdrDragView::TakeActionRect(Rectangle& rRect) const
157 {
158 	if (mpCurrentSdrDragMethod)
159 	{
160 		rRect=aDragStat.GetActionRect();
161 		if (rRect.IsEmpty())
162 		{
163 			SdrPageView* pPV = GetSdrPageView();
164 
165 			if(pPV&& pPV->HasMarkedObjPageView())
166 			{
167                 // #i95646# is this used..?
168                 const basegfx::B2DRange aBoundRange(mpCurrentSdrDragMethod->getCurrentRange());
169 				rRect = Rectangle(
170                     basegfx::fround(aBoundRange.getMinX()), basegfx::fround(aBoundRange.getMinY()),
171                     basegfx::fround(aBoundRange.getMaxX()), basegfx::fround(aBoundRange.getMaxY()));
172 			}
173 		}
174 		if (rRect.IsEmpty())
175 		{
176 			rRect=Rectangle(aDragStat.GetNow(),aDragStat.GetNow());
177 		}
178 	}
179 	else
180 	{
181 		SdrExchangeView::TakeActionRect(rRect);
182 	}
183 }
184 
TakeDragObjAnchorPos(Point & rPos,sal_Bool bTR) const185 sal_Bool SdrDragView::TakeDragObjAnchorPos(Point& rPos, sal_Bool bTR ) const
186 {
187 	Rectangle aR;
188 	TakeActionRect(aR);
189 	rPos = bTR ? aR.TopRight() : aR.TopLeft();
190 	if (GetMarkedObjectCount()==1 && IsDragObj() && // nur bei Einzelselektion
191 		!IsDraggingPoints() && !IsDraggingGluePoints() && // nicht beim Punkteschieben
192 		!mpCurrentSdrDragMethod->ISA(SdrDragMovHdl)) // nicht beim Handlesschieben
193 	{
194 		SdrObject* pObj=GetMarkedObjectByIndex(0);
195 		if (pObj->ISA(SdrCaptionObj))
196 		{
197 			Point aPt(((SdrCaptionObj*)pObj)->GetTailPos());
198 			sal_Bool bTail=eDragHdl==HDL_POLY; // Schwanz wird gedraggt (nicht so ganz feine Abfrage hier)
199 			sal_Bool bOwn=mpCurrentSdrDragMethod->ISA(SdrDragObjOwn); // Objektspeziefisch
200 			if (!bTail)
201 			{ // bei bTail liefert TakeActionRect schon das richtige
202 				if (bOwn)
203 				{ // bOwn kann sein MoveTextFrame, ResizeTextFrame aber eben nicht mehr DragTail
204 					rPos=aPt;
205 				}
206 				else
207 				{
208 					// drag the whole Object (Move, Resize, ...)
209 					const basegfx::B2DPoint aTransformed(mpCurrentSdrDragMethod->getCurrentTransformation() * basegfx::B2DPoint(aPt.X(), aPt.Y()));
210 					rPos.X() = basegfx::fround(aTransformed.getX());
211 					rPos.Y() = basegfx::fround(aTransformed.getY());
212 				}
213 			}
214 		}
215 		return sal_True;
216 	}
217 	return sal_False;
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////////////////////////
221 
TakeDragLimit(SdrDragMode,Rectangle &) const222 sal_Bool SdrDragView::TakeDragLimit(SdrDragMode /*eMode*/, Rectangle& /*rRect*/) const
223 {
224 	return sal_False;
225 }
226 
BegDragObj(const Point & rPnt,OutputDevice * pOut,SdrHdl * pHdl,short nMinMov,SdrDragMethod * pForcedMeth)227 sal_Bool SdrDragView::BegDragObj(const Point& rPnt, OutputDevice* pOut, SdrHdl* pHdl, short nMinMov, SdrDragMethod* pForcedMeth)
228 {
229 	BrkAction();
230 
231 	bool bRet=false;
232 	{
233 		SetDragWithCopy(sal_False);
234 		//ForceEdgesOfMarkedNodes();
235 		//TODO: aAni.Reset();
236 		mpCurrentSdrDragMethod=NULL;
237 		bDragSpecial=sal_False;
238 		bDragLimit=sal_False;
239 		SdrDragMode eTmpMode=eDragMode;
240 		if (eTmpMode==SDRDRAG_MOVE && pHdl!=NULL && pHdl->GetKind()!=HDL_MOVE) {
241 			eTmpMode=SDRDRAG_RESIZE;
242 		}
243 		bDragLimit=TakeDragLimit(eTmpMode,aDragLimit);
244 		bFramDrag=ImpIsFrameHandles();
245 		if (!bFramDrag &&
246 			(pMarkedObj==NULL || !pMarkedObj->hasSpecialDrag()) &&
247 			(pHdl==NULL || pHdl->GetObj()==NULL)) {
248 			bFramDrag=sal_True;
249 		}
250 
251 		Point aPnt(rPnt);
252 		if(pHdl == NULL
253 			|| pHdl->GetKind() == HDL_MOVE
254 			|| pHdl->GetKind() == HDL_MIRX
255 			|| pHdl->GetKind() == HDL_TRNS
256 			|| pHdl->GetKind() == HDL_GRAD)
257 		{
258 			aDragStat.Reset(aPnt);
259 		}
260 		else
261 		{
262 			aDragStat.Reset(pHdl->GetPos());
263 		}
264 
265 		aDragStat.SetView((SdrView*)this);
266 		aDragStat.SetPageView(pMarkedPV);  // <<-- hier muss die DragPV rein!!!
267 		aDragStat.SetMinMove(ImpGetMinMovLogic(nMinMov,pOut));
268 		aDragStat.SetHdl(pHdl);
269 		aDragStat.NextPoint();
270 		pDragWin=pOut;
271 		pDragHdl=pHdl;
272 		eDragHdl= pHdl==NULL ? HDL_MOVE : pHdl->GetKind();
273 		bDragHdl=eDragHdl==HDL_REF1 || eDragHdl==HDL_REF2 || eDragHdl==HDL_MIRX;
274 
275 		// #103894# Expand test for HDL_ANCHOR_TR
276 		sal_Bool bNotDraggable = (HDL_ANCHOR == eDragHdl || HDL_ANCHOR_TR == eDragHdl);
277 
278 		if(pHdl && (pHdl->GetKind() == HDL_SMARTTAG) && pForcedMeth )
279 		{
280 			// just use the forced method for smart tags
281 		}
282 		else if(bDragHdl)
283 		{
284 			mpCurrentSdrDragMethod = new SdrDragMovHdl(*this);
285 		}
286 		else if(!bNotDraggable)
287 		{
288 			switch (eDragMode)
289 			{
290 				case SDRDRAG_ROTATE: case SDRDRAG_SHEAR: case SDRDRAG_DISTORT:
291 				{
292 					switch (eDragHdl)
293 					{
294 						case HDL_LEFT:  case HDL_RIGHT:
295 						case HDL_UPPER: case HDL_LOWER:
296 						{
297 							// Sind 3D-Objekte selektiert?
298 							sal_Bool b3DObjSelected = sal_False;
299 							for(sal_uInt32 a=0;!b3DObjSelected && a<GetMarkedObjectCount();a++)
300 							{
301 								SdrObject* pObj = GetMarkedObjectByIndex(a);
302 								if(pObj && pObj->ISA(E3dObject))
303 									b3DObjSelected = sal_True;
304 							}
305 							// Falls ja, Shear auch bei !IsShearAllowed zulassen,
306 							// da es sich bei 3D-Objekten um eingeschraenkte
307 							// Rotationen handelt
308 							if (!b3DObjSelected && !IsShearAllowed())
309 								return sal_False;
310 							mpCurrentSdrDragMethod = new SdrDragShear(*this,eDragMode==SDRDRAG_ROTATE);
311 						} break;
312 						case HDL_UPLFT: case HDL_UPRGT:
313 						case HDL_LWLFT: case HDL_LWRGT:
314 						{
315 							if (eDragMode==SDRDRAG_SHEAR || eDragMode==SDRDRAG_DISTORT)
316 							{
317 								if (!IsDistortAllowed(sal_True) && !IsDistortAllowed(sal_False)) return sal_False;
318 								mpCurrentSdrDragMethod = new SdrDragDistort(*this);
319 							}
320 							else
321 							{
322 								if (!IsRotateAllowed(sal_True)) return sal_False;
323 								mpCurrentSdrDragMethod = new SdrDragRotate(*this);
324 							}
325 						} break;
326 						default:
327 						{
328 							if (IsMarkedHitMovesAlways() && eDragHdl==HDL_MOVE)
329 							{ // HDL_MOVE ist auch wenn Obj direkt getroffen
330 								if (!IsMoveAllowed()) return sal_False;
331 								mpCurrentSdrDragMethod = new SdrDragMove(*this);
332 							}
333 							else
334 							{
335 								if (!IsRotateAllowed(sal_True)) return sal_False;
336 								mpCurrentSdrDragMethod = new SdrDragRotate(*this);
337 							}
338 						}
339 					}
340 				} break;
341 				case SDRDRAG_MIRROR:
342 				{
343 					if (eDragHdl==HDL_MOVE && IsMarkedHitMovesAlways())
344 					{
345 						if (!IsMoveAllowed()) return sal_False;
346 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
347 					}
348 					else
349 					{
350 						if (!IsMirrorAllowed(sal_True,sal_True)) return sal_False;
351 						mpCurrentSdrDragMethod = new SdrDragMirror(*this);
352 					}
353 				} break;
354 
355 				case SDRDRAG_CROP:
356 				{
357 					if (eDragHdl==HDL_MOVE && IsMarkedHitMovesAlways())
358 					{
359 						if (!IsMoveAllowed())
360 							return sal_False;
361 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
362 					}
363 					else
364 					{
365 						if (!IsCrookAllowed(sal_True) && !IsCrookAllowed(sal_False))
366 							return sal_False;
367 						mpCurrentSdrDragMethod = new SdrDragCrop(*this);
368 					}
369 				}
370 				break;
371 
372 				case SDRDRAG_TRANSPARENCE:
373 				{
374 					if(eDragHdl == HDL_MOVE && IsMarkedHitMovesAlways())
375 					{
376 						if(!IsMoveAllowed())
377 							return sal_False;
378 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
379 					}
380 					else
381 					{
382 						if(!IsTransparenceAllowed())
383 							return sal_False;
384 
385 						mpCurrentSdrDragMethod = new SdrDragGradient(*this, sal_False);
386 					}
387 					break;
388 				}
389 				case SDRDRAG_GRADIENT:
390 				{
391 					if(eDragHdl == HDL_MOVE && IsMarkedHitMovesAlways())
392 					{
393 						if(!IsMoveAllowed())
394 							return sal_False;
395 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
396 					}
397 					else
398 					{
399 						if(!IsGradientAllowed())
400 							return sal_False;
401 
402 						mpCurrentSdrDragMethod = new SdrDragGradient(*this);
403 					}
404 					break;
405 				}
406 
407 				case SDRDRAG_CROOK :
408 				{
409 					if (eDragHdl==HDL_MOVE && IsMarkedHitMovesAlways())
410 					{
411 						if (!IsMoveAllowed()) return sal_False;
412 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
413 					}
414 					else
415 					{
416 						if (!IsCrookAllowed(sal_True) && !IsCrookAllowed(sal_False)) return sal_False;
417 						mpCurrentSdrDragMethod = new SdrDragCrook(*this);
418 					}
419 				} break;
420 
421 				default:
422 				{
423 					// SDRDRAG_MOVE
424 					if((eDragHdl == HDL_MOVE) && !IsMoveAllowed())
425 					{
426 						return sal_False;
427 					}
428 					else if(eDragHdl == HDL_GLUE)
429 					{
430 						mpCurrentSdrDragMethod = new SdrDragMove(*this);
431 					}
432 					else
433 					{
434 						if(bFramDrag)
435 						{
436 							if(eDragHdl == HDL_MOVE)
437 							{
438 								mpCurrentSdrDragMethod = new SdrDragMove(*this);
439 							}
440 							else
441 							{
442 								if(!IsResizeAllowed(sal_True))
443 								{
444 									return sal_False;
445 								}
446 
447 								sal_Bool bSingleTextObjMark = sal_False;	// SJ: #i100490#
448 								if ( GetMarkedObjectCount() == 1 )
449 								{
450 									pMarkedObj=GetMarkedObjectByIndex(0);
451 									if ( pMarkedObj &&
452 										pMarkedObj->ISA( SdrTextObj ) &&
453 										static_cast<SdrTextObj*>(pMarkedObj)->IsTextFrame() )
454 										bSingleTextObjMark = sal_True;
455 								}
456 								if ( bSingleTextObjMark )
457 									mpCurrentSdrDragMethod = new SdrDragObjOwn(*this);
458 								else
459 									mpCurrentSdrDragMethod = new SdrDragResize(*this);
460 							}
461 						}
462 						else
463 						{
464 							if(HDL_MOVE == eDragHdl)
465 							{
466                                 const bool bCustomShapeSelected(1 == GetMarkedObjectCount() && GetMarkedObjectByIndex(0)->ISA(SdrObjCustomShape));
467 
468                                 if(bCustomShapeSelected)
469                                 {
470     								mpCurrentSdrDragMethod = new SdrDragMove( *this );
471                                 }
472 							}
473 							else if(HDL_POLY == eDragHdl)
474                             {
475                                 const bool bConnectorSelected(1 == GetMarkedObjectCount() && GetMarkedObjectByIndex(0)->ISA(SdrEdgeObj));
476 
477                                 if(bConnectorSelected)
478                                 {
479                                     // #i97784#
480                                     // fallback to old behaviour for connectors (see
481                                     // text in task description for more details)
482                                 }
483                                 else if(!IsMoveAllowed() || !IsResizeAllowed())
484     							{
485 	    							// #i77187#
486                                     // do not allow move of polygon points if object is move or size protected
487 		    						return sal_False;
488                                 }
489                             }
490 
491                             if(!mpCurrentSdrDragMethod)
492                             {
493                                 // fallback to DragSpecial if no interaction defined
494                                 bDragSpecial = sal_True;
495 								mpCurrentSdrDragMethod = new SdrDragObjOwn(*this);
496 							}
497 						}
498 					}
499 				}
500 			}
501 		}
502 		if (pForcedMeth!=NULL)
503 		{
504             delete mpCurrentSdrDragMethod;
505 			mpCurrentSdrDragMethod = pForcedMeth;
506 		}
507 		aDragStat.SetDragMethod(mpCurrentSdrDragMethod);
508 		if (mpCurrentSdrDragMethod)
509 		{
510 			bRet = mpCurrentSdrDragMethod->BeginSdrDrag();
511 			if (!bRet)
512 			{
513 				if (pHdl==NULL && IS_TYPE(SdrDragObjOwn,mpCurrentSdrDragMethod))
514 				{
515 					// Aha, Obj kann nicht Move SpecialDrag, also MoveFrameDrag versuchen
516                     delete mpCurrentSdrDragMethod;
517                     mpCurrentSdrDragMethod = 0;
518 					bDragSpecial=sal_False;
519 
520                     if (!IsMoveAllowed())
521                         return sal_False;
522 
523                     bFramDrag=sal_True;
524 					mpCurrentSdrDragMethod = new SdrDragMove(*this);
525 					aDragStat.SetDragMethod(mpCurrentSdrDragMethod);
526 					bRet = mpCurrentSdrDragMethod->BeginSdrDrag();
527 				}
528 			}
529 			if (!bRet)
530 			{
531                 delete mpCurrentSdrDragMethod;
532                 mpCurrentSdrDragMethod = 0;
533 				aDragStat.SetDragMethod(mpCurrentSdrDragMethod);
534 			}
535 		}
536 	}
537 
538 	return bRet;
539 }
540 
MovDragObj(const Point & rPnt)541 void SdrDragView::MovDragObj(const Point& rPnt)
542 {
543 	if (mpCurrentSdrDragMethod)
544 	{
545 		Point aPnt(rPnt);
546 		ImpLimitToWorkArea(aPnt);
547 		mpCurrentSdrDragMethod->MoveSdrDrag(aPnt); // this call already makes a Hide()/Show combination
548 	}
549 }
550 
EndDragObj(sal_Bool bCopy)551 sal_Bool SdrDragView::EndDragObj(sal_Bool bCopy)
552 {
553 	bool bRet(false);
554 
555 	// #i73341# If insert GluePoint, do not insist on last points being different
556 	if(mpCurrentSdrDragMethod && aDragStat.IsMinMoved() && (IsInsertGluePoint() || aDragStat.GetNow() != aDragStat.GetPrev()))
557 	{
558 		sal_uIntPtr nHdlAnzMerk=0;
559 
560 		if (bEliminatePolyPoints)
561 		{ // IBM Special
562 			nHdlAnzMerk=GetMarkablePointCount();
563 		}
564 
565 		const bool bUndo = IsUndoEnabled();
566         if (IsInsertGluePoint() && bUndo)
567 		{
568 			BegUndo(aInsPointUndoStr);
569 			AddUndo(pInsPointUndo);
570 		}
571 
572         bRet = mpCurrentSdrDragMethod->EndSdrDrag(bCopy);
573 
574         if( IsInsertGluePoint() && bUndo)
575             EndUndo();
576 
577         delete mpCurrentSdrDragMethod;
578         mpCurrentSdrDragMethod = 0;
579 
580         if (bEliminatePolyPoints)
581 		{ // IBM Special
582 			if (nHdlAnzMerk!=GetMarkablePointCount())
583 			{
584 				UnmarkAllPoints();
585 			}
586 		}
587 
588         if (bInsPolyPoint)
589 		{
590 			SetMarkHandles();
591 			bInsPolyPoint=sal_False;
592 			if( bUndo )
593 			{
594 				BegUndo(aInsPointUndoStr);
595 				AddUndo(pInsPointUndo);
596 				EndUndo();
597 			}
598 		}
599 
600 		eDragHdl=HDL_MOVE;
601 		pDragHdl=NULL;
602 
603 		if (!bSomeObjChgdFlag)
604 		{
605 			// Aha, Obj hat nicht gebroadcastet (z.B. Writer FlyFrames)
606 			if(!bDragHdl)
607 			{
608 				AdjustMarkHdl();
609 			}
610 		}
611 	}
612 	else
613 	{
614 		BrkDragObj();
615 	}
616 
617     bInsPolyPoint=sal_False;
618 	SetInsertGluePoint(sal_False);
619 
620 	return bRet;
621 }
622 
BrkDragObj()623 void SdrDragView::BrkDragObj()
624 {
625 	if (mpCurrentSdrDragMethod)
626 	{
627 		mpCurrentSdrDragMethod->CancelSdrDrag();
628 
629         delete mpCurrentSdrDragMethod;
630         mpCurrentSdrDragMethod = 0;
631 
632         if (bInsPolyPoint)
633 		{
634 			pInsPointUndo->Undo(); // Den eingefuegten Punkt wieder raus
635 			delete pInsPointUndo;
636 			pInsPointUndo=NULL;
637 			SetMarkHandles();
638 			bInsPolyPoint=sal_False;
639 		}
640 
641         if (IsInsertGluePoint())
642 		{
643 			pInsPointUndo->Undo(); // Den eingefuegten Klebepunkt wieder raus
644 			delete pInsPointUndo;
645 			pInsPointUndo=NULL;
646 			SetInsertGluePoint(sal_False);
647 		}
648 
649         eDragHdl=HDL_MOVE;
650 		pDragHdl=NULL;
651 	}
652 }
653 
IsInsObjPointPossible() const654 sal_Bool SdrDragView::IsInsObjPointPossible() const
655 {
656 	return pMarkedObj!=NULL && pMarkedObj->IsPolyObj();
657 }
658 
ImpBegInsObjPoint(sal_Bool bIdxZwang,sal_uInt32 nIdx,const Point & rPnt,sal_Bool bNewObj,OutputDevice * pOut)659 sal_Bool SdrDragView::ImpBegInsObjPoint(sal_Bool bIdxZwang, sal_uInt32 nIdx, const Point& rPnt, sal_Bool bNewObj, OutputDevice* pOut)
660 {
661 	sal_Bool bRet(sal_False);
662 
663 	if(pMarkedObj && pMarkedObj->ISA(SdrPathObj))
664 	{
665 		SdrPathObj* pMarkedPath = (SdrPathObj*)pMarkedObj;
666 		BrkAction();
667 		pInsPointUndo = dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pMarkedObj) );
668 		DBG_ASSERT( pInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" );
669 
670 		XubString aStr(ImpGetResStr(STR_DragInsertPoint));
671 		XubString aName;
672         pMarkedObj->TakeObjNameSingul(aName);
673 		xub_StrLen nPos(aStr.SearchAscii("%1"));
674 
675 		if(STRING_NOTFOUND != nPos)
676 		{
677 			aStr.Erase(nPos, 2);
678 			aStr.Insert(aName, nPos);
679 		}
680 
681 		aInsPointUndoStr = aStr;
682 		Point aPt(rPnt);
683 
684 		if(bNewObj)
685 			aPt = GetSnapPos(aPt,pMarkedPV);
686 
687 		sal_Bool bClosed0(pMarkedPath->IsClosedObj());
688 
689 		if(bIdxZwang)
690 		{
691 			mnInsPointNum = pMarkedPath->NbcInsPoint(nIdx, aPt, bNewObj, sal_True);
692 		}
693 		else
694 		{
695 			mnInsPointNum = pMarkedPath->NbcInsPointOld(aPt, bNewObj, sal_True);
696 		}
697 
698 		if(bClosed0 != pMarkedPath->IsClosedObj())
699 		{
700 			// Obj was closed implicit
701 			// object changed
702 			pMarkedPath->SetChanged();
703 			pMarkedPath->BroadcastObjectChange();
704 		}
705 
706 		if(0xffffffff != mnInsPointNum)
707 		{
708 			bInsPolyPoint = sal_True;
709 			UnmarkAllPoints();
710 			AdjustMarkHdl();
711 
712 			bRet = BegDragObj(rPnt, pOut, aHdl.GetHdl(mnInsPointNum), 0);
713 
714 			if (bRet)
715 			{
716 				aDragStat.SetMinMoved();
717 				MovDragObj(rPnt);
718 			}
719 		}
720 		else
721 		{
722 			delete pInsPointUndo;
723 			pInsPointUndo = NULL;
724 		}
725 	}
726 
727 	return bRet;
728 }
729 
EndInsObjPoint(SdrCreateCmd eCmd)730 sal_Bool SdrDragView::EndInsObjPoint(SdrCreateCmd eCmd)
731 {
732 	if(IsInsObjPoint())
733 	{
734 		sal_uInt32 nNextPnt(mnInsPointNum);
735 		Point aPnt(aDragStat.GetNow());
736 		sal_Bool bOk=EndDragObj(sal_False);
737 		if (bOk==sal_True && eCmd!=SDRCREATE_FORCEEND)
738 		{
739 			// Ret=True bedeutet: Action ist vorbei.
740 			bOk=!(ImpBegInsObjPoint(sal_True, nNextPnt, aPnt, eCmd == SDRCREATE_NEXTOBJECT, pDragWin));
741 		}
742 
743 		return bOk;
744 	} else return sal_False;
745 }
746 
IsInsGluePointPossible() const747 sal_Bool SdrDragView::IsInsGluePointPossible() const
748 {
749 	sal_Bool bRet=sal_False;
750 	if (IsInsGluePointMode() && AreObjectsMarked())
751 	{
752 		if (GetMarkedObjectCount()==1)
753 		{
754 			// sal_False liefern, wenn 1 Objekt und dieses ein Verbinder ist.
755 			const SdrObject* pObj=GetMarkedObjectByIndex(0);
756 			if (!HAS_BASE(SdrEdgeObj,pObj))
757 			{
758 			   bRet=sal_True;
759 			}
760 		}
761 		else
762 		{
763 			bRet=sal_True;
764 		}
765 	}
766 	return bRet;
767 }
768 
BegInsGluePoint(const Point & rPnt)769 sal_Bool SdrDragView::BegInsGluePoint(const Point& rPnt)
770 {
771 	sal_Bool bRet=sal_False;
772 	SdrObject* pObj;
773 	SdrPageView* pPV;
774 	sal_uIntPtr nMarkNum;
775 	if (PickMarkedObj(rPnt,pObj,pPV,&nMarkNum,SDRSEARCH_PASS2BOUND))
776 	{
777 		BrkAction();
778 		UnmarkAllGluePoints();
779 		pInsPointUndo= dynamic_cast< SdrUndoGeoObj* >( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj) );
780 		DBG_ASSERT( pInsPointUndo, "svx::SdrDragView::BegInsObjPoint(), could not create correct undo object!" );
781 		XubString aStr(ImpGetResStr(STR_DragInsertGluePoint));
782 		XubString aName; pObj->TakeObjNameSingul(aName);
783 
784 		aStr.SearchAndReplaceAscii("%1", aName);
785 
786 		aInsPointUndoStr=aStr;
787 		SdrGluePointList* pGPL=pObj->ForceGluePointList();
788 		if (pGPL!=NULL)
789 		{
790 			sal_uInt16 nGlueIdx=pGPL->Insert(SdrGluePoint());
791 			SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
792 			sal_uInt16 nGlueId=rGP.GetId();
793 			rGP.SetAbsolutePos(rPnt,*pObj);
794 
795 			SdrHdl* pHdl=NULL;
796 			if (MarkGluePoint(pObj,nGlueId,pPV))
797 			{
798 				pHdl=GetGluePointHdl(pObj,nGlueId);
799 			}
800 			if (pHdl!=NULL && pHdl->GetKind()==HDL_GLUE && pHdl->GetObj()==pObj && pHdl->GetObjHdlNum()==nGlueId)
801 			{
802 				SetInsertGluePoint(sal_True);
803 				bRet=BegDragObj(rPnt,NULL,pHdl,0);
804 				if (bRet)
805 				{
806 					aDragStat.SetMinMoved();
807 					MovDragObj(rPnt);
808 				}
809 				else
810 				{
811 					SetInsertGluePoint(sal_False);
812 					delete pInsPointUndo;
813 					pInsPointUndo=NULL;
814 				}
815 			}
816 			else
817 			{
818 				DBG_ERROR("BegInsGluePoint(): GluePoint-Handle nicht gefunden");
819 			}
820 		}
821 		else
822 		{
823 			// Keine Klebepunkte moeglich bei diesem Objekt (z.B. Edge)
824 			SetInsertGluePoint(sal_False);
825 			delete pInsPointUndo;
826 			pInsPointUndo=NULL;
827 		}
828 	}
829 
830 	return bRet;
831 }
832 
ShowDragObj()833 void SdrDragView::ShowDragObj()
834 {
835 	if(mpCurrentSdrDragMethod && !aDragStat.IsShown())
836 	{
837         for(sal_uInt32 a(0); a < PaintWindowCount(); a++)
838         {
839 	        SdrPaintWindow* pCandidate = GetPaintWindow(a);
840 	        sdr::overlay::OverlayManager* pOverlayManager = pCandidate->GetOverlayManager();
841 
842 	        if(pOverlayManager)
843 	        {
844 		        mpCurrentSdrDragMethod->CreateOverlayGeometry(*pOverlayManager);
845 
846 				// #i101679# Force changed overlay to be shown
847 				pOverlayManager->flush();
848 	        }
849         }
850 
851 		aDragStat.SetShown(sal_True);
852 	}
853 }
854 
HideDragObj()855 void SdrDragView::HideDragObj()
856 {
857 	if(mpCurrentSdrDragMethod && aDragStat.IsShown())
858 	{
859         mpCurrentSdrDragMethod->destroyOverlayGeometry();
860 		aDragStat.SetShown(sal_False);
861 	}
862 }
863 
864 ////////////////////////////////////////////////////////////////////////////////////////////////////
865 
SetNoDragXorPolys(sal_Bool bOn)866 void SdrDragView::SetNoDragXorPolys(sal_Bool bOn)
867 {
868 	if (IsNoDragXorPolys()!=bOn)
869 	{
870 		const bool bDragging(mpCurrentSdrDragMethod);
871 		const bool bShown(bDragging && aDragStat.IsShown());
872 
873         if(bShown)
874         {
875             HideDragObj();
876         }
877 
878 		bNoDragXorPolys = bOn;
879 
880 		if(bDragging)
881 		{
882             // force recreation of drag content
883             mpCurrentSdrDragMethod->resetSdrDragEntries();
884 		}
885 
886 		if(bShown)
887         {
888 			ShowDragObj();
889         }
890 	}
891 }
892 
SetDragStripes(sal_Bool bOn)893 void SdrDragView::SetDragStripes(sal_Bool bOn)
894 {
895 	if (mpCurrentSdrDragMethod && aDragStat.IsShown())
896 	{
897 		HideDragObj();
898 		bDragStripes=bOn;
899 		ShowDragObj();
900 	}
901 	else
902 	{
903 		bDragStripes=bOn;
904 	}
905 }
906 
IsOrthoDesired() const907 sal_Bool SdrDragView::IsOrthoDesired() const
908 {
909 	if(mpCurrentSdrDragMethod && (IS_TYPE(SdrDragObjOwn, mpCurrentSdrDragMethod) || IS_TYPE(SdrDragResize, mpCurrentSdrDragMethod)))
910 	{
911 		return bOrthoDesiredOnMarked;
912 	}
913 
914     return sal_False;
915 }
916 
917 ////////////////////////////////////////////////////////////////////////////////////////////////////
918 
SetRubberEdgeDragging(sal_Bool bOn)919 void SdrDragView::SetRubberEdgeDragging(sal_Bool bOn)
920 {
921 	if (bOn!=IsRubberEdgeDragging())
922 	{
923 		sal_uIntPtr nAnz = GetEdgesOfMarkedNodes().GetMarkCount();
924 		sal_Bool bShowHide=nAnz!=0 && IsDragObj() &&
925 				 (nRubberEdgeDraggingLimit>=nAnz);
926 		if (bShowHide)
927 			HideDragObj();
928 		bRubberEdgeDragging=bOn;
929 		if (bShowHide)
930 			ShowDragObj();
931 	}
932 }
933 
SetRubberEdgeDraggingLimit(sal_uInt16 nEdgeObjAnz)934 void SdrDragView::SetRubberEdgeDraggingLimit(sal_uInt16 nEdgeObjAnz)
935 {
936 	if (nEdgeObjAnz!=nRubberEdgeDraggingLimit)
937 	{
938 		sal_uIntPtr nAnz = GetEdgesOfMarkedNodes().GetMarkCount();
939 		sal_Bool bShowHide=IsRubberEdgeDragging() && nAnz!=0 && IsDragObj() &&
940 				 (nEdgeObjAnz>=nAnz)!=(nRubberEdgeDraggingLimit>=nAnz);
941 		if (bShowHide)
942 			HideDragObj();
943 		nRubberEdgeDraggingLimit=nEdgeObjAnz;
944 		if (bShowHide)
945 			ShowDragObj();
946 	}
947 }
948 
SetDetailedEdgeDragging(sal_Bool bOn)949 void SdrDragView::SetDetailedEdgeDragging(sal_Bool bOn)
950 {
951 	if (bOn!=IsDetailedEdgeDragging())
952 	{
953 		sal_uIntPtr nAnz = GetEdgesOfMarkedNodes().GetMarkCount();
954 		sal_Bool bShowHide=nAnz!=0 && IsDragObj() &&
955 				 (nDetailedEdgeDraggingLimit>=nAnz);
956 		if (bShowHide)
957 			HideDragObj();
958 		bDetailedEdgeDragging=bOn;
959 		if (bShowHide)
960 			ShowDragObj();
961 	}
962 }
963 
SetDetailedEdgeDraggingLimit(sal_uInt16 nEdgeObjAnz)964 void SdrDragView::SetDetailedEdgeDraggingLimit(sal_uInt16 nEdgeObjAnz)
965 {
966 	if (nEdgeObjAnz!=nDetailedEdgeDraggingLimit)
967 	{
968 		sal_uIntPtr nAnz = GetEdgesOfMarkedNodes().GetMarkCount();
969 		sal_Bool bShowHide=IsDetailedEdgeDragging() && nAnz!=0 && IsDragObj() &&
970 				 (nEdgeObjAnz>=nAnz)!=(nDetailedEdgeDraggingLimit>=nAnz);
971 		if (bShowHide)
972 			HideDragObj();
973 		nDetailedEdgeDraggingLimit=nEdgeObjAnz;
974 		if (bShowHide)
975 			ShowDragObj();
976 	}
977 }
978 
SetMarkHandles()979 void SdrDragView::SetMarkHandles()
980 {
981 	if( pDragHdl )
982 		pDragHdl = 0;
983 
984 	SdrExchangeView::SetMarkHandles();
985 }
986 
SetSolidDragging(bool bOn)987 void SdrDragView::SetSolidDragging(bool bOn)
988 {
989 	if((bool)mbSolidDragging != bOn)
990 	{
991 		mbSolidDragging = bOn;
992 	}
993 }
994 
IsSolidDragging() const995 bool SdrDragView::IsSolidDragging() const
996 {
997 	// allow each user to disable by having a local setting, but using AND for
998 	// checking allowance
999 	return mbSolidDragging && getOptionsDrawinglayer().IsSolidDragCreate();
1000 }
1001 
1002 // eof
1003