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_TYPED( DlgEdFunc
, ScrollTimeout
, Timer
*, pTimer
, void )
33 vcl::Window
& rWindow
= rParent
.GetWindow();
34 Point aPos
= rWindow
.ScreenToOutputPixel( rWindow
.GetPointerPosPixel() );
35 aPos
= rWindow
.PixelToLogic( aPos
);
39 void DlgEdFunc::ForceScroll( const Point
& rPos
)
43 vcl::Window
& rWindow
= rParent
.GetWindow();
45 static Point aDefPoint
;
46 Rectangle
aOutRect( aDefPoint
, rWindow
.GetOutputSizePixel() );
47 aOutRect
= rWindow
.PixelToLogic( aOutRect
);
49 ScrollBar
* pHScroll
= rParent
.GetHScroll();
50 ScrollBar
* pVScroll
= rParent
.GetVScroll();
51 long nDeltaX
= pHScroll
->GetLineSize();
52 long nDeltaY
= pVScroll
->GetLineSize();
54 if( !aOutRect
.IsInside( rPos
) )
56 if( rPos
.X() < aOutRect
.Left() )
58 else if( rPos
.X() <= aOutRect
.Right() )
61 if( rPos
.Y() < aOutRect
.Top() )
63 else if( rPos
.Y() <= aOutRect
.Bottom() )
67 pHScroll
->SetThumbPos( pHScroll
->GetThumbPos() + nDeltaX
);
69 pVScroll
->SetThumbPos( pVScroll
->GetThumbPos() + nDeltaY
);
72 rParent
.DoScroll( pHScroll
);
74 rParent
.DoScroll( pVScroll
);
80 DlgEdFunc::DlgEdFunc (DlgEditor
& rParent_
) :
83 aScrollTimer
.SetTimeoutHdl( LINK( this, DlgEdFunc
, ScrollTimeout
) );
84 aScrollTimer
.SetTimeout( SELENG_AUTOREPEAT_INTERVAL
);
87 DlgEdFunc::~DlgEdFunc()
91 bool DlgEdFunc::MouseButtonDown( const MouseEvent
& )
96 bool DlgEdFunc::MouseButtonUp( const MouseEvent
& )
102 bool DlgEdFunc::MouseMove( const MouseEvent
& )
107 bool DlgEdFunc::KeyInput( const KeyEvent
& rKEvt
)
109 bool bReturn
= false;
111 SdrView
& rView
= rParent
.GetView();
112 vcl::Window
& rWindow
= rParent
.GetWindow();
114 vcl::KeyCode aCode
= rKEvt
.GetKeyCode();
115 sal_uInt16 nCode
= aCode
.GetCode();
121 if ( rView
.IsAction() )
126 else if ( rView
.AreObjectsMarked() )
128 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
129 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
131 const_cast<SdrHdlList
&>(rHdlList
).ResetFocusHdl();
141 if ( !aCode
.IsMod1() && !aCode
.IsMod2() )
144 if ( !rView
.MarkNextObj( !aCode
.IsShift() ) )
146 // if no next object, mark first/last
147 rView
.UnmarkAllObj();
148 rView
.MarkNextObj( !aCode
.IsShift() );
151 if ( rView
.AreObjectsMarked() )
152 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
156 else if ( aCode
.IsMod1() )
159 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
160 const_cast<SdrHdlList
&>(rHdlList
).TravelFocusHdl( !aCode
.IsShift() );
162 // guarantee visibility of focused handle
163 if (SdrHdl
* pHdl
= rHdlList
.GetFocusHdl())
165 Point
aHdlPosition( pHdl
->GetPos() );
166 Rectangle
aVisRect( aHdlPosition
- Point( 100, 100 ), Size( 200, 200 ) );
167 rView
.MakeVisible( aVisRect
, rWindow
);
182 if ( nCode
== KEY_UP
)
188 else if ( nCode
== KEY_DOWN
)
194 else if ( nCode
== KEY_LEFT
)
200 else if ( nCode
== KEY_RIGHT
)
207 if ( rView
.AreObjectsMarked() && !aCode
.IsMod1() )
209 if ( aCode
.IsMod2() )
211 // move in 1 pixel distance
212 Size aPixelSize
= rWindow
.PixelToLogic(Size(1, 1));
213 nX
*= aPixelSize
.Width();
214 nY
*= aPixelSize
.Height();
218 // move in 1 mm distance
223 const SdrHdlList
& rHdlList
= rView
.GetHdlList();
224 SdrHdl
* pHdl
= rHdlList
.GetFocusHdl();
228 // no handle selected
229 if ( rView
.IsMoveAllowed() )
231 // restrict movement to work area
232 const Rectangle
& rWorkArea
= rView
.GetWorkArea();
234 if ( !rWorkArea
.IsEmpty() )
236 Rectangle
aMarkRect( rView
.GetMarkedObjRect() );
237 aMarkRect
.Move( nX
, nY
);
239 if ( !rWorkArea
.IsInside( aMarkRect
) )
241 if ( aMarkRect
.Left() < rWorkArea
.Left() )
242 nX
+= rWorkArea
.Left() - aMarkRect
.Left();
244 if ( aMarkRect
.Right() > rWorkArea
.Right() )
245 nX
-= aMarkRect
.Right() - rWorkArea
.Right();
247 if ( aMarkRect
.Top() < rWorkArea
.Top() )
248 nY
+= rWorkArea
.Top() - aMarkRect
.Top();
250 if ( aMarkRect
.Bottom() > rWorkArea
.Bottom() )
251 nY
-= aMarkRect
.Bottom() - rWorkArea
.Bottom();
255 if ( nX
!= 0 || nY
!= 0 )
257 rView
.MoveAllMarked( Size( nX
, nY
) );
258 rView
.MakeVisible( rView
.GetAllMarkedRect(), rWindow
);
265 if ( pHdl
&& ( nX
|| nY
) )
267 Point
aStartPoint( pHdl
->GetPos() );
268 Point
aEndPoint( pHdl
->GetPos() + Point( nX
, nY
) );
269 const SdrDragStat
& rDragStat
= rView
.GetDragStat();
272 rView
.BegDragObj( aStartPoint
, 0, pHdl
, 0 );
274 if ( rView
.IsDragObj() )
276 bool const bWasNoSnap
= rDragStat
.IsNoSnap();
277 bool const bWasSnapEnabled
= rView
.IsSnapEnabled();
279 // switch snapping off
281 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap(true);
282 if ( bWasSnapEnabled
)
283 rView
.SetSnapEnabled(false);
285 rView
.MovAction( aEndPoint
);
290 const_cast<SdrDragStat
&>(rDragStat
).SetNoSnap( bWasNoSnap
);
291 if ( bWasSnapEnabled
)
292 rView
.SetSnapEnabled( bWasSnapEnabled
);
295 // make moved handle visible
296 Rectangle
aVisRect( aEndPoint
- Point( 100, 100 ), Size( 200, 200 ) );
297 rView
.MakeVisible( aVisRect
, rWindow
);
304 ScrollBar
* pScrollBar
= ( nX
!= 0 ) ? rParent
.GetHScroll() : rParent
.GetVScroll();
307 long nRangeMin
= pScrollBar
->GetRangeMin();
308 long nRangeMax
= pScrollBar
->GetRangeMax();
309 long nThumbPos
= pScrollBar
->GetThumbPos() + ( ( nX
!= 0 ) ? nX
: nY
) * pScrollBar
->GetLineSize();
310 if ( nThumbPos
< nRangeMin
)
311 nThumbPos
= nRangeMin
;
312 if ( nThumbPos
> nRangeMax
)
313 nThumbPos
= nRangeMax
;
314 pScrollBar
->SetThumbPos( nThumbPos
);
315 rParent
.DoScroll( pScrollBar
);
329 rWindow
.ReleaseMouse();
334 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor
& rParent_
) :
337 rParent
.GetView().SetCreateMode(true);
340 DlgEdFuncInsert::~DlgEdFuncInsert()
342 rParent
.GetView().SetEditMode( true );
345 bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent
& rMEvt
)
347 if( !rMEvt
.IsLeft() )
350 SdrView
& rView
= rParent
.GetView();
351 vcl::Window
& rWindow
= rParent
.GetWindow();
352 rView
.SetActualWin(&rWindow
);
354 Point aPos
= rWindow
.PixelToLogic( rMEvt
.GetPosPixel() );
355 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
356 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
358 rWindow
.CaptureMouse();
360 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
362 SdrHdl
* pHdl
= rView
.PickHandle(aPos
);
364 // if selected object was hit, drag object
365 if ( pHdl
!=NULL
|| rView
.IsMarkedHit(aPos
, nHitLog
) )
366 rView
.BegDragObj(aPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
367 else if ( rView
.AreObjectsMarked() )
370 // if no action, create object
371 if ( !rView
.IsAction() )
372 rView
.BegCreateObj(aPos
);
374 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
376 // if object was hit, show property browser
377 if ( rView
.IsMarkedHit(aPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
378 rParent
.ShowProperties();
384 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent
& rMEvt
)
386 DlgEdFunc::MouseButtonUp( rMEvt
);
388 SdrView
& rView
= rParent
.GetView();
389 vcl::Window
& rWindow
= rParent
.GetWindow();
390 rView
.SetActualWin(&rWindow
);
392 rWindow
.ReleaseMouse();
394 // object creation active?
395 if ( rView
.IsCreateObj() )
397 rView
.EndCreateObj(SDRCREATE_FORCEEND
);
399 if ( !rView
.AreObjectsMarked() )
401 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
402 Point
aPos( rWindow
.PixelToLogic( rMEvt
.GetPosPixel() ) );
403 rView
.MarkObj(aPos
, nHitLog
);
406 return rView
.AreObjectsMarked();
410 if ( rView
.IsDragObj() )
411 rView
.EndDragObj( rMEvt
.IsMod1() );
416 bool DlgEdFuncInsert::MouseMove( const MouseEvent
& rMEvt
)
418 SdrView
& rView
= rParent
.GetView();
419 vcl::Window
& rWindow
= rParent
.GetWindow();
420 rView
.SetActualWin(&rWindow
);
422 Point aPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
423 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
425 if (rView
.IsAction())
428 rView
.MovAction(aPos
);
431 rWindow
.SetPointer( rView
.GetPreferredPointer( aPos
, &rWindow
, nHitLog
) );
436 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor
& rParent_
) :
442 DlgEdFuncSelect::~DlgEdFuncSelect()
446 bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent
& rMEvt
)
448 // get view from parent
449 SdrView
& rView
= rParent
.GetView();
450 vcl::Window
& rWindow
= rParent
.GetWindow();
451 rView
.SetActualWin(&rWindow
);
453 sal_uInt16 nDrgLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
454 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
455 Point aMDPos
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
457 if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 )
459 SdrHdl
* pHdl
= rView
.PickHandle(aMDPos
);
461 // hit selected object?
462 if ( pHdl
!=NULL
|| rView
.IsMarkedHit(aMDPos
, nHitLog
) )
464 rView
.BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
468 // if not multi selection, unmark all
469 if ( !rMEvt
.IsShift() )
475 if( rView
.PickObj( aMDPos
, nHitLog
, pObj
, pPV
) )
477 //if (dynamic_cast<DlgEdForm*>(pObj))
478 // rView.UnmarkAll();
480 // rParent.UnmarkDialog();
484 if ( rView
.MarkObj(aMDPos
, nHitLog
) )
487 pHdl
= rView
.PickHandle(aMDPos
);
488 rView
.BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
493 rView
.BegMarkObj(aMDPos
);
498 else if ( rMEvt
.IsLeft() && rMEvt
.GetClicks() == 2 )
500 // if object was hit, show property browser
501 if ( rView
.IsMarkedHit(aMDPos
, nHitLog
) && rParent
.GetMode() != DlgEditor::READONLY
)
502 rParent
.ShowProperties();
508 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent
& rMEvt
)
510 DlgEdFunc::MouseButtonUp( rMEvt
);
512 // get view from parent
513 SdrView
& rView
= rParent
.GetView();
514 vcl::Window
& rWindow
= rParent
.GetWindow();
515 rView
.SetActualWin(&rWindow
);
517 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
518 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
520 if ( rMEvt
.IsLeft() )
522 if (rView
.IsDragObj())
524 // object was dragged
525 rView
.EndDragObj( rMEvt
.IsMod1() );
526 rView
.ForceMarkedToAnotherPage();
528 else if (rView
.IsAction())
536 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
537 rWindow
.ReleaseMouse();
542 bool DlgEdFuncSelect::MouseMove( const MouseEvent
& rMEvt
)
544 SdrView
& rView
= rParent
.GetView();
545 vcl::Window
& rWindow
= rParent
.GetWindow();
546 rView
.SetActualWin(&rWindow
);
548 Point aPnt
= rWindow
.PixelToLogic(rMEvt
.GetPosPixel());
549 sal_uInt16 nHitLog
= static_cast<sal_uInt16
>(rWindow
.PixelToLogic(Size(3, 0)).Width());
551 if ( rView
.IsAction() )
553 Point aPix
= rMEvt
.GetPosPixel();
554 Point aPnt_
= rWindow
.PixelToLogic(aPix
);
557 rView
.MovAction(aPnt_
);
560 rWindow
.SetPointer( rView
.GetPreferredPointer( aPnt
, &rWindow
, nHitLog
) );
565 } // namespace basctl
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */