update dev300-m58
[ooovba.git] / basctl / source / dlged / dlgedfunc.cxx
blobbcc78a44c368071af350fa40f7211a7d41550aef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgedfunc.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
33 #include <vcl/scrbar.hxx>
34 #include <svx/svdview.hxx>
35 #include "dlgedfunc.hxx"
36 #include "dlged.hxx"
37 #include "dlgedview.hxx"
38 #include <vcl/seleng.hxx>
41 //----------------------------------------------------------------------------
43 IMPL_LINK_INLINE_START( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
45 (void)pTimer;
46 Window* pWindow = pParent->GetWindow();
47 Point aPos = pWindow->ScreenToOutputPixel( pWindow->GetPointerPosPixel() );
48 aPos = pWindow->PixelToLogic( aPos );
49 ForceScroll( aPos );
50 return 0;
52 IMPL_LINK_INLINE_END( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
54 //----------------------------------------------------------------------------
56 void DlgEdFunc::ForceScroll( const Point& rPos )
58 aScrollTimer.Stop();
60 Window* pWindow = pParent->GetWindow();
62 static Point aDefPoint;
63 Rectangle aOutRect( aDefPoint, pWindow->GetOutputSizePixel() );
64 aOutRect = pWindow->PixelToLogic( aOutRect );
66 ScrollBar* pHScroll = pParent->GetHScroll();
67 ScrollBar* pVScroll = pParent->GetVScroll();
68 long nDeltaX = pHScroll->GetLineSize();
69 long nDeltaY = pVScroll->GetLineSize();
71 if( !aOutRect.IsInside( rPos ) )
73 if( rPos.X() < aOutRect.Left() )
74 nDeltaX = -nDeltaX;
75 else
76 if( rPos.X() <= aOutRect.Right() )
77 nDeltaX = 0;
79 if( rPos.Y() < aOutRect.Top() )
80 nDeltaY = -nDeltaY;
81 else
82 if( rPos.Y() <= aOutRect.Bottom() )
83 nDeltaY = 0;
85 if( nDeltaX )
86 pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
87 if( nDeltaY )
88 pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
90 if( nDeltaX )
91 pParent->DoScroll( pHScroll );
92 if( nDeltaY )
93 pParent->DoScroll( pVScroll );
96 aScrollTimer.Start();
99 //----------------------------------------------------------------------------
101 DlgEdFunc::DlgEdFunc( DlgEditor* pParent_ )
103 DlgEdFunc::pParent = pParent_;
104 aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
105 aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
108 //----------------------------------------------------------------------------
110 DlgEdFunc::~DlgEdFunc()
114 //----------------------------------------------------------------------------
116 BOOL DlgEdFunc::MouseButtonDown( const MouseEvent& )
118 return TRUE;
121 //----------------------------------------------------------------------------
123 BOOL DlgEdFunc::MouseButtonUp( const MouseEvent& )
125 aScrollTimer.Stop();
126 return TRUE;
129 //----------------------------------------------------------------------------
131 BOOL DlgEdFunc::MouseMove( const MouseEvent& )
133 return TRUE;
136 //----------------------------------------------------------------------------
138 BOOL DlgEdFunc::KeyInput( const KeyEvent& rKEvt )
140 BOOL bReturn = FALSE;
142 SdrView* pView = pParent->GetView();
143 Window* pWindow = pParent->GetWindow();
145 KeyCode aCode = rKEvt.GetKeyCode();
146 USHORT nCode = aCode.GetCode();
148 switch ( nCode )
150 case KEY_ESCAPE:
152 if ( pView->IsAction() )
154 pView->BrkAction();
155 bReturn = TRUE;
157 else if ( pView->AreObjectsMarked() )
159 const SdrHdlList& rHdlList = pView->GetHdlList();
160 SdrHdl* pHdl = rHdlList.GetFocusHdl();
161 if ( pHdl )
162 ((SdrHdlList&)rHdlList).ResetFocusHdl();
163 else
164 pView->UnmarkAll();
166 bReturn = TRUE;
169 break;
170 case KEY_TAB:
172 if ( !aCode.IsMod1() && !aCode.IsMod2() )
174 // mark next object
175 if ( !pView->MarkNextObj( !aCode.IsShift() ) )
177 // if no next object, mark first/last
178 pView->UnmarkAllObj();
179 pView->MarkNextObj( !aCode.IsShift() );
182 if ( pView->AreObjectsMarked() )
183 pView->MakeVisible( pView->GetAllMarkedRect(), *pWindow );
185 bReturn = TRUE;
187 else if ( aCode.IsMod1() )
189 // selected handle
190 const SdrHdlList& rHdlList = pView->GetHdlList();
191 ((SdrHdlList&)rHdlList).TravelFocusHdl( !aCode.IsShift() );
193 // guarantee visibility of focused handle
194 SdrHdl* pHdl = rHdlList.GetFocusHdl();
195 if ( pHdl )
197 Point aHdlPosition( pHdl->GetPos() );
198 Rectangle aVisRect( aHdlPosition - Point( 100, 100 ), Size( 200, 200 ) );
199 pView->MakeVisible( aVisRect, *pWindow );
202 bReturn = TRUE;
205 break;
206 case KEY_UP:
207 case KEY_DOWN:
208 case KEY_LEFT:
209 case KEY_RIGHT:
211 long nX = 0;
212 long nY = 0;
214 if ( nCode == KEY_UP )
216 // scroll up
217 nX = 0;
218 nY = -1;
220 else if ( nCode == KEY_DOWN )
222 // scroll down
223 nX = 0;
224 nY = 1;
226 else if ( nCode == KEY_LEFT )
228 // scroll left
229 nX = -1;
230 nY = 0;
232 else if ( nCode == KEY_RIGHT )
234 // scroll right
235 nX = 1;
236 nY = 0;
239 if ( pView->AreObjectsMarked() && !aCode.IsMod1() )
241 if ( aCode.IsMod2() )
243 // move in 1 pixel distance
244 Size aPixelSize = pWindow ? pWindow->PixelToLogic( Size( 1, 1 ) ) : Size( 100, 100 );
245 nX *= aPixelSize.Width();
246 nY *= aPixelSize.Height();
248 else
250 // move in 1 mm distance
251 nX *= 100;
252 nY *= 100;
255 const SdrHdlList& rHdlList = pView->GetHdlList();
256 SdrHdl* pHdl = rHdlList.GetFocusHdl();
258 if ( pHdl == 0 )
260 // no handle selected
261 if ( pView->IsMoveAllowed() )
263 // restrict movement to work area
264 const Rectangle& rWorkArea = pView->GetWorkArea();
266 if ( !rWorkArea.IsEmpty() )
268 Rectangle aMarkRect( pView->GetMarkedObjRect() );
269 aMarkRect.Move( nX, nY );
271 if ( !rWorkArea.IsInside( aMarkRect ) )
273 if ( aMarkRect.Left() < rWorkArea.Left() )
274 nX += rWorkArea.Left() - aMarkRect.Left();
276 if ( aMarkRect.Right() > rWorkArea.Right() )
277 nX -= aMarkRect.Right() - rWorkArea.Right();
279 if ( aMarkRect.Top() < rWorkArea.Top() )
280 nY += rWorkArea.Top() - aMarkRect.Top();
282 if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
283 nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
287 if ( nX != 0 || nY != 0 )
289 pView->MoveAllMarked( Size( nX, nY ) );
290 pView->MakeVisible( pView->GetAllMarkedRect(), *pWindow );
294 else
296 // move the handle
297 if ( pHdl && ( nX || nY ) )
299 Point aStartPoint( pHdl->GetPos() );
300 Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
301 const SdrDragStat& rDragStat = pView->GetDragStat();
303 // start dragging
304 pView->BegDragObj( aStartPoint, 0, pHdl, 0 );
306 if ( pView->IsDragObj() )
308 FASTBOOL bWasNoSnap = rDragStat.IsNoSnap();
309 BOOL bWasSnapEnabled = pView->IsSnapEnabled();
311 // switch snapping off
312 if ( !bWasNoSnap )
313 ((SdrDragStat&)rDragStat).SetNoSnap( TRUE );
314 if ( bWasSnapEnabled )
315 pView->SetSnapEnabled( FALSE );
317 pView->MovAction( aEndPoint );
318 pView->EndDragObj();
320 // restore snap
321 if ( !bWasNoSnap )
322 ((SdrDragStat&)rDragStat).SetNoSnap( bWasNoSnap );
323 if ( bWasSnapEnabled )
324 pView->SetSnapEnabled( bWasSnapEnabled );
327 // make moved handle visible
328 Rectangle aVisRect( aEndPoint - Point( 100, 100 ), Size( 200, 200 ) );
329 pView->MakeVisible( aVisRect, *pWindow );
333 else
335 // scroll page
336 ScrollBar* pScrollBar = ( nX != 0 ) ? pParent->GetHScroll() : pParent->GetVScroll();
337 if ( pScrollBar )
339 long nRangeMin = pScrollBar->GetRangeMin();
340 long nRangeMax = pScrollBar->GetRangeMax();
341 long nThumbPos = pScrollBar->GetThumbPos() + ( ( nX != 0 ) ? nX : nY ) * pScrollBar->GetLineSize();
342 if ( nThumbPos < nRangeMin )
343 nThumbPos = nRangeMin;
344 if ( nThumbPos > nRangeMax )
345 nThumbPos = nRangeMax;
346 pScrollBar->SetThumbPos( nThumbPos );
347 pParent->DoScroll( pScrollBar );
351 bReturn = TRUE;
353 break;
354 default:
357 break;
360 if ( bReturn )
361 pWindow->ReleaseMouse();
363 return bReturn;
366 //----------------------------------------------------------------------------
368 DlgEdFuncInsert::DlgEdFuncInsert( DlgEditor* pParent_ ) :
369 DlgEdFunc( pParent_ )
371 pParent_->GetView()->SetCreateMode( TRUE );
374 //----------------------------------------------------------------------------
376 DlgEdFuncInsert::~DlgEdFuncInsert()
378 pParent->GetView()->SetEditMode( TRUE );
381 //----------------------------------------------------------------------------
383 BOOL DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
385 if( !rMEvt.IsLeft() )
386 return TRUE;
388 SdrView* pView = pParent->GetView();
389 Window* pWindow= pParent->GetWindow();
390 pView->SetActualWin( pWindow );
392 Point aPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
393 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
394 USHORT nDrgLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
396 pWindow->CaptureMouse();
398 if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
400 SdrHdl* pHdl = pView->PickHandle(aPos);
402 // if selected object was hit, drag object
403 if ( pHdl!=NULL || pView->IsMarkedHit(aPos, nHitLog) )
404 pView->BegDragObj(aPos, (OutputDevice*) NULL, pHdl, nDrgLog);
405 else if ( pView->AreObjectsMarked() )
406 pView->UnmarkAll();
408 // if no action, create object
409 if ( !pView->IsAction() )
410 pView->BegCreateObj(aPos);
412 else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
414 // if object was hit, show property browser
415 if ( pView->IsMarkedHit(aPos, nHitLog) && pParent->GetMode() != DLGED_READONLY )
416 pParent->ShowProperties();
419 return TRUE;
422 //----------------------------------------------------------------------------
424 BOOL DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
426 DlgEdFunc::MouseButtonUp( rMEvt );
428 SdrView* pView = pParent->GetView();
429 Window* pWindow= pParent->GetWindow();
430 pView->SetActualWin( pWindow );
432 pWindow->ReleaseMouse();
434 // object creation active?
435 if ( pView->IsCreateObj() )
437 pView->EndCreateObj(SDRCREATE_FORCEEND);
439 if ( !pView->AreObjectsMarked() )
441 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
442 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
443 pView->MarkObj(aPos, nHitLog);
446 if( pView->AreObjectsMarked() )
447 return TRUE;
448 else
449 return FALSE;
451 else
453 if ( pView->IsDragObj() )
454 pView->EndDragObj( rMEvt.IsMod1() );
455 return TRUE;
459 //----------------------------------------------------------------------------
461 BOOL DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
463 SdrView* pView = pParent->GetView();
464 Window* pWindow= pParent->GetWindow();
465 pView->SetActualWin( pWindow );
467 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
468 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
470 if ( pView->IsAction() )
472 ForceScroll(aPos);
473 pView->MovAction(aPos);
476 pWindow->SetPointer( pView->GetPreferedPointer( aPos, pWindow, nHitLog ) );
478 return TRUE;
481 //----------------------------------------------------------------------------
483 DlgEdFuncSelect::DlgEdFuncSelect( DlgEditor* pParent_ ) :
484 DlgEdFunc( pParent_ ),
485 bMarkAction(FALSE)
489 //----------------------------------------------------------------------------
491 DlgEdFuncSelect::~DlgEdFuncSelect()
495 //----------------------------------------------------------------------------
497 BOOL DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
499 // get view from parent
500 SdrView* pView = pParent->GetView();
501 Window* pWindow = pParent->GetWindow();
502 pView->SetActualWin( pWindow );
504 USHORT nDrgLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
505 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
506 Point aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
508 if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
510 SdrHdl* pHdl = pView->PickHandle(aMDPos);
511 SdrObject* pObj;
512 SdrPageView* pPV;
514 // hit selected object?
515 if ( pHdl!=NULL || pView->IsMarkedHit(aMDPos, nHitLog) )
517 pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
519 else
521 // if not multi selection, unmark all
522 if ( !rMEvt.IsShift() )
523 pView->UnmarkAll();
524 else
526 if( pView->PickObj( aMDPos, nHitLog, pObj, pPV ) )
528 //if( pObj->ISA( DlgEdForm ) )
529 // pView->UnmarkAll();
530 //else
531 // pParent->UnmarkDialog();
535 if ( pView->MarkObj(aMDPos, nHitLog) )
537 // drag object
538 pHdl=pView->PickHandle(aMDPos);
539 pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
541 else
543 // select object
544 pView->BegMarkObj(aMDPos);
545 bMarkAction = TRUE;
549 else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
551 // if object was hit, show property browser
552 if ( pView->IsMarkedHit(aMDPos, nHitLog) && pParent->GetMode() != DLGED_READONLY )
553 pParent->ShowProperties();
556 return TRUE;
559 //----------------------------------------------------------------------------
561 BOOL DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
563 DlgEdFunc::MouseButtonUp( rMEvt );
565 // get view from parent
566 SdrView* pView = pParent->GetView();
567 Window* pWindow= pParent->GetWindow();
568 pView->SetActualWin( pWindow );
570 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
571 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
573 if ( rMEvt.IsLeft() )
575 if ( pView->IsDragObj() )
577 // object was dragged
578 pView->EndDragObj( rMEvt.IsMod1() );
579 pView->ForceMarkedToAnotherPage();
581 else
582 if (pView->IsAction() )
584 pView->EndAction();
585 //if( bMarkAction )
586 //pParent->UnmarkDialog();
590 // USHORT nClicks = rMEvt.GetClicks();
591 // if (nClicks == 2)
592 // {
593 // if ( pView->AreObjectsMarked() )
594 // {
595 // const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
597 // if (rMarkList.GetMarkCount() == 1)
598 // {
599 // SdrMark* pMark = rMarkList.GetMark(0);
600 // SdrObject* pObj = pMark->GetMarkedSdrObj();
602 // // edit objects here
603 // }
604 // }
605 // }
607 bMarkAction = FALSE;
609 pWindow->SetPointer( pView->GetPreferedPointer( aPnt, pWindow, nHitLog ) );
610 pWindow->ReleaseMouse();
612 return TRUE;
615 //----------------------------------------------------------------------------
617 BOOL DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
619 SdrView* pView = pParent->GetView();
620 Window* pWindow= pParent->GetWindow();
621 pView->SetActualWin( pWindow );
623 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
624 USHORT nHitLog = USHORT ( pWindow->PixelToLogic(Size(3,0)).Width() );
626 if ( pView->IsAction() )
628 Point aPix(rMEvt.GetPosPixel());
629 Point aPnt_(pWindow->PixelToLogic(aPix));
631 ForceScroll(aPnt_);
632 pView->MovAction(aPnt_);
635 pWindow->SetPointer( pView->GetPreferedPointer( aPnt, pWindow, nHitLog ) );
637 return TRUE;
640 //----------------------------------------------------------------------------