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_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 Point aDefPoint
;
45 tools::Rectangle
aOutRect( aDefPoint
, rWindow
.GetOutputSizePixel() );
46 aOutRect
= rWindow
.PixelToLogic( aOutRect
);
48 ScrollBar
* pHScroll
= rParent
.GetHScroll();
49 ScrollBar
* pVScroll
= rParent
.GetVScroll();
50 long nDeltaX
= pHScroll
->GetLineSize();
51 long nDeltaY
= pVScroll
->GetLineSize();
53 if( !aOutRect
.IsInside( 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_
) :
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
.AreObjectsMarked() )
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
.AreObjectsMarked() )
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
.AreObjectsMarked() && !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
.IsInside( 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
);
262 if ( pHdl
&& ( nX
|| nY
) )
264 Point
aStartPoint( pHdl
->GetPos() );
265 Point
aEndPoint( pHdl
->GetPos() + Point( nX
, nY
) );
266 const SdrDragStat
& rDragStat
= rView
.GetDragStat();
269 rView
.BegDragObj( aStartPoint
, nullptr, pHdl
, 0 );
271 if ( rView
.IsDragObj() )
273 bool const bWasNoSnap
= rDragStat
.IsNoSnap();
274 bool const bWasSnapEnabled
= rView
.IsSnapEnabled();
276 // switch snapping off
278 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap();
279 if ( bWasSnapEnabled
)
280 rView
.SetSnapEnabled(false);
282 rView
.MovAction( aEndPoint
);
287 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap( bWasNoSnap
);
288 if ( bWasSnapEnabled
)
289 rView
.SetSnapEnabled( bWasSnapEnabled
);
292 // make moved handle visible
293 tools::Rectangle
aVisRect( aEndPoint
- Point( 100, 100 ), Size( 200, 200 ) );
294 rView
.MakeVisible( aVisRect
, rWindow
);
301 ScrollBar
* pScrollBar
= ( nX
!= 0 ) ? rParent
.GetHScroll() : rParent
.GetVScroll();
304 long nRangeMin
= pScrollBar
->GetRangeMin();
305 long nRangeMax
= pScrollBar
->GetRangeMax();
306 long nThumbPos
= pScrollBar
->GetThumbPos() + ( ( nX
!= 0 ) ? nX
: nY
) * pScrollBar
->GetLineSize();
307 if ( nThumbPos
< nRangeMin
)
308 nThumbPos
= nRangeMin
;
309 if ( nThumbPos
> nRangeMax
)
310 nThumbPos
= nRangeMax
;
311 pScrollBar
->SetThumbPos( nThumbPos
);
326 rWindow
.ReleaseMouse();
331 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor
& rParent_
) :
334 rParent
.GetView().SetCreateMode();
337 DlgEdFuncInsert::~DlgEdFuncInsert()
339 rParent
.GetView().SetEditMode();
342 void DlgEdFuncInsert::MouseButtonDown( const MouseEvent
& rMEvt
)
344 if( !rMEvt
.IsLeft() )
347 SdrView
& rView
= rParent
.GetView();
348 vcl::Window
& rWindow
= rParent
.GetWindow();
349 rView
.SetActualWin(&rWindow
);
351 Point aPos
= rWindow
.PixelToLogic( rMEvt
.GetPosPixel() );
352 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
353 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
355 rWindow
.CaptureMouse();
357 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
359 SdrHdl
* pHdl
= rView
.PickHandle(aPos
);
361 // if selected object was hit, drag object
362 if ( pHdl
!=nullptr || rView
.IsMarkedHit(aPos
, nHitLog
) )
363 rView
.BegDragObj(aPos
, nullptr, pHdl
, nDrgLog
);
364 else if ( rView
.AreObjectsMarked() )
367 // if no action, create object
368 if ( !rView
.IsAction() )
369 rView
.BegCreateObj(aPos
);
371 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
373 // if object was hit, show property browser
374 if ( rView
.IsMarkedHit(aPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
375 rParent
.ShowProperties();
379 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent
& rMEvt
)
381 DlgEdFunc::MouseButtonUp( rMEvt
);
383 SdrView
& rView
= rParent
.GetView();
384 vcl::Window
& rWindow
= rParent
.GetWindow();
385 rView
.SetActualWin(&rWindow
);
387 rWindow
.ReleaseMouse();
389 // object creation active?
390 if ( rView
.IsCreateObj() )
392 rView
.EndCreateObj(SdrCreateCmd::ForceEnd
);
394 if ( !rView
.AreObjectsMarked() )
396 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
397 Point
aPos( rWindow
.PixelToLogic( rMEvt
.GetPosPixel() ) );
398 rView
.MarkObj(aPos
, nHitLog
);
401 return rView
.AreObjectsMarked();
405 if ( rView
.IsDragObj() )
406 rView
.EndDragObj( rMEvt
.IsMod1() );
411 void DlgEdFuncInsert::MouseMove( const MouseEvent
& rMEvt
)
413 SdrView
& rView
= rParent
.GetView();
414 vcl::Window
& rWindow
= rParent
.GetWindow();
415 rView
.SetActualWin(&rWindow
);
417 Point aPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
418 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
420 if (rView
.IsAction())
423 rView
.MovAction(aPos
);
426 rWindow
.SetPointer( rView
.GetPreferredPointer( aPos
, &rWindow
, nHitLog
) );
429 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor
& rParent_
) :
434 DlgEdFuncSelect::~DlgEdFuncSelect()
438 void DlgEdFuncSelect::MouseButtonDown( const MouseEvent
& rMEvt
)
440 // get view from parent
441 SdrView
& rView
= rParent
.GetView();
442 vcl::Window
& rWindow
= rParent
.GetWindow();
443 rView
.SetActualWin(&rWindow
);
445 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
446 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
447 Point aMDPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
449 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
451 SdrHdl
* pHdl
= rView
.PickHandle(aMDPos
);
453 // hit selected object?
454 if ( pHdl
!=nullptr || rView
.IsMarkedHit(aMDPos
, nHitLog
) )
456 rView
.BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
460 // if not multi selection, unmark all
461 if ( !rMEvt
.IsShift() )
466 SdrObject
* pObj
= rView
.PickObj(aMDPos
, nHitLog
, pPV
);
469 //if (dynamic_cast<DlgEdForm*>(pObj))
470 // rView.UnmarkAll();
472 // rParent.UnmarkDialog();
476 if ( rView
.MarkObj(aMDPos
, nHitLog
) )
479 pHdl
= rView
.PickHandle(aMDPos
);
480 rView
.BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
485 rView
.BegMarkObj(aMDPos
);
489 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
491 // if object was hit, show property browser
492 if ( rView
.IsMarkedHit(aMDPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
493 rParent
.ShowProperties();
497 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent
& rMEvt
)
499 DlgEdFunc::MouseButtonUp( rMEvt
);
501 // get view from parent
502 SdrView
& rView
= rParent
.GetView();
503 vcl::Window
& rWindow
= rParent
.GetWindow();
504 rView
.SetActualWin(&rWindow
);
506 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
507 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
509 if ( rMEvt
.IsLeft() )
511 if (rView
.IsDragObj())
513 // object was dragged
514 rView
.EndDragObj( rMEvt
.IsMod1() );
515 rView
.ForceMarkedToAnotherPage();
517 else if (rView
.IsAction())
523 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
524 rWindow
.ReleaseMouse();
529 void DlgEdFuncSelect::MouseMove( const MouseEvent
& rMEvt
)
531 SdrView
& rView
= rParent
.GetView();
532 vcl::Window
& rWindow
= rParent
.GetWindow();
533 rView
.SetActualWin(&rWindow
);
535 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
536 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
538 if ( rView
.IsAction() )
540 Point aPix
= rMEvt
.GetPosPixel();
541 Point aPnt_
= rWindow
.PixelToLogic(aPix
);
544 rView
.MovAction(aPnt_
);
547 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
550 } // namespace basctl
552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */