1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgedfunc.cxx,v $
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"
37 #include "dlgedview.hxx"
38 #include <vcl/seleng.hxx>
41 //----------------------------------------------------------------------------
43 IMPL_LINK_INLINE_START( DlgEdFunc
, ScrollTimeout
, Timer
*, pTimer
)
46 Window
* pWindow
= pParent
->GetWindow();
47 Point aPos
= pWindow
->ScreenToOutputPixel( pWindow
->GetPointerPosPixel() );
48 aPos
= pWindow
->PixelToLogic( aPos
);
52 IMPL_LINK_INLINE_END( DlgEdFunc
, ScrollTimeout
, Timer
*, pTimer
)
54 //----------------------------------------------------------------------------
56 void DlgEdFunc::ForceScroll( const Point
& rPos
)
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() )
76 if( rPos
.X() <= aOutRect
.Right() )
79 if( rPos
.Y() < aOutRect
.Top() )
82 if( rPos
.Y() <= aOutRect
.Bottom() )
86 pHScroll
->SetThumbPos( pHScroll
->GetThumbPos() + nDeltaX
);
88 pVScroll
->SetThumbPos( pVScroll
->GetThumbPos() + nDeltaY
);
91 pParent
->DoScroll( pHScroll
);
93 pParent
->DoScroll( pVScroll
);
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
& )
121 //----------------------------------------------------------------------------
123 BOOL
DlgEdFunc::MouseButtonUp( const MouseEvent
& )
129 //----------------------------------------------------------------------------
131 BOOL
DlgEdFunc::MouseMove( const MouseEvent
& )
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();
152 if ( pView
->IsAction() )
157 else if ( pView
->AreObjectsMarked() )
159 const SdrHdlList
& rHdlList
= pView
->GetHdlList();
160 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
162 ((SdrHdlList
&)rHdlList
).ResetFocusHdl();
172 if ( !aCode
.IsMod1() && !aCode
.IsMod2() )
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
);
187 else if ( aCode
.IsMod1() )
190 const SdrHdlList
& rHdlList
= pView
->GetHdlList();
191 ((SdrHdlList
&)rHdlList
).TravelFocusHdl( !aCode
.IsShift() );
193 // guarantee visibility of focused handle
194 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
197 Point
aHdlPosition( pHdl
->GetPos() );
198 Rectangle
aVisRect( aHdlPosition
- Point( 100, 100 ), Size( 200, 200 ) );
199 pView
->MakeVisible( aVisRect
, *pWindow
);
214 if ( nCode
== KEY_UP
)
220 else if ( nCode
== KEY_DOWN
)
226 else if ( nCode
== KEY_LEFT
)
232 else if ( nCode
== KEY_RIGHT
)
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();
250 // move in 1 mm distance
255 const SdrHdlList
& rHdlList
= pView
->GetHdlList();
256 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
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
);
297 if ( pHdl
&& ( nX
|| nY
) )
299 Point
aStartPoint( pHdl
->GetPos() );
300 Point
aEndPoint( pHdl
->GetPos() + Point( nX
, nY
) );
301 const SdrDragStat
& rDragStat
= pView
->GetDragStat();
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
313 ((SdrDragStat
&)rDragStat
).SetNoSnap( TRUE
);
314 if ( bWasSnapEnabled
)
315 pView
->SetSnapEnabled( FALSE
);
317 pView
->MovAction( aEndPoint
);
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
);
336 ScrollBar
* pScrollBar
= ( nX
!= 0 ) ? pParent
->GetHScroll() : pParent
->GetVScroll();
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
);
361 pWindow
->ReleaseMouse();
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() )
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() )
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();
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() )
453 if ( pView
->IsDragObj() )
454 pView
->EndDragObj( rMEvt
.IsMod1() );
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() )
473 pView
->MovAction(aPos
);
476 pWindow
->SetPointer( pView
->GetPreferedPointer( aPos
, pWindow
, nHitLog
) );
481 //----------------------------------------------------------------------------
483 DlgEdFuncSelect::DlgEdFuncSelect( DlgEditor
* pParent_
) :
484 DlgEdFunc( pParent_
),
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
);
514 // hit selected object?
515 if ( pHdl
!=NULL
|| pView
->IsMarkedHit(aMDPos
, nHitLog
) )
517 pView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
521 // if not multi selection, unmark all
522 if ( !rMEvt
.IsShift() )
526 if( pView
->PickObj( aMDPos
, nHitLog
, pObj
, pPV
) )
528 //if( pObj->ISA( DlgEdForm ) )
529 // pView->UnmarkAll();
531 // pParent->UnmarkDialog();
535 if ( pView
->MarkObj(aMDPos
, nHitLog
) )
538 pHdl
=pView
->PickHandle(aMDPos
);
539 pView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
544 pView
->BegMarkObj(aMDPos
);
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();
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();
582 if (pView
->IsAction() )
586 //pParent->UnmarkDialog();
590 // USHORT nClicks = rMEvt.GetClicks();
593 // if ( pView->AreObjectsMarked() )
595 // const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
597 // if (rMarkList.GetMarkCount() == 1)
599 // SdrMark* pMark = rMarkList.GetMark(0);
600 // SdrObject* pObj = pMark->GetMarkedSdrObj();
602 // // edit objects here
609 pWindow
->SetPointer( pView
->GetPreferedPointer( aPnt
, pWindow
, nHitLog
) );
610 pWindow
->ReleaseMouse();
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
));
632 pView
->MovAction(aPnt_
);
635 pWindow
->SetPointer( pView
->GetPreferedPointer( aPnt
, pWindow
, nHitLog
) );
640 //----------------------------------------------------------------------------