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 <svtools/scrolladaptor.hxx>
21 #include <svx/svdview.hxx>
22 #include <dlgedfunc.hxx>
24 #include <dlgedview.hxx>
25 #include <vcl/seleng.hxx>
30 IMPL_LINK_NOARG( DlgEdFunc
, ScrollTimeout
, Timer
*, void )
32 vcl::Window
& rWindow
= rParent
.GetWindow();
33 Point aPos
= rWindow
.ScreenToOutputPixel( rWindow
.GetPointerPosPixel() );
34 aPos
= rWindow
.PixelToLogic( aPos
);
38 void DlgEdFunc::ForceScroll( const Point
& rPos
)
42 vcl::Window
& rWindow
= rParent
.GetWindow();
44 static const Point aDefPoint
;
45 tools::Rectangle
aOutRect( aDefPoint
, rWindow
.GetOutputSizePixel() );
46 aOutRect
= rWindow
.PixelToLogic( aOutRect
);
48 ScrollAdaptor
* pHScroll
= rParent
.GetHScroll();
49 ScrollAdaptor
* pVScroll
= rParent
.GetVScroll();
50 tools::Long nDeltaX
= pHScroll
->GetLineSize();
51 tools::Long nDeltaY
= pVScroll
->GetLineSize();
53 if( !aOutRect
.Contains( rPos
) )
55 if( rPos
.X() < aOutRect
.Left() )
57 else if( rPos
.X() <= aOutRect
.Right() )
60 if( rPos
.Y() < aOutRect
.Top() )
62 else if( rPos
.Y() <= aOutRect
.Bottom() )
66 pHScroll
->SetThumbPos( pHScroll
->GetThumbPos() + nDeltaX
);
68 pVScroll
->SetThumbPos( pVScroll
->GetThumbPos() + nDeltaY
);
79 DlgEdFunc::DlgEdFunc (DlgEditor
& rParent_
) :
80 rParent(rParent_
), aScrollTimer("basctl DlgEdFunc aScrollTimer")
82 aScrollTimer
.SetInvokeHandler( LINK( this, DlgEdFunc
, ScrollTimeout
) );
83 aScrollTimer
.SetTimeout( SELENG_AUTOREPEAT_INTERVAL
);
86 DlgEdFunc::~DlgEdFunc()
90 void DlgEdFunc::MouseButtonDown( const MouseEvent
& )
94 bool DlgEdFunc::MouseButtonUp( const MouseEvent
& )
100 void DlgEdFunc::MouseMove( const MouseEvent
& )
104 bool DlgEdFunc::KeyInput( const KeyEvent
& rKEvt
)
106 bool bReturn
= false;
108 SdrView
& rView
= rParent
.GetView();
109 vcl::Window
& rWindow
= rParent
.GetWindow();
111 vcl::KeyCode aCode
= rKEvt
.GetKeyCode();
112 sal_uInt16 nCode
= aCode
.GetCode();
118 if ( rView
.IsAction() )
123 else if ( rView
.GetMarkedObjectList().GetMarkCount() != 0 )
125 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
126 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
128 const_cast<SdrHdlList
&>(rHdlList
).ResetFocusHdl();
138 if ( !aCode
.IsMod1() && !aCode
.IsMod2() )
141 if ( !rView
.MarkNextObj( !aCode
.IsShift() ) )
143 // if no next object, mark first/last
144 rView
.UnmarkAllObj();
145 rView
.MarkNextObj( !aCode
.IsShift() );
148 if ( rView
.GetMarkedObjectList().GetMarkCount() != 0 )
149 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
153 else if ( aCode
.IsMod1() )
156 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
157 const_cast<SdrHdlList
&>(rHdlList
).TravelFocusHdl( !aCode
.IsShift() );
159 // guarantee visibility of focused handle
160 if (SdrHdl
* pHdl
= rHdlList
.GetFocusHdl())
162 Point
aHdlPosition( pHdl
->GetPos() );
163 tools::Rectangle
aVisRect( aHdlPosition
- Point( 100, 100 ), Size( 200, 200 ) );
164 rView
.MakeVisible( aVisRect
, rWindow
);
179 if ( nCode
== KEY_UP
)
185 else if ( nCode
== KEY_DOWN
)
191 else if ( nCode
== KEY_LEFT
)
197 else if ( nCode
== KEY_RIGHT
)
204 if ( rView
.GetMarkedObjectList().GetMarkCount() != 0 && !aCode
.IsMod1() )
206 if ( aCode
.IsMod2() )
208 // move in 1 pixel distance
209 Size aPixelSize
= rWindow
.PixelToLogic(Size(1, 1));
210 nX
*= aPixelSize
.Width();
211 nY
*= aPixelSize
.Height();
215 // move in 1 mm distance
220 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
221 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
223 if ( pHdl
== nullptr )
225 // no handle selected
226 if ( rView
.IsMoveAllowed() )
228 // restrict movement to work area
229 const tools::Rectangle
& rWorkArea
= rView
.GetWorkArea();
231 if ( !rWorkArea
.IsEmpty() )
233 tools::Rectangle
aMarkRect( rView
.GetMarkedObjRect() );
234 aMarkRect
.Move( nX
, nY
);
236 if ( !rWorkArea
.Contains( aMarkRect
) )
238 if ( aMarkRect
.Left() < rWorkArea
.Left() )
239 nX
+= rWorkArea
.Left() - aMarkRect
.Left();
241 if ( aMarkRect
.Right() > rWorkArea
.Right() )
242 nX
-= aMarkRect
.Right() - rWorkArea
.Right();
244 if ( aMarkRect
.Top() < rWorkArea
.Top() )
245 nY
+= rWorkArea
.Top() - aMarkRect
.Top();
247 if ( aMarkRect
.Bottom() > rWorkArea
.Bottom() )
248 nY
-= aMarkRect
.Bottom() - rWorkArea
.Bottom();
252 if ( nX
!= 0 || nY
!= 0 )
254 rView
.MoveAllMarked( Size( nX
, nY
) );
255 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
261 Point
aStartPoint(pHdl
->GetPos());
262 Point
aEndPoint(pHdl
->GetPos() + Point(nX
, nY
));
263 const SdrDragStat
& rDragStat
= rView
.GetDragStat();
266 rView
.BegDragObj(aStartPoint
, nullptr, pHdl
, 0);
268 if (rView
.IsDragObj())
270 bool const bWasNoSnap
= rDragStat
.IsNoSnap();
271 bool const bWasSnapEnabled
= rView
.IsSnapEnabled();
273 // switch snapping off
275 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap();
277 rView
.SetSnapEnabled(false);
279 rView
.MovAction(aEndPoint
);
284 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap(bWasNoSnap
);
286 rView
.SetSnapEnabled(bWasSnapEnabled
);
289 // make moved handle visible
290 tools::Rectangle
aVisRect(aEndPoint
- Point(100, 100), Size(200, 200));
291 rView
.MakeVisible(aVisRect
, rWindow
);
297 ScrollAdaptor
* pScrollBar
= ( nX
!= 0 ) ? rParent
.GetHScroll() : rParent
.GetVScroll();
300 tools::Long nRangeMin
= pScrollBar
->GetRangeMin();
301 tools::Long nRangeMax
= pScrollBar
->GetRangeMax();
302 tools::Long nThumbPos
= pScrollBar
->GetThumbPos() + ( ( nX
!= 0 ) ? nX
: nY
) * pScrollBar
->GetLineSize();
303 if ( nThumbPos
< nRangeMin
)
304 nThumbPos
= nRangeMin
;
305 if ( nThumbPos
> nRangeMax
)
306 nThumbPos
= nRangeMax
;
307 pScrollBar
->SetThumbPos( nThumbPos
);
322 rWindow
.ReleaseMouse();
327 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor
& rParent_
) :
330 rParent
.GetView().SetCreateMode();
333 DlgEdFuncInsert::~DlgEdFuncInsert()
335 rParent
.GetView().SetEditMode();
338 void DlgEdFuncInsert::MouseButtonDown( const MouseEvent
& rMEvt
)
340 if( !rMEvt
.IsLeft() )
343 SdrView
& rView
= rParent
.GetView();
344 vcl::Window
& rWindow
= rParent
.GetWindow();
345 rView
.SetActualWin(rWindow
.GetOutDev());
347 Point aPos
= rWindow
.PixelToLogic( rMEvt
.GetPosPixel() );
348 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
349 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
351 rWindow
.CaptureMouse();
353 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
355 SdrHdl
* pHdl
= rView
.PickHandle(aPos
);
357 // if selected object was hit, drag object
358 if ( pHdl
!=nullptr || rView
.IsMarkedHit(aPos
, nHitLog
) )
359 rView
.BegDragObj(aPos
, nullptr, pHdl
, nDrgLog
);
360 else if ( rView
.GetMarkedObjectList().GetMarkCount() != 0 )
363 // if no action, create object
364 if ( !rView
.IsAction() )
365 rView
.BegCreateObj(aPos
);
367 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
369 // if object was hit, show property browser
370 if ( rView
.IsMarkedHit(aPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
371 rParent
.ShowProperties();
375 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent
& rMEvt
)
377 DlgEdFunc::MouseButtonUp( rMEvt
);
379 SdrView
& rView
= rParent
.GetView();
380 vcl::Window
& rWindow
= rParent
.GetWindow();
381 rView
.SetActualWin(rWindow
.GetOutDev());
383 rWindow
.ReleaseMouse();
385 // object creation active?
386 if ( rView
.IsCreateObj() )
388 rView
.EndCreateObj(SdrCreateCmd::ForceEnd
);
390 if ( rView
.GetMarkedObjectList().GetMarkCount() == 0 )
392 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
393 Point
aPos( rWindow
.PixelToLogic( rMEvt
.GetPosPixel() ) );
394 rView
.MarkObj(aPos
, nHitLog
);
397 return rView
.GetMarkedObjectList().GetMarkCount() != 0;
401 if ( rView
.IsDragObj() )
402 rView
.EndDragObj( rMEvt
.IsMod1() );
407 void DlgEdFuncInsert::MouseMove( const MouseEvent
& rMEvt
)
409 SdrView
& rView
= rParent
.GetView();
410 vcl::Window
& rWindow
= rParent
.GetWindow();
411 rView
.SetActualWin(rWindow
.GetOutDev());
413 Point aPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
414 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
416 if (rView
.IsAction())
419 rView
.MovAction(aPos
);
422 rWindow
.SetPointer( rView
.GetPreferredPointer( aPos
, rWindow
.GetOutDev(), nHitLog
) );
425 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor
& rParent_
) :
430 DlgEdFuncSelect::~DlgEdFuncSelect()
434 void DlgEdFuncSelect::MouseButtonDown( const MouseEvent
& rMEvt
)
436 // get view from parent
437 SdrView
& rView
= rParent
.GetView();
438 vcl::Window
& rWindow
= rParent
.GetWindow();
439 rView
.SetActualWin(rWindow
.GetOutDev());
441 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
442 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
443 Point aMDPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
445 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
447 SdrHdl
* pHdl
= rView
.PickHandle(aMDPos
);
449 // hit selected object?
450 if ( pHdl
!=nullptr || rView
.IsMarkedHit(aMDPos
, nHitLog
) )
452 rView
.BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
456 // if not multi selection, unmark all
457 if ( !rMEvt
.IsShift() )
462 SdrObject
* pObj
= rView
.PickObj(aMDPos
, nHitLog
, pPV
);
465 //if (dynamic_cast<DlgEdForm*>(pObj))
466 // rView.UnmarkAll();
468 // rParent.UnmarkDialog();
472 if ( rView
.MarkObj(aMDPos
, nHitLog
) )
475 pHdl
= rView
.PickHandle(aMDPos
);
476 rView
.BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
481 rView
.BegMarkObj(aMDPos
);
485 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
487 // if object was hit, show property browser
488 if ( rView
.IsMarkedHit(aMDPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
489 rParent
.ShowProperties();
493 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent
& rMEvt
)
495 DlgEdFunc::MouseButtonUp( rMEvt
);
497 // get view from parent
498 SdrView
& rView
= rParent
.GetView();
499 vcl::Window
& rWindow
= rParent
.GetWindow();
500 rView
.SetActualWin(rWindow
.GetOutDev());
502 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
503 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
505 if ( rMEvt
.IsLeft() )
507 if (rView
.IsDragObj())
509 // object was dragged
510 rView
.EndDragObj( rMEvt
.IsMod1() );
511 rView
.ForceMarkedToAnotherPage();
513 else if (rView
.IsAction())
519 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, rWindow
.GetOutDev(), nHitLog
) );
520 rWindow
.ReleaseMouse();
525 void DlgEdFuncSelect::MouseMove( const MouseEvent
& rMEvt
)
527 SdrView
& rView
= rParent
.GetView();
528 vcl::Window
& rWindow
= rParent
.GetWindow();
529 rView
.SetActualWin(rWindow
.GetOutDev());
531 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
532 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
534 if ( rView
.IsAction() )
536 Point aPix
= rMEvt
.GetPosPixel();
537 Point aPnt_
= rWindow
.PixelToLogic(aPix
);
540 rView
.MovAction(aPnt_
);
543 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, rWindow
.GetOutDev(), nHitLog
) );
546 } // namespace basctl
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */