1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/scrbar.hxx>
21 #include <svx/svdview.hxx>
22 #include "dlgedfunc.hxx"
24 #include "dlgedview.hxx"
25 #include <vcl/seleng.hxx>
30 IMPL_LINK_INLINE_START( DlgEdFunc
, ScrollTimeout
, Timer
*, pTimer
)
33 Window
& rWindow
= rParent
.GetWindow();
34 Point aPos
= rWindow
.ScreenToOutputPixel( rWindow
.GetPointerPosPixel() );
35 aPos
= rWindow
.PixelToLogic( aPos
);
39 IMPL_LINK_INLINE_END( DlgEdFunc
, ScrollTimeout
, Timer
*, pTimer
)
41 void DlgEdFunc::ForceScroll( const Point
& rPos
)
45 Window
& rWindow
= rParent
.GetWindow();
47 static Point aDefPoint
;
48 Rectangle
aOutRect( aDefPoint
, rWindow
.GetOutputSizePixel() );
49 aOutRect
= rWindow
.PixelToLogic( aOutRect
);
51 ScrollBar
* pHScroll
= rParent
.GetHScroll();
52 ScrollBar
* pVScroll
= rParent
.GetVScroll();
53 long nDeltaX
= pHScroll
->GetLineSize();
54 long nDeltaY
= pVScroll
->GetLineSize();
56 if( !aOutRect
.IsInside( rPos
) )
58 if( rPos
.X() < aOutRect
.Left() )
60 else if( rPos
.X() <= aOutRect
.Right() )
63 if( rPos
.Y() < aOutRect
.Top() )
65 else if( rPos
.Y() <= aOutRect
.Bottom() )
69 pHScroll
->SetThumbPos( pHScroll
->GetThumbPos() + nDeltaX
);
71 pVScroll
->SetThumbPos( pVScroll
->GetThumbPos() + nDeltaY
);
74 rParent
.DoScroll( pHScroll
);
76 rParent
.DoScroll( pVScroll
);
82 DlgEdFunc::DlgEdFunc (DlgEditor
& rParent_
) :
85 aScrollTimer
.SetTimeoutHdl( LINK( this, DlgEdFunc
, ScrollTimeout
) );
86 aScrollTimer
.SetTimeout( SELENG_AUTOREPEAT_INTERVAL
);
89 DlgEdFunc::~DlgEdFunc()
93 bool DlgEdFunc::MouseButtonDown( const MouseEvent
& )
98 bool DlgEdFunc::MouseButtonUp( const MouseEvent
& )
104 bool DlgEdFunc::MouseMove( const MouseEvent
& )
109 bool DlgEdFunc::KeyInput( const KeyEvent
& rKEvt
)
111 bool bReturn
= false;
113 SdrView
& rView
= rParent
.GetView();
114 Window
& rWindow
= rParent
.GetWindow();
116 KeyCode aCode
= rKEvt
.GetKeyCode();
117 sal_uInt16 nCode
= aCode
.GetCode();
123 if ( rView
.IsAction() )
128 else if ( rView
.AreObjectsMarked() )
130 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
131 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
133 const_cast<SdrHdlList
&>(rHdlList
).ResetFocusHdl();
143 if ( !aCode
.IsMod1() && !aCode
.IsMod2() )
146 if ( !rView
.MarkNextObj( !aCode
.IsShift() ) )
148 // if no next object, mark first/last
149 rView
.UnmarkAllObj();
150 rView
.MarkNextObj( !aCode
.IsShift() );
153 if ( rView
.AreObjectsMarked() )
154 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
158 else if ( aCode
.IsMod1() )
161 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
162 const_cast<SdrHdlList
&>(rHdlList
).TravelFocusHdl( !aCode
.IsShift() );
164 // guarantee visibility of focused handle
165 if (SdrHdl
* pHdl
= rHdlList
.GetFocusHdl())
167 Point
aHdlPosition( pHdl
->GetPos() );
168 Rectangle
aVisRect( aHdlPosition
- Point( 100, 100 ), Size( 200, 200 ) );
169 rView
.MakeVisible( aVisRect
, rWindow
);
184 if ( nCode
== KEY_UP
)
190 else if ( nCode
== KEY_DOWN
)
196 else if ( nCode
== KEY_LEFT
)
202 else if ( nCode
== KEY_RIGHT
)
209 if ( rView
.AreObjectsMarked() && !aCode
.IsMod1() )
211 if ( aCode
.IsMod2() )
213 // move in 1 pixel distance
214 Size aPixelSize
= rWindow
.PixelToLogic(Size(1, 1));
215 nX
*= aPixelSize
.Width();
216 nY
*= aPixelSize
.Height();
220 // move in 1 mm distance
225 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
226 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
230 // no handle selected
231 if ( rView
.IsMoveAllowed() )
233 // restrict movement to work area
234 const Rectangle
& rWorkArea
= rView
.GetWorkArea();
236 if ( !rWorkArea
.IsEmpty() )
238 Rectangle
aMarkRect( rView
.GetMarkedObjRect() );
239 aMarkRect
.Move( nX
, nY
);
241 if ( !rWorkArea
.IsInside( aMarkRect
) )
243 if ( aMarkRect
.Left() < rWorkArea
.Left() )
244 nX
+= rWorkArea
.Left() - aMarkRect
.Left();
246 if ( aMarkRect
.Right() > rWorkArea
.Right() )
247 nX
-= aMarkRect
.Right() - rWorkArea
.Right();
249 if ( aMarkRect
.Top() < rWorkArea
.Top() )
250 nY
+= rWorkArea
.Top() - aMarkRect
.Top();
252 if ( aMarkRect
.Bottom() > rWorkArea
.Bottom() )
253 nY
-= aMarkRect
.Bottom() - rWorkArea
.Bottom();
257 if ( nX
!= 0 || nY
!= 0 )
259 rView
.MoveAllMarked( Size( nX
, nY
) );
260 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
267 if ( pHdl
&& ( nX
|| nY
) )
269 Point
aStartPoint( pHdl
->GetPos() );
270 Point
aEndPoint( pHdl
->GetPos() + Point( nX
, nY
) );
271 const SdrDragStat
& rDragStat
= rView
.GetDragStat();
274 rView
.BegDragObj( aStartPoint
, 0, pHdl
, 0 );
276 if ( rView
.IsDragObj() )
278 bool const bWasNoSnap
= rDragStat
.IsNoSnap();
279 bool const bWasSnapEnabled
= rView
.IsSnapEnabled();
281 // switch snapping off
283 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap(true);
284 if ( bWasSnapEnabled
)
285 rView
.SetSnapEnabled(false);
287 rView
.MovAction( aEndPoint
);
292 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap( bWasNoSnap
);
293 if ( bWasSnapEnabled
)
294 rView
.SetSnapEnabled( bWasSnapEnabled
);
297 // make moved handle visible
298 Rectangle
aVisRect( aEndPoint
- Point( 100, 100 ), Size( 200, 200 ) );
299 rView
.MakeVisible( aVisRect
, rWindow
);
306 ScrollBar
* pScrollBar
= ( nX
!= 0 ) ? rParent
.GetHScroll() : rParent
.GetVScroll();
309 long nRangeMin
= pScrollBar
->GetRangeMin();
310 long nRangeMax
= pScrollBar
->GetRangeMax();
311 long nThumbPos
= pScrollBar
->GetThumbPos() + ( ( nX
!= 0 ) ? nX
: nY
) * pScrollBar
->GetLineSize();
312 if ( nThumbPos
< nRangeMin
)
313 nThumbPos
= nRangeMin
;
314 if ( nThumbPos
> nRangeMax
)
315 nThumbPos
= nRangeMax
;
316 pScrollBar
->SetThumbPos( nThumbPos
);
317 rParent
.DoScroll( pScrollBar
);
331 rWindow
.ReleaseMouse();
336 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor
& rParent_
) :
339 rParent
.GetView().SetCreateMode(true);
342 DlgEdFuncInsert::~DlgEdFuncInsert()
344 rParent
.GetView().SetEditMode( true );
347 bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent
& rMEvt
)
349 if( !rMEvt
.IsLeft() )
352 SdrView
& rView
= rParent
.GetView();
353 Window
& rWindow
= rParent
.GetWindow();
354 rView
.SetActualWin(&rWindow
);
356 Point aPos
= rWindow
.PixelToLogic( rMEvt
.GetPosPixel() );
357 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
358 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
360 rWindow
.CaptureMouse();
362 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
364 SdrHdl
* pHdl
= rView
.PickHandle(aPos
);
366 // if selected object was hit, drag object
367 if ( pHdl
!=NULL
|| rView
.IsMarkedHit(aPos
, nHitLog
) )
368 rView
.BegDragObj(aPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
369 else if ( rView
.AreObjectsMarked() )
372 // if no action, create object
373 if ( !rView
.IsAction() )
374 rView
.BegCreateObj(aPos
);
376 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
378 // if object was hit, show property browser
379 if ( rView
.IsMarkedHit(aPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
380 rParent
.ShowProperties();
386 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent
& rMEvt
)
388 DlgEdFunc::MouseButtonUp( rMEvt
);
390 SdrView
& rView
= rParent
.GetView();
391 Window
& rWindow
= rParent
.GetWindow();
392 rView
.SetActualWin(&rWindow
);
394 rWindow
.ReleaseMouse();
396 // object creation active?
397 if ( rView
.IsCreateObj() )
399 rView
.EndCreateObj(SDRCREATE_FORCEEND
);
401 if ( !rView
.AreObjectsMarked() )
403 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
404 Point
aPos( rWindow
.PixelToLogic( rMEvt
.GetPosPixel() ) );
405 rView
.MarkObj(aPos
, nHitLog
);
408 return rView
.AreObjectsMarked();
412 if ( rView
.IsDragObj() )
413 rView
.EndDragObj( rMEvt
.IsMod1() );
418 bool DlgEdFuncInsert::MouseMove( const MouseEvent
& rMEvt
)
420 SdrView
& rView
= rParent
.GetView();
421 Window
& rWindow
= rParent
.GetWindow();
422 rView
.SetActualWin(&rWindow
);
424 Point aPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
425 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
427 if (rView
.IsAction())
430 rView
.MovAction(aPos
);
433 rWindow
.SetPointer( rView
.GetPreferredPointer( aPos
, &rWindow
, nHitLog
) );
438 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor
& rParent_
) :
444 DlgEdFuncSelect::~DlgEdFuncSelect()
448 bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent
& rMEvt
)
450 // get view from parent
451 SdrView
& rView
= rParent
.GetView();
452 Window
& rWindow
= rParent
.GetWindow();
453 rView
.SetActualWin(&rWindow
);
455 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
456 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
457 Point aMDPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
459 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
461 SdrHdl
* pHdl
= rView
.PickHandle(aMDPos
);
465 // hit selected object?
466 if ( pHdl
!=NULL
|| rView
.IsMarkedHit(aMDPos
, nHitLog
) )
468 rView
.BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
472 // if not multi selection, unmark all
473 if ( !rMEvt
.IsShift() )
477 if( rView
.PickObj( aMDPos
, nHitLog
, pObj
, pPV
) )
479 //if (dynamic_cast<DlgEdForm*>(pObj))
480 // rView.UnmarkAll();
482 // rParent.UnmarkDialog();
486 if ( rView
.MarkObj(aMDPos
, nHitLog
) )
489 pHdl
= rView
.PickHandle(aMDPos
);
490 rView
.BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
495 rView
.BegMarkObj(aMDPos
);
500 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
502 // if object was hit, show property browser
503 if ( rView
.IsMarkedHit(aMDPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
504 rParent
.ShowProperties();
510 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent
& rMEvt
)
512 DlgEdFunc::MouseButtonUp( rMEvt
);
514 // get view from parent
515 SdrView
& rView
= rParent
.GetView();
516 Window
& rWindow
= rParent
.GetWindow();
517 rView
.SetActualWin(&rWindow
);
519 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
520 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
522 if ( rMEvt
.IsLeft() )
524 if (rView
.IsDragObj())
526 // object was dragged
527 rView
.EndDragObj( rMEvt
.IsMod1() );
528 rView
.ForceMarkedToAnotherPage();
530 else if (rView
.IsAction())
538 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
539 rWindow
.ReleaseMouse();
544 bool DlgEdFuncSelect::MouseMove( const MouseEvent
& rMEvt
)
546 SdrView
& rView
= rParent
.GetView();
547 Window
& rWindow
= rParent
.GetWindow();
548 rView
.SetActualWin(&rWindow
);
550 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
551 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
553 if ( rView
.IsAction() )
555 Point aPix
= rMEvt
.GetPosPixel();
556 Point aPnt_
= rWindow
.PixelToLogic(aPix
);
559 rView
.MovAction(aPnt_
);
562 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
567 } // namespace basctl
569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */