Branch libreoffice-5-0-4
[LibreOffice.git] / basctl / source / dlged / dlgedfunc.cxx
blob3840ba98390ed2dcba2405e7e18d3e451ff0b7e8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "dlged.hxx"
24 #include "dlgedview.hxx"
25 #include <vcl/seleng.hxx>
27 namespace basctl
30 IMPL_LINK_TYPED( DlgEdFunc, ScrollTimeout, Timer *, pTimer, void )
32 (void)pTimer;
33 vcl::Window& rWindow = rParent.GetWindow();
34 Point aPos = rWindow.ScreenToOutputPixel( rWindow.GetPointerPosPixel() );
35 aPos = rWindow.PixelToLogic( aPos );
36 ForceScroll( aPos );
39 void DlgEdFunc::ForceScroll( const Point& rPos )
41 aScrollTimer.Stop();
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() )
57 nDeltaX = -nDeltaX;
58 else if( rPos.X() <= aOutRect.Right() )
59 nDeltaX = 0;
61 if( rPos.Y() < aOutRect.Top() )
62 nDeltaY = -nDeltaY;
63 else if( rPos.Y() <= aOutRect.Bottom() )
64 nDeltaY = 0;
66 if( nDeltaX )
67 pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
68 if( nDeltaY )
69 pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
71 if( nDeltaX )
72 rParent.DoScroll( pHScroll );
73 if( nDeltaY )
74 rParent.DoScroll( pVScroll );
77 aScrollTimer.Start();
80 DlgEdFunc::DlgEdFunc (DlgEditor& rParent_) :
81 rParent(rParent_)
83 aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
84 aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
87 DlgEdFunc::~DlgEdFunc()
91 bool DlgEdFunc::MouseButtonDown( const MouseEvent& )
93 return true;
96 bool DlgEdFunc::MouseButtonUp( const MouseEvent& )
98 aScrollTimer.Stop();
99 return true;
102 bool DlgEdFunc::MouseMove( const MouseEvent& )
104 return true;
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();
117 switch ( nCode )
119 case KEY_ESCAPE:
121 if ( rView.IsAction() )
123 rView.BrkAction();
124 bReturn = true;
126 else if ( rView.AreObjectsMarked() )
128 const SdrHdlList& rHdlList = rView.GetHdlList();
129 SdrHdl* pHdl = rHdlList.GetFocusHdl();
130 if ( pHdl )
131 const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
132 else
133 rView.UnmarkAll();
135 bReturn = true;
138 break;
139 case KEY_TAB:
141 if ( !aCode.IsMod1() && !aCode.IsMod2() )
143 // mark next object
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 );
154 bReturn = true;
156 else if ( aCode.IsMod1() )
158 // selected handle
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 );
170 bReturn = true;
173 break;
174 case KEY_UP:
175 case KEY_DOWN:
176 case KEY_LEFT:
177 case KEY_RIGHT:
179 long nX = 0;
180 long nY = 0;
182 if ( nCode == KEY_UP )
184 // scroll up
185 nX = 0;
186 nY = -1;
188 else if ( nCode == KEY_DOWN )
190 // scroll down
191 nX = 0;
192 nY = 1;
194 else if ( nCode == KEY_LEFT )
196 // scroll left
197 nX = -1;
198 nY = 0;
200 else if ( nCode == KEY_RIGHT )
202 // scroll right
203 nX = 1;
204 nY = 0;
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();
216 else
218 // move in 1 mm distance
219 nX *= 100;
220 nY *= 100;
223 const SdrHdlList& rHdlList = rView.GetHdlList();
224 SdrHdl* pHdl = rHdlList.GetFocusHdl();
226 if ( pHdl == 0 )
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 );
262 else
264 // move the handle
265 if ( pHdl && ( nX || nY ) )
267 Point aStartPoint( pHdl->GetPos() );
268 Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
269 const SdrDragStat& rDragStat = rView.GetDragStat();
271 // start dragging
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
280 if ( !bWasNoSnap )
281 const_cast<SdrDragStat&>(rDragStat).SetNoSnap(true);
282 if ( bWasSnapEnabled )
283 rView.SetSnapEnabled(false);
285 rView.MovAction( aEndPoint );
286 rView.EndDragObj();
288 // restore snap
289 if ( !bWasNoSnap )
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 );
301 else
303 // scroll page
304 ScrollBar* pScrollBar = ( nX != 0 ) ? rParent.GetHScroll() : rParent.GetVScroll();
305 if ( pScrollBar )
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 );
319 bReturn = true;
321 break;
322 default:
325 break;
328 if ( bReturn )
329 rWindow.ReleaseMouse();
331 return bReturn;
334 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor& rParent_) :
335 DlgEdFunc(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() )
348 return true;
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() )
368 rView.UnmarkAll();
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();
381 return true;
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();
408 else
410 if ( rView.IsDragObj() )
411 rView.EndDragObj( rMEvt.IsMod1() );
412 return true;
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())
427 ForceScroll(aPos);
428 rView.MovAction(aPos);
431 rWindow.SetPointer( rView.GetPreferredPointer( aPos, &rWindow, nHitLog ) );
433 return true;
436 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor& rParent_) :
437 DlgEdFunc(rParent_),
438 bMarkAction(false)
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);
466 else
468 // if not multi selection, unmark all
469 if ( !rMEvt.IsShift() )
470 rView.UnmarkAll();
471 else
473 SdrObject* pObj;
474 SdrPageView* pPV;
475 if( rView.PickObj( aMDPos, nHitLog, pObj, pPV ) )
477 //if (dynamic_cast<DlgEdForm*>(pObj))
478 // rView.UnmarkAll();
479 //else
480 // rParent.UnmarkDialog();
484 if ( rView.MarkObj(aMDPos, nHitLog) )
486 // drag object
487 pHdl = rView.PickHandle(aMDPos);
488 rView.BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
490 else
492 // select object
493 rView.BegMarkObj(aMDPos);
494 bMarkAction = true;
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();
505 return true;
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())
530 rView.EndAction();
534 bMarkAction = false;
536 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
537 rWindow.ReleaseMouse();
539 return true;
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);
556 ForceScroll(aPnt_);
557 rView.MovAction(aPnt_);
560 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
562 return true;
565 } // namespace basctl
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */