xref: /aoo42x/main/svx/source/svdraw/svdsnpv.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/svdsnpv.hxx>
28 #include <math.h>
29 
30 #include <svx/svdetc.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <svx/svdpage.hxx>
34 #include "svx/svditer.hxx"
35 #include <svx/sdr/overlay/overlayobjectlist.hxx>
36 #include <svx/sdr/overlay/overlaycrosshair.hxx>
37 #include <svx/sdr/overlay/overlayhelpline.hxx>
38 #include <svx/sdr/overlay/overlaymanager.hxx>
39 #include <basegfx/matrix/b2dhommatrix.hxx>
40 #include <svx/sdrpaintwindow.hxx>
41 
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 // #114409#-1 Migrate PageOrigin
44 class ImplPageOriginOverlay
45 {
46 	// The OverlayObjects
47 	::sdr::overlay::OverlayObjectList				maObjects;
48 
49 	// The current position in logical coodinates
50 	basegfx::B2DPoint								maPosition;
51 
52 public:
53 	ImplPageOriginOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos);
54 	~ImplPageOriginOverlay();
55 
56 	void SetPosition(const basegfx::B2DPoint& rNewPosition);
57 };
58 
ImplPageOriginOverlay(const SdrPaintView & rView,const basegfx::B2DPoint & rStartPos)59 ImplPageOriginOverlay::ImplPageOriginOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos)
60 :	maPosition(rStartPos)
61 {
62 	for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
63 	{
64 		SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
65 		::sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager();
66 
67 		if(pTargetOverlay)
68 		{
69 			::sdr::overlay::OverlayCrosshairStriped* aNew = new ::sdr::overlay::OverlayCrosshairStriped(
70 				maPosition);
71 			pTargetOverlay->add(*aNew);
72 			maObjects.append(*aNew);
73 		}
74 	}
75 }
76 
~ImplPageOriginOverlay()77 ImplPageOriginOverlay::~ImplPageOriginOverlay()
78 {
79 	// The OverlayObjects are cleared using the destructor of OverlayObjectList.
80 	// That destructor calls clear() at the list which removes all objects from the
81 	// OverlayManager and deletes them.
82 }
83 
SetPosition(const basegfx::B2DPoint & rNewPosition)84 void ImplPageOriginOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition)
85 {
86 	if(rNewPosition != maPosition)
87 	{
88 		// apply to OverlayObjects
89 		for(sal_uInt32 a(0); a < maObjects.count(); a++)
90 		{
91 			sdr::overlay::OverlayCrosshairStriped* pCandidate =
92 				static_cast< sdr::overlay::OverlayCrosshairStriped* >(&maObjects.getOverlayObject(a));
93 
94 			if(pCandidate)
95 			{
96 				pCandidate->setBasePosition(rNewPosition);
97 			}
98 		}
99 
100 		// remember new position
101 		maPosition = rNewPosition;
102 	}
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////////////////////////
106 // #114409#-2 Migrate HelpLine
107 class ImplHelpLineOverlay
108 {
109 	// The OverlayObjects
110 	::sdr::overlay::OverlayObjectList				maObjects;
111 
112 	// The current position in logical coodinates
113 	basegfx::B2DPoint								maPosition;
114 
115 	// HelpLine specific stuff
116 	SdrPageView*									mpPageView;
117 	sal_uInt16										mnHelpLineNumber;
118 	SdrHelpLineKind									meHelpLineKind;
119 
120 public:
121 	ImplHelpLineOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos,
122 		SdrPageView* pPageView, sal_uInt16 nHelpLineNumber, SdrHelpLineKind eKind);
123 	~ImplHelpLineOverlay();
124 
125 	void SetPosition(const basegfx::B2DPoint& rNewPosition);
126 
127 	// access to HelpLine specific stuff
GetPageView() const128 	SdrPageView* GetPageView() const { return mpPageView; }
GetHelpLineNumber() const129 	sal_uInt16 GetHelpLineNumber() const { return mnHelpLineNumber; }
GetHelpLineKind() const130 	SdrHelpLineKind GetHelpLineKind() const { return meHelpLineKind; }
131 };
132 
ImplHelpLineOverlay(const SdrPaintView & rView,const basegfx::B2DPoint & rStartPos,SdrPageView * pPageView,sal_uInt16 nHelpLineNumber,SdrHelpLineKind eKind)133 ImplHelpLineOverlay::ImplHelpLineOverlay(
134 	const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos,
135 	SdrPageView* pPageView, sal_uInt16 nHelpLineNumber, SdrHelpLineKind eKind)
136 :	maPosition(rStartPos),
137 	mpPageView(pPageView),
138 	mnHelpLineNumber(nHelpLineNumber),
139 	meHelpLineKind(eKind)
140 {
141 	for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
142 	{
143 		SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
144 		::sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager();
145 
146 		if(pTargetOverlay)
147 		{
148 			::sdr::overlay::OverlayHelplineStriped* aNew = new ::sdr::overlay::OverlayHelplineStriped(
149 				maPosition, meHelpLineKind);
150 			pTargetOverlay->add(*aNew);
151 			maObjects.append(*aNew);
152 		}
153 	}
154 }
155 
~ImplHelpLineOverlay()156 ImplHelpLineOverlay::~ImplHelpLineOverlay()
157 {
158 	// The OverlayObjects are cleared using the destructor of OverlayObjectList.
159 	// That destructor calls clear() at the list which removes all objects from the
160 	// OverlayManager and deletes them.
161 }
162 
SetPosition(const basegfx::B2DPoint & rNewPosition)163 void ImplHelpLineOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition)
164 {
165 	if(rNewPosition != maPosition)
166 	{
167 		// apply to OverlayObjects
168 		// apply to OverlayObjects
169 		for(sal_uInt32 a(0); a < maObjects.count(); a++)
170 		{
171 			sdr::overlay::OverlayHelplineStriped* pCandidate =
172 				static_cast< sdr::overlay::OverlayHelplineStriped* >(&maObjects.getOverlayObject(a));
173 
174 			if(pCandidate)
175 			{
176 				pCandidate->setBasePosition(rNewPosition);
177 			}
178 		}
179 
180 		// remember new position
181 		maPosition = rNewPosition;
182 	}
183 }
184 
185 ////////////////////////////////////////////////////////////////////////////////////////////////////
186 ////////////////////////////////////////////////////////////////////////////////////////////////////
187 //
188 //  @@@@  @@  @@  @@@@  @@@@@   @@ @@ @@ @@@@@ @@   @@
189 // @@  @@ @@@ @@ @@  @@ @@  @@  @@ @@ @@ @@    @@   @@
190 // @@     @@@@@@ @@  @@ @@  @@  @@ @@ @@ @@    @@ @ @@
191 //  @@@@  @@@@@@ @@@@@@ @@@@@   @@@@@ @@ @@@@  @@@@@@@
192 //     @@ @@ @@@ @@  @@ @@       @@@  @@ @@    @@@@@@@
193 // @@  @@ @@  @@ @@  @@ @@       @@@  @@ @@    @@@ @@@
194 //  @@@@  @@  @@ @@  @@ @@        @   @@ @@@@@ @@   @@
195 //
196 ////////////////////////////////////////////////////////////////////////////////////////////////////
197 ////////////////////////////////////////////////////////////////////////////////////////////////////
198 
ClearVars()199 void SdrSnapView::ClearVars()
200 {
201 	nMagnSizPix=4;
202 	bSnapEnab=sal_True;
203 	bGridSnap=sal_True;
204 	bSnapTo1Pix=sal_True;
205 	bBordSnap=sal_True;
206 	bHlplSnap=sal_True;
207 	bOFrmSnap=sal_True;
208 	bOPntSnap=sal_False;
209 	bOConSnap=sal_True;
210 	bMoveMFrmSnap=sal_True;
211 	bMoveOFrmSnap=sal_True;
212 	bMoveOPntSnap=sal_True;
213 	bMoveOConSnap=sal_True;
214 	bMoveSnapOnlyTopLeft=sal_False;
215 	bOrtho=sal_False;
216 	bBigOrtho=sal_True;
217 	nSnapAngle=1500;
218 	bAngleSnapEnab=sal_False;
219 	bMoveOnlyDragging=sal_False;
220 	bSlantButShear=sal_False;
221 	bCrookNoContortion=sal_False;
222 	eCrookMode=SDRCROOK_ROTATE;
223 	bHlplFixed=sal_False;
224 	bEliminatePolyPoints=sal_False;
225 	nEliminatePolyPointLimitAngle=0;
226 
227 	// #114409#-1 Migrate PageOrigin
228 	BrkSetPageOrg();
229 
230 	// #114409#-2 Migrate HelpLine
231 	BrkDragHelpLine();
232 }
233 
SdrSnapView(SdrModel * pModel1,OutputDevice * pOut)234 SdrSnapView::SdrSnapView(SdrModel* pModel1, OutputDevice* pOut):
235 	SdrPaintView(pModel1,pOut),
236 	// #114409#-1 Migrate PageOrigin
237 	mpPageOriginOverlay(0L),
238 	// #114409#-2 Migrate HelpLine
239 	mpHelpLineOverlay(0L)
240 {
241 	ClearVars();
242 }
243 
244 // #114409#-1 Migrate PageOrigin
~SdrSnapView()245 SdrSnapView::~SdrSnapView()
246 {
247 	// #114409#-1 Migrate PageOrigin
248 	BrkSetPageOrg();
249 
250 	// #114409#-2 Migrate HelpLine
251 	BrkDragHelpLine();
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////////////////////////
255 
IsAction() const256 sal_Bool SdrSnapView::IsAction() const
257 {
258 	return IsSetPageOrg() || IsDragHelpLine() || SdrPaintView::IsAction();
259 }
260 
MovAction(const Point & rPnt)261 void SdrSnapView::MovAction(const Point& rPnt)
262 {
263 	SdrPaintView::MovAction(rPnt);
264 	if (IsSetPageOrg()) {
265 		MovSetPageOrg(rPnt);
266 	}
267 	if (IsDragHelpLine()) {
268 		MovDragHelpLine(rPnt);
269 	}
270 }
271 
EndAction()272 void SdrSnapView::EndAction()
273 {
274 	if (IsSetPageOrg()) {
275 		EndSetPageOrg();
276 	}
277 	if (IsDragHelpLine()) {
278 		EndDragHelpLine();
279 	}
280 	SdrPaintView::EndAction();
281 }
282 
BckAction()283 void SdrSnapView::BckAction()
284 {
285 	BrkSetPageOrg();
286 	BrkDragHelpLine();
287 	SdrPaintView::BckAction();
288 }
289 
BrkAction()290 void SdrSnapView::BrkAction()
291 {
292 	BrkSetPageOrg();
293 	BrkDragHelpLine();
294 	SdrPaintView::BrkAction();
295 }
296 
TakeActionRect(Rectangle & rRect) const297 void SdrSnapView::TakeActionRect(Rectangle& rRect) const
298 {
299 	if (IsSetPageOrg() || IsDragHelpLine()) {
300 		rRect=Rectangle(aDragStat.GetNow(),aDragStat.GetNow());
301 	} else {
302 		SdrPaintView::TakeActionRect(rRect);
303 	}
304 }
305 
306 ////////////////////////////////////////////////////////////////////////////////////////////////////
307 
GetSnapPos(const Point & rPnt,const SdrPageView * pPV) const308 Point SdrSnapView::GetSnapPos(const Point& rPnt, const SdrPageView* pPV) const
309 {
310 	Point aPt(rPnt);
311 	SnapPos(aPt,pPV);
312 	return aPt;
313 }
314 
315 #define NOT_SNAPPED 0x7FFFFFFF
SnapPos(Point & rPnt,const SdrPageView * pPV) const316 sal_uInt16 SdrSnapView::SnapPos(Point& rPnt, const SdrPageView* pPV) const
317 {
318 	if (!bSnapEnab) return SDRSNAP_NOTSNAPPED;
319 	sal_Bool bPVOfs=sal_False;
320 	long x=rPnt.X();
321 	long y=rPnt.Y();
322 	if (pPV==NULL) {
323 		bPVOfs=sal_True;
324 		pPV=GetSdrPageView();
325 		if (pPV==NULL) return SDRSNAP_NOTSNAPPED;
326 	}
327 
328 	long dx=NOT_SNAPPED;
329 	long dy=NOT_SNAPPED;
330 	long dx1,dy1;
331 	long mx=aMagnSiz.Width();
332 	long my=aMagnSiz.Height();
333 	if (bHlplVisible && bHlplSnap && !IsDragHelpLine())
334 	{
335 		const SdrHelpLineList& rHLL=pPV->GetHelpLines();
336 		sal_uInt16 nAnz=rHLL.GetCount();
337 		for (sal_uInt16 i=nAnz; i>0;) {
338 			i--;
339 			const SdrHelpLine& rHL=rHLL[i];
340 			const Point& rPos=rHL.GetPos();
341 			switch (rHL.GetKind()) {
342 				case SDRHELPLINE_VERTICAL: {
343 					long a=x-rPos.X();
344 					if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; }
345 				} break;
346 				case SDRHELPLINE_HORIZONTAL: {
347 					long b=y-rPos.Y();
348 					if (Abs(b)<=my) { dy1=-b; if (Abs(dy1)<Abs(dy)) dy=dy1; }
349 				} break;
350 				case SDRHELPLINE_POINT: {
351 					long a=x-rPos.X();
352 					long b=y-rPos.Y();
353 					if (Abs(a)<=mx && Abs(b)<=my) {
354 						dx1=-a; dy1=-b;
355 						if (Abs(dx1)<Abs(dx) && Abs(dy1)<Abs(dy)) { dx=dx1; dy=dy1; }
356 					}
357 				} break;
358 			} // switch
359 		}
360 	}
361 	if (bBordVisible && bBordSnap) {
362 		SdrPage* pPage=pPV->GetPage();
363 		long xs=pPage->GetWdt();
364 		long ys=pPage->GetHgt();
365 		long lft=pPage->GetLftBorder();
366 		long rgt=pPage->GetRgtBorder();
367 		long upp=pPage->GetUppBorder();
368 		long lwr=pPage->GetLwrBorder();
369 		long a;
370 		a=x- lft    ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // linker Rand
371 		a=x-(xs-rgt); if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // rechter Rand
372 		a=x         ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // linke Papierkante
373 		a=x- xs     ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // rechte Papierkante
374 		a=y- upp    ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // linker Rand
375 		a=y-(ys-lwr); if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // rechter Rand
376 		a=y         ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // linke Papierkante
377 		a=y- ys     ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // rechte Papierkante
378 	}
379 	if (bOFrmSnap || bOPntSnap /*|| (bConnVisible && bOConSnap)*/) {
380 		sal_uIntPtr nMaxPointSnapCount=200;
381 		sal_uIntPtr nMaxFrameSnapCount=200;
382 
383 		// #97981# go back to IM_DEEPNOGROUPS runthrough for snap to object comparisons
384 		SdrObjListIter aIter(*pPV->GetPage(),/*IM_FLAT*/IM_DEEPNOGROUPS,sal_True);
385 
386 		while (aIter.IsMore() && (nMaxPointSnapCount>0 || nMaxFrameSnapCount>0)) {
387 			SdrObject* pO=aIter.Next();
388 			Rectangle aRect(pO->GetCurrentBoundRect());
389 			aRect.Left  ()-=mx;
390 			aRect.Right ()+=mx;
391 			aRect.Top   ()-=my;
392 			aRect.Bottom()+=my;
393 			if (aRect.IsInside(rPnt)) {
394 				if (bOPntSnap && nMaxPointSnapCount>0)
395 				{
396 					sal_uInt32 nAnz(pO->GetSnapPointCount());
397 					for (sal_uInt32 i(0L); i < nAnz && nMaxPointSnapCount > 0L; i++)
398 					{
399 						Point aP(pO->GetSnapPoint(i));
400 						dx1=x-aP.X();
401 						dy1=y-aP.Y();
402 						if (Abs(dx1)<=mx && Abs(dy1)<=my && Abs(dx1)<Abs(dx) && Abs(dy1)<Abs(dy)) {
403 							dx=-dx1;
404 							dy=-dy1;
405 						}
406 						nMaxPointSnapCount--;
407 					}
408 				}
409 				if (bOFrmSnap && nMaxFrameSnapCount>0) {
410 					Rectangle aLog(pO->GetSnapRect());
411 					Rectangle aR1(aLog);
412 					aR1.Left  ()-=mx;
413 					aR1.Right ()+=mx;
414 					aR1.Top   ()-=my;
415 					aR1.Bottom()+=my;
416 					if (aR1.IsInside(rPnt)) {
417 						if (Abs(x-aLog.Left  ())<=mx) { dx1=-(x-aLog.Left  ()); if (Abs(dx1)<Abs(dx)) dx=dx1; }
418 						if (Abs(x-aLog.Right ())<=mx) { dx1=-(x-aLog.Right ()); if (Abs(dx1)<Abs(dx)) dx=dx1; }
419 						if (Abs(y-aLog.Top   ())<=my) { dy1=-(y-aLog.Top   ()); if (Abs(dy1)<Abs(dy)) dy=dy1; }
420 						if (Abs(y-aLog.Bottom())<=my) { dy1=-(y-aLog.Bottom()); if (Abs(dy1)<Abs(dy)) dy=dy1; }
421 					}
422 					nMaxFrameSnapCount--;
423 				}
424 			}
425 		}
426 	}
427 	if(bGridSnap)
428 	{
429 		double fSnapWidth = aSnapWdtX;
430 		if(dx == NOT_SNAPPED && fSnapWidth != 0.0)
431 		{
432 			double fx = (double)x;
433 
434 			// round statt trunc
435 			if(fx - (double)pPV->GetPageOrigin().X() >= 0.0)
436 				fx += fSnapWidth / 2.0;
437 			else
438 				fx -= fSnapWidth / 2.0;
439 
440 			x = (long)((fx - (double)pPV->GetPageOrigin().X()) / fSnapWidth);
441 			x = (long)((double)x * fSnapWidth + (double)pPV->GetPageOrigin().X());
442 			dx = 0;
443 		}
444 		fSnapWidth = aSnapWdtY;
445 		if(dy == NOT_SNAPPED && fSnapWidth)
446 		{
447 			double fy = (double)y;
448 
449 			// round statt trunc
450 			if(fy - (double)pPV->GetPageOrigin().Y() >= 0.0)
451 				fy += fSnapWidth / 2.0;
452 			else
453 				fy -= fSnapWidth / 2.0;
454 
455 			y = (long)((fy - (double)pPV->GetPageOrigin().Y()) / fSnapWidth);
456 			y = (long)((double)y * fSnapWidth + (double)pPV->GetPageOrigin().Y());
457 			dy = 0;
458 		}
459 	}
460 	sal_Bool bRet=SDRSNAP_NOTSNAPPED;
461 	if (dx==NOT_SNAPPED) dx=0; else bRet|=SDRSNAP_XSNAPPED;
462 	if (dy==NOT_SNAPPED) dy=0; else bRet|=SDRSNAP_YSNAPPED;
463 	rPnt.X()=x+dx;
464 	rPnt.Y()=y+dy;
465 	return bRet;
466 }
467 
CheckSnap(const Point & rPt,const SdrPageView * pPV,long & nBestXSnap,long & nBestYSnap,bool & bXSnapped,bool & bYSnapped) const468 void SdrSnapView::CheckSnap(const Point& rPt, const SdrPageView* pPV, long& nBestXSnap, long& nBestYSnap, bool& bXSnapped, bool& bYSnapped) const
469 {
470 	Point aPt(rPt);
471 	sal_uInt16 nRet=SnapPos(aPt,pPV);
472 	aPt-=rPt;
473 	if ((nRet & SDRSNAP_XSNAPPED) !=0) {
474 		if (bXSnapped) {
475 			if (Abs(aPt.X())<Abs(nBestXSnap)) {
476 				nBestXSnap=aPt.X();
477 			}
478 		} else {
479 			nBestXSnap=aPt.X();
480 			bXSnapped=sal_True;
481 		}
482 	}
483 	if ((nRet & SDRSNAP_YSNAPPED) !=0) {
484 		if (bYSnapped) {
485 			if (Abs(aPt.Y())<Abs(nBestYSnap)) {
486 				nBestYSnap=aPt.Y();
487 			}
488 		} else {
489 			nBestYSnap=aPt.Y();
490 			bYSnapped=sal_True;
491 		}
492 	}
493 }
494 
SnapRect(const Rectangle & rRect,const SdrPageView * pPV,long & rDX,long & rDY) const495 sal_uInt16 SdrSnapView::SnapRect(const Rectangle& rRect, const SdrPageView* pPV, long& rDX, long& rDY) const
496 {
497 	long nBestXSnap=0;
498 	long nBestYSnap=0;
499 	bool bXSnapped=sal_False;
500 	bool bYSnapped=sal_False;
501 	CheckSnap(rRect.TopLeft()    ,pPV,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
502 	if (!bMoveSnapOnlyTopLeft) {
503 		CheckSnap(rRect.TopRight()   ,pPV,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
504 		CheckSnap(rRect.BottomLeft() ,pPV,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
505 		CheckSnap(rRect.BottomRight(),pPV,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
506 	}
507 	rDX=nBestXSnap;
508 	rDY=nBestYSnap;
509 	sal_uInt16 nRet=0;
510 	if (bXSnapped) nRet+=SDRSNAP_XSNAPPED;
511 	if (bYSnapped) nRet+=SDRSNAP_YSNAPPED;
512 	return nRet;
513 }
514 
515 ////////////////////////////////////////////////////////////////////////////////////////////////////
516 
BegSetPageOrg(const Point & rPnt)517 sal_Bool SdrSnapView::BegSetPageOrg(const Point& rPnt)
518 {
519 	BrkAction();
520 
521 	DBG_ASSERT(0L == mpPageOriginOverlay, "SdrSnapView::BegSetPageOrg: There exists a ImplPageOriginOverlay (!)");
522 	basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
523 	mpPageOriginOverlay = new ImplPageOriginOverlay(*this, aStartPos);
524 	aDragStat.Reset(GetSnapPos(rPnt,NULL));
525 
526 	return sal_True;
527 }
528 
MovSetPageOrg(const Point & rPnt)529 void SdrSnapView::MovSetPageOrg(const Point& rPnt)
530 {
531 	if(IsSetPageOrg())
532 	{
533 		aDragStat.NextMove(GetSnapPos(rPnt,NULL));
534 		DBG_ASSERT(mpPageOriginOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
535 		basegfx::B2DPoint aNewPos(aDragStat.GetNow().X(), aDragStat.GetNow().Y());
536 		mpPageOriginOverlay->SetPosition(aNewPos);
537 	}
538 }
539 
EndSetPageOrg()540 sal_Bool SdrSnapView::EndSetPageOrg()
541 {
542 	sal_Bool bRet(sal_False);
543 
544 	if(IsSetPageOrg())
545 	{
546 		SdrPageView* pPV = GetSdrPageView();
547 
548 		if(pPV)
549 		{
550 			Point aPnt(aDragStat.GetNow());
551 			pPV->SetPageOrigin(aPnt);
552 			bRet = sal_True;
553 		}
554 
555 		// cleanup
556 		BrkSetPageOrg();
557 	}
558 
559 	return bRet;
560 }
561 
BrkSetPageOrg()562 void SdrSnapView::BrkSetPageOrg()
563 {
564 	if(IsSetPageOrg())
565 	{
566 		DBG_ASSERT(mpPageOriginOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
567 		delete mpPageOriginOverlay;
568 		mpPageOriginOverlay = 0L;
569 	}
570 }
571 
572 ////////////////////////////////////////////////////////////////////////////////////////////////////
573 
PickHelpLine(const Point & rPnt,short nTol,const OutputDevice & rOut,sal_uInt16 & rnHelpLineNum,SdrPageView * & rpPV) const574 sal_Bool SdrSnapView::PickHelpLine(const Point& rPnt, short nTol, const OutputDevice& rOut, sal_uInt16& rnHelpLineNum, SdrPageView*& rpPV) const
575 {
576 	rpPV=NULL;
577 	nTol=ImpGetHitTolLogic(nTol,&rOut);
578 	SdrPageView* pPV = GetSdrPageView();
579 
580 	if(pPV)
581 	{
582 		Point aPnt(rPnt);
583 		sal_uInt16 nIndex=pPV->GetHelpLines().HitTest(aPnt,sal_uInt16(nTol),rOut);
584 		if (nIndex!=SDRHELPLINE_NOTFOUND) {
585 			rpPV=pPV;
586 			rnHelpLineNum=nIndex;
587 			return sal_True;
588 		}
589 	}
590 	return sal_False;
591 }
592 
593 // start HelpLine drag for new HelpLine
BegDragHelpLine(sal_uInt16 nHelpLineNum,SdrPageView * pPV)594 sal_Bool SdrSnapView::BegDragHelpLine(sal_uInt16 nHelpLineNum, SdrPageView* pPV)
595 {
596 	sal_Bool bRet(sal_False);
597 
598 	if(!bHlplFixed)
599 	{
600 		BrkAction();
601 
602 		if(pPV && nHelpLineNum < pPV->GetHelpLines().GetCount())
603 		{
604 			const SdrHelpLineList& rHelpLines = pPV->GetHelpLines();
605 			const SdrHelpLine& rHelpLine = rHelpLines[nHelpLineNum];
606 			Point aHelpLinePos = rHelpLine.GetPos(); // + pPV->GetOffset();
607 			basegfx::B2DPoint aStartPos(aHelpLinePos.X(), aHelpLinePos.Y());
608 
609 			DBG_ASSERT(0L == mpHelpLineOverlay, "SdrSnapView::BegDragHelpLine: There exists a ImplHelpLineOverlay (!)");
610 			mpHelpLineOverlay = new ImplHelpLineOverlay(*this, aStartPos, pPV, nHelpLineNum, rHelpLine.GetKind());
611 
612 			aDragStat.Reset(GetSnapPos(aHelpLinePos, pPV));
613 			aDragStat.SetMinMove(ImpGetMinMovLogic(-3, 0L));
614 
615 			bRet = sal_True;
616 		}
617 	}
618 
619 	return bRet;
620 }
621 
622 // start HelpLine drag with existing HelpLine
BegDragHelpLine(const Point & rPnt,SdrHelpLineKind eNewKind)623 sal_Bool SdrSnapView::BegDragHelpLine(const Point& rPnt, SdrHelpLineKind eNewKind)
624 {
625 	sal_Bool bRet(sal_False);
626 
627 	BrkAction();
628 
629 	if(GetSdrPageView())
630 	{
631 		DBG_ASSERT(0L == mpHelpLineOverlay, "SdrSnapView::BegDragHelpLine: There exists a ImplHelpLineOverlay (!)");
632 		basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
633 		mpHelpLineOverlay = new ImplHelpLineOverlay(*this, aStartPos, 0L, 0, eNewKind);
634 		aDragStat.Reset(GetSnapPos(rPnt, 0L));
635 		bRet = sal_True;
636 	}
637 
638 	return bRet;
639 }
640 
GetDraggedHelpLinePointer() const641 Pointer SdrSnapView::GetDraggedHelpLinePointer() const
642 {
643 	if(IsDragHelpLine())
644 	{
645 		switch(mpHelpLineOverlay->GetHelpLineKind())
646 		{
647 			case SDRHELPLINE_VERTICAL  : return Pointer(POINTER_ESIZE);
648 			case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
649 			default                    : return Pointer(POINTER_MOVE);
650 		}
651 	}
652 
653 	return Pointer(POINTER_MOVE);
654 }
655 
MovDragHelpLine(const Point & rPnt)656 void SdrSnapView::MovDragHelpLine(const Point& rPnt)
657 {
658 	if(IsDragHelpLine() && aDragStat.CheckMinMoved(rPnt))
659 	{
660 		Point aPnt(GetSnapPos(rPnt, 0L));
661 
662 		if(aPnt != aDragStat.GetNow())
663 		{
664 			aDragStat.NextMove(aPnt);
665 			DBG_ASSERT(mpHelpLineOverlay, "SdrSnapView::MovDragHelpLine: no ImplHelpLineOverlay (!)");
666 			basegfx::B2DPoint aNewPos(aDragStat.GetNow().X(), aDragStat.GetNow().Y());
667 			mpHelpLineOverlay->SetPosition(aNewPos);
668 		}
669 	}
670 }
671 
EndDragHelpLine()672 sal_Bool SdrSnapView::EndDragHelpLine()
673 {
674 	sal_Bool bRet(sal_False);
675 
676 	if(IsDragHelpLine())
677 	{
678 		if(aDragStat.IsMinMoved())
679 		{
680 			SdrPageView* pPageView = mpHelpLineOverlay->GetPageView();
681 
682 			if(pPageView)
683 			{
684 				// moved existing one
685 				Point aPnt(aDragStat.GetNow());
686 				const SdrHelpLineList& rHelpLines = pPageView->GetHelpLines();
687 				SdrHelpLine aChangedHelpLine = rHelpLines[mpHelpLineOverlay->GetHelpLineNumber()];
688 				aChangedHelpLine.SetPos(aPnt);
689 				pPageView->SetHelpLine(mpHelpLineOverlay->GetHelpLineNumber(), aChangedHelpLine);
690 
691 				bRet = sal_True;
692 			}
693 			else
694 			{
695 				// create new one
696 				pPageView = GetSdrPageView();
697 
698 				if(pPageView)
699 				{
700 					Point aPnt(aDragStat.GetNow());
701 					SdrHelpLine aNewHelpLine(mpHelpLineOverlay->GetHelpLineKind(), aPnt);
702 					pPageView->InsertHelpLine(aNewHelpLine);
703 
704 					bRet = sal_True;
705 				}
706 			}
707 		}
708 
709 		// cleanup
710 		BrkDragHelpLine();
711 	}
712 
713 	return bRet;
714 }
715 
BrkDragHelpLine()716 void SdrSnapView::BrkDragHelpLine()
717 {
718 	if(IsDragHelpLine())
719 	{
720 		DBG_ASSERT(mpHelpLineOverlay, "SdrSnapView::EndDragHelpLine: no ImplHelpLineOverlay (!)");
721 		delete mpHelpLineOverlay;
722 		mpHelpLineOverlay = 0L;
723 	}
724 }
725 
726 // eof
727