xref: /aoo41x/main/basctl/source/dlged/dlgedfunc.cxx (revision 31598a22)
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_basctl.hxx"
26 #include <vcl/scrbar.hxx>
27 #include <svx/svdview.hxx>
28 #include "dlgedfunc.hxx"
29 #include "dlged.hxx"
30 #include "dlgedview.hxx"
31 #include <vcl/seleng.hxx>
32 
33 
34 //----------------------------------------------------------------------------
35 
IMPL_LINK_INLINE_START(DlgEdFunc,ScrollTimeout,Timer *,pTimer)36 IMPL_LINK_INLINE_START( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
37 {
38 	(void)pTimer;
39 	Window* pWindow = pParent->GetWindow();
40 	Point aPos = pWindow->ScreenToOutputPixel( pWindow->GetPointerPosPixel() );
41 	aPos = pWindow->PixelToLogic( aPos );
42 	ForceScroll( aPos );
43 	return 0;
44 }
IMPL_LINK_INLINE_END(DlgEdFunc,ScrollTimeout,Timer *,pTimer)45 IMPL_LINK_INLINE_END( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
46 
47 //----------------------------------------------------------------------------
48 
49 void DlgEdFunc::ForceScroll( const Point& rPos )
50 {
51 	aScrollTimer.Stop();
52 
53 	Window* pWindow  = pParent->GetWindow();
54 
55 	static Point aDefPoint;
56 	Rectangle aOutRect( aDefPoint, pWindow->GetOutputSizePixel() );
57 	aOutRect = pWindow->PixelToLogic( aOutRect );
58 
59 	ScrollBar* pHScroll = pParent->GetHScroll();
60 	ScrollBar* pVScroll = pParent->GetVScroll();
61 	long nDeltaX = pHScroll->GetLineSize();
62 	long nDeltaY = pVScroll->GetLineSize();
63 
64 	if( !aOutRect.IsInside( rPos ) )
65 	{
66 		if( rPos.X() < aOutRect.Left() )
67 			nDeltaX = -nDeltaX;
68 		else
69 		if( rPos.X() <= aOutRect.Right() )
70 			nDeltaX = 0;
71 
72 		if( rPos.Y() < aOutRect.Top() )
73 			nDeltaY = -nDeltaY;
74 		else
75 		if( rPos.Y() <= aOutRect.Bottom() )
76 			nDeltaY = 0;
77 
78 		if( nDeltaX )
79 			pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
80 		if( nDeltaY )
81 			pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
82 
83 		if( nDeltaX )
84 			pParent->DoScroll( pHScroll );
85 		if( nDeltaY )
86 			pParent->DoScroll( pVScroll );
87 	}
88 
89 	aScrollTimer.Start();
90 }
91 
92 //----------------------------------------------------------------------------
93 
DlgEdFunc(DlgEditor * pParent_)94 DlgEdFunc::DlgEdFunc( DlgEditor* pParent_ )
95 {
96 	DlgEdFunc::pParent = pParent_;
97 	aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
98 	aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
99 }
100 
101 //----------------------------------------------------------------------------
102 
~DlgEdFunc()103 DlgEdFunc::~DlgEdFunc()
104 {
105 }
106 
107 //----------------------------------------------------------------------------
108 
MouseButtonDown(const MouseEvent &)109 sal_Bool DlgEdFunc::MouseButtonDown( const MouseEvent& )
110 {
111 	return sal_True;
112 }
113 
114 //----------------------------------------------------------------------------
115 
MouseButtonUp(const MouseEvent &)116 sal_Bool DlgEdFunc::MouseButtonUp( const MouseEvent& )
117 {
118 	aScrollTimer.Stop();
119 	return sal_True;
120 }
121 
122 //----------------------------------------------------------------------------
123 
MouseMove(const MouseEvent &)124 sal_Bool DlgEdFunc::MouseMove( const MouseEvent& )
125 {
126 	return sal_True;
127 }
128 
129 //----------------------------------------------------------------------------
130 
KeyInput(const KeyEvent & rKEvt)131 sal_Bool DlgEdFunc::KeyInput( const KeyEvent& rKEvt )
132 {
133 	sal_Bool bReturn = sal_False;
134 
135 	SdrView* pView = pParent->GetView();
136 	Window* pWindow = pParent->GetWindow();
137 
138 	KeyCode aCode = rKEvt.GetKeyCode();
139 	sal_uInt16 nCode = aCode.GetCode();
140 
141 	switch ( nCode )
142 	{
143 		case KEY_ESCAPE:
144 		{
145 			if ( pView->IsAction() )
146 			{
147 				pView->BrkAction();
148 				bReturn = sal_True;
149 			}
150 			else if ( pView->AreObjectsMarked() )
151 			{
152 				const SdrHdlList& rHdlList = pView->GetHdlList();
153 				SdrHdl* pHdl = rHdlList.GetFocusHdl();
154 				if ( pHdl )
155 					((SdrHdlList&)rHdlList).ResetFocusHdl();
156 				else
157 					pView->UnmarkAll();
158 
159 				bReturn = sal_True;
160 			}
161 		}
162 		break;
163 		case KEY_TAB:
164 		{
165 			if ( !aCode.IsMod1() && !aCode.IsMod2() )
166 			{
167 				// mark next object
168 				if ( !pView->MarkNextObj( !aCode.IsShift() ) )
169 				{
170 					// if no next object, mark first/last
171 					pView->UnmarkAllObj();
172 					pView->MarkNextObj( !aCode.IsShift() );
173 				}
174 
175 				if ( pView->AreObjectsMarked() )
176 					pView->MakeVisible( pView->GetAllMarkedRect(), *pWindow );
177 
178 				bReturn = sal_True;
179 			}
180 			else if ( aCode.IsMod1() )
181 			{
182 				// selected handle
183 				const SdrHdlList& rHdlList = pView->GetHdlList();
184 				((SdrHdlList&)rHdlList).TravelFocusHdl( !aCode.IsShift() );
185 
186 				// guarantee visibility of focused handle
187 				SdrHdl* pHdl = rHdlList.GetFocusHdl();
188 				if ( pHdl )
189 				{
190 					Point aHdlPosition( pHdl->GetPos() );
191 					Rectangle aVisRect( aHdlPosition - Point( 100, 100 ), Size( 200, 200 ) );
192 					pView->MakeVisible( aVisRect, *pWindow );
193 				}
194 
195 				bReturn = sal_True;
196 			}
197 		}
198 		break;
199 		case KEY_UP:
200 		case KEY_DOWN:
201 		case KEY_LEFT:
202 		case KEY_RIGHT:
203 		{
204 			long nX = 0;
205 			long nY = 0;
206 
207 			if ( nCode == KEY_UP )
208 			{
209 				// scroll up
210 				nX =  0;
211 				nY = -1;
212 			}
213 			else if ( nCode == KEY_DOWN )
214 			{
215 				// scroll down
216 				nX =  0;
217 				nY =  1;
218 			}
219 			else if ( nCode == KEY_LEFT )
220 			{
221 				// scroll left
222 				nX = -1;
223 				nY =  0;
224 			}
225 			else if ( nCode == KEY_RIGHT )
226 			{
227 				// scroll right
228 				nX =  1;
229 				nY =  0;
230 			}
231 
232 			if ( pView->AreObjectsMarked() && !aCode.IsMod1() )
233 			{
234 				if ( aCode.IsMod2() )
235 				{
236 					// move in 1 pixel distance
237 					Size aPixelSize = pWindow ? pWindow->PixelToLogic( Size( 1, 1 ) ) : Size( 100, 100 );
238 					nX *= aPixelSize.Width();
239 					nY *= aPixelSize.Height();
240 				}
241 				else
242 				{
243 					// move in 1 mm distance
244 					nX *= 100;
245 					nY *= 100;
246 				}
247 
248 				const SdrHdlList& rHdlList = pView->GetHdlList();
249 				SdrHdl* pHdl = rHdlList.GetFocusHdl();
250 
251 				if ( pHdl == 0 )
252 				{
253 					// no handle selected
254 					if ( pView->IsMoveAllowed() )
255 					{
256 						// restrict movement to work area
257 						const Rectangle& rWorkArea = pView->GetWorkArea();
258 
259 						if ( !rWorkArea.IsEmpty() )
260 						{
261 							Rectangle aMarkRect( pView->GetMarkedObjRect() );
262 							aMarkRect.Move( nX, nY );
263 
264 							if ( !rWorkArea.IsInside( aMarkRect ) )
265 							{
266 								if ( aMarkRect.Left() < rWorkArea.Left() )
267 									nX += rWorkArea.Left() - aMarkRect.Left();
268 
269 								if ( aMarkRect.Right() > rWorkArea.Right() )
270 									nX -= aMarkRect.Right() - rWorkArea.Right();
271 
272 								if ( aMarkRect.Top() < rWorkArea.Top() )
273 									nY += rWorkArea.Top() - aMarkRect.Top();
274 
275 								if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
276 									nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
277 							}
278 						}
279 
280 						if ( nX != 0 || nY != 0 )
281 						{
282 							pView->MoveAllMarked( Size( nX, nY ) );
283 							pView->MakeVisible( pView->GetAllMarkedRect(), *pWindow );
284 						}
285 					}
286 				}
287 				else
288 				{
289 					// move the handle
290 					if ( pHdl && ( nX || nY ) )
291 					{
292 						Point aStartPoint( pHdl->GetPos() );
293 						Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
294 						const SdrDragStat& rDragStat = pView->GetDragStat();
295 
296 						// start dragging
297 						pView->BegDragObj( aStartPoint, 0, pHdl, 0 );
298 
299 					    if ( pView->IsDragObj() )
300 						{
301 							FASTBOOL bWasNoSnap = rDragStat.IsNoSnap();
302 							sal_Bool bWasSnapEnabled = pView->IsSnapEnabled();
303 
304 							// switch snapping off
305 							if ( !bWasNoSnap )
306 								((SdrDragStat&)rDragStat).SetNoSnap( sal_True );
307 							if ( bWasSnapEnabled )
308 								pView->SetSnapEnabled( sal_False );
309 
310 							pView->MovAction( aEndPoint );
311 							pView->EndDragObj();
312 
313 							// restore snap
314 							if ( !bWasNoSnap )
315 								((SdrDragStat&)rDragStat).SetNoSnap( bWasNoSnap );
316 							if ( bWasSnapEnabled )
317 								pView->SetSnapEnabled( bWasSnapEnabled );
318 						}
319 
320 						// make moved handle visible
321 						Rectangle aVisRect( aEndPoint - Point( 100, 100 ), Size( 200, 200 ) );
322 						pView->MakeVisible( aVisRect, *pWindow );
323 					}
324 				}
325 			}
326 			else
327 			{
328 				// scroll page
329 				ScrollBar* pScrollBar = ( nX != 0 ) ? pParent->GetHScroll() : pParent->GetVScroll();
330 				if ( pScrollBar )
331 				{
332 					long nRangeMin = pScrollBar->GetRangeMin();
333 					long nRangeMax = pScrollBar->GetRangeMax();
334 					long nThumbPos = pScrollBar->GetThumbPos() + ( ( nX != 0 ) ? nX : nY ) * pScrollBar->GetLineSize();
335 					if ( nThumbPos < nRangeMin )
336 						nThumbPos = nRangeMin;
337 					if ( nThumbPos > nRangeMax )
338 						nThumbPos = nRangeMax;
339 					pScrollBar->SetThumbPos( nThumbPos );
340 					pParent->DoScroll( pScrollBar );
341 				}
342 			}
343 
344 			bReturn = sal_True;
345 		}
346 		break;
347 		default:
348 		{
349 		}
350 		break;
351 	}
352 
353 	if ( bReturn )
354 		pWindow->ReleaseMouse();
355 
356 	return bReturn;
357 }
358 
359 //----------------------------------------------------------------------------
360 
DlgEdFuncInsert(DlgEditor * pParent_)361 DlgEdFuncInsert::DlgEdFuncInsert( DlgEditor* pParent_ ) :
362 	DlgEdFunc( pParent_ )
363 {
364 	pParent_->GetView()->SetCreateMode( sal_True );
365 }
366 
367 //----------------------------------------------------------------------------
368 
~DlgEdFuncInsert()369 DlgEdFuncInsert::~DlgEdFuncInsert()
370 {
371 	pParent->GetView()->SetEditMode( sal_True );
372 }
373 
374 //----------------------------------------------------------------------------
375 
MouseButtonDown(const MouseEvent & rMEvt)376 sal_Bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
377 {
378 	if( !rMEvt.IsLeft() )
379 		return sal_True;
380 
381 	SdrView* pView  = pParent->GetView();
382 	Window*  pWindow= pParent->GetWindow();
383 	pView->SetActualWin( pWindow );
384 
385 	Point aPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
386 	sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
387 	sal_uInt16 nDrgLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
388 
389 	pWindow->CaptureMouse();
390 
391 	if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
392     {
393 	    SdrHdl* pHdl = pView->PickHandle(aPos);
394 
395 	    // if selected object was hit, drag object
396 	    if ( pHdl!=NULL || pView->IsMarkedHit(aPos, nHitLog) )
397 		    pView->BegDragObj(aPos, (OutputDevice*) NULL, pHdl, nDrgLog);
398 	    else if ( pView->AreObjectsMarked() )
399 		    pView->UnmarkAll();
400 
401 	    // if no action, create object
402 	    if ( !pView->IsAction() )
403 		    pView->BegCreateObj(aPos);
404     }
405     else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
406     {
407         // if object was hit, show property browser
408 		if ( pView->IsMarkedHit(aPos, nHitLog) && pParent->GetMode() != DLGED_READONLY )
409             pParent->ShowProperties();
410     }
411 
412 	return sal_True;
413 }
414 
415 //----------------------------------------------------------------------------
416 
MouseButtonUp(const MouseEvent & rMEvt)417 sal_Bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
418 {
419 	DlgEdFunc::MouseButtonUp( rMEvt );
420 
421 	SdrView* pView  = pParent->GetView();
422 	Window*  pWindow= pParent->GetWindow();
423 	pView->SetActualWin( pWindow );
424 
425 	pWindow->ReleaseMouse();
426 
427 	// object creation active?
428 	if ( pView->IsCreateObj() )
429 	{
430 		pView->EndCreateObj(SDRCREATE_FORCEEND);
431 
432 		if ( !pView->AreObjectsMarked() )
433 		{
434 			sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
435 			Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
436 			pView->MarkObj(aPos, nHitLog);
437 		}
438 
439 		if( pView->AreObjectsMarked() )
440 			return sal_True;
441 		else
442 			return sal_False;
443 	}
444 	else
445 	{
446 		if ( pView->IsDragObj() )
447 			 pView->EndDragObj( rMEvt.IsMod1() );
448 		return sal_True;
449 	}
450 }
451 
452 //----------------------------------------------------------------------------
453 
MouseMove(const MouseEvent & rMEvt)454 sal_Bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
455 {
456 	SdrView* pView  = pParent->GetView();
457 	Window*  pWindow= pParent->GetWindow();
458 	pView->SetActualWin( pWindow );
459 
460 	Point	aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
461 	sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
462 
463 	if ( pView->IsAction() )
464 	{
465 		ForceScroll(aPos);
466 		pView->MovAction(aPos);
467 	}
468 
469 	pWindow->SetPointer( pView->GetPreferedPointer( aPos, pWindow, nHitLog ) );
470 
471 	return sal_True;
472 }
473 
474 //----------------------------------------------------------------------------
475 
DlgEdFuncSelect(DlgEditor * pParent_)476 DlgEdFuncSelect::DlgEdFuncSelect( DlgEditor* pParent_ ) :
477 	DlgEdFunc( pParent_ ),
478 	bMarkAction(sal_False)
479 {
480 }
481 
482 //----------------------------------------------------------------------------
483 
~DlgEdFuncSelect()484 DlgEdFuncSelect::~DlgEdFuncSelect()
485 {
486 }
487 
488 //----------------------------------------------------------------------------
489 
MouseButtonDown(const MouseEvent & rMEvt)490 sal_Bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
491 {
492 	// get view from parent
493 	SdrView* pView   = pParent->GetView();
494 	Window*  pWindow = pParent->GetWindow();
495 	pView->SetActualWin( pWindow );
496 
497 	sal_uInt16 nDrgLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
498 	sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
499 	Point  aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
500 
501 	if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
502 	{
503 		SdrHdl* pHdl = pView->PickHandle(aMDPos);
504 		SdrObject* pObj;
505 		SdrPageView* pPV;
506 
507 		// hit selected object?
508 		if ( pHdl!=NULL || pView->IsMarkedHit(aMDPos, nHitLog) )
509 		{
510 			pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
511 		}
512 		else
513 		{
514 			// if not multi selection, unmark all
515 			if ( !rMEvt.IsShift() )
516 				pView->UnmarkAll();
517 			else
518 			{
519 				if( pView->PickObj( aMDPos, nHitLog, pObj, pPV ) )
520 				{
521 					//if( pObj->ISA( DlgEdForm ) )
522 					//	pView->UnmarkAll();
523 					//else
524 					//	pParent->UnmarkDialog();
525 				}
526 			}
527 
528 			if ( pView->MarkObj(aMDPos, nHitLog) )
529 			{
530 				// drag object
531 				pHdl=pView->PickHandle(aMDPos);
532 				pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
533 			}
534 			else
535 			{
536 				// select object
537 				pView->BegMarkObj(aMDPos);
538 				bMarkAction = sal_True;
539 			}
540 		}
541 	}
542 	else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
543     {
544         // if object was hit, show property browser
545 		if ( pView->IsMarkedHit(aMDPos, nHitLog) && pParent->GetMode() != DLGED_READONLY )
546             pParent->ShowProperties();
547     }
548 
549 	return sal_True;
550 }
551 
552 //----------------------------------------------------------------------------
553 
MouseButtonUp(const MouseEvent & rMEvt)554 sal_Bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
555 {
556 	DlgEdFunc::MouseButtonUp( rMEvt );
557 
558 	// get view from parent
559 	SdrView* pView  = pParent->GetView();
560 	Window*  pWindow= pParent->GetWindow();
561 	pView->SetActualWin( pWindow );
562 
563 	Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
564 	sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
565 
566 	if ( rMEvt.IsLeft() )
567 	{
568 		if ( pView->IsDragObj() )
569 		{
570 			// object was dragged
571 			pView->EndDragObj( rMEvt.IsMod1() );
572 			pView->ForceMarkedToAnotherPage();
573 		}
574 		else
575 		if (pView->IsAction() )
576 		{
577 			pView->EndAction();
578 			//if( bMarkAction )
579 				//pParent->UnmarkDialog();
580 		}
581 	}
582 
583 //	sal_uInt16 nClicks = rMEvt.GetClicks();
584 //	if (nClicks == 2)
585 //	{
586 //		if ( pView->AreObjectsMarked() )
587 //		{
588 //			const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
589 //
590 //			if (rMarkList.GetMarkCount() == 1)
591 //			{
592 //				SdrMark* pMark = rMarkList.GetMark(0);
593 //				SdrObject* pObj = pMark->GetMarkedSdrObj();
594 //
595 //				// edit objects here
596 //			}
597 //		}
598 //	}
599 
600 	bMarkAction = sal_False;
601 
602 	pWindow->SetPointer( pView->GetPreferedPointer( aPnt, pWindow, nHitLog ) );
603 	pWindow->ReleaseMouse();
604 
605 	return sal_True;
606 }
607 
608 //----------------------------------------------------------------------------
609 
MouseMove(const MouseEvent & rMEvt)610 sal_Bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
611 {
612 	SdrView* pView  = pParent->GetView();
613 	Window*  pWindow= pParent->GetWindow();
614 	pView->SetActualWin( pWindow );
615 
616 	Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
617 	sal_uInt16 nHitLog = sal_uInt16 ( pWindow->PixelToLogic(Size(3,0)).Width() );
618 
619 	if ( pView->IsAction() )
620 	{
621 		Point aPix(rMEvt.GetPosPixel());
622 		Point aPnt_(pWindow->PixelToLogic(aPix));
623 
624 		ForceScroll(aPnt_);
625 		pView->MovAction(aPnt_);
626 	}
627 
628 	pWindow->SetPointer( pView->GetPreferedPointer( aPnt, pWindow, nHitLog ) );
629 
630 	return sal_True;
631 }
632 
633 //----------------------------------------------------------------------------
634