Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / basctl / source / dlged / dlgedfunc.cxx
blob665bd7c147d3b532c207156ed8152d1faeaf6f98
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_NOARG( DlgEdFunc, ScrollTimeout, Timer *, void )
32 vcl::Window& rWindow = rParent.GetWindow();
33 Point aPos = rWindow.ScreenToOutputPixel( rWindow.GetPointerPosPixel() );
34 aPos = rWindow.PixelToLogic( aPos );
35 ForceScroll( aPos );
38 void DlgEdFunc::ForceScroll( const Point& rPos )
40 aScrollTimer.Stop();
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() )
56 nDeltaX = -nDeltaX;
57 else if( rPos.X() <= aOutRect.Right() )
58 nDeltaX = 0;
60 if( rPos.Y() < aOutRect.Top() )
61 nDeltaY = -nDeltaY;
62 else if( rPos.Y() <= aOutRect.Bottom() )
63 nDeltaY = 0;
65 if( nDeltaX )
66 pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
67 if( nDeltaY )
68 pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
70 if( nDeltaX )
71 rParent.DoScroll();
72 if( nDeltaY )
73 rParent.DoScroll();
76 aScrollTimer.Start();
79 DlgEdFunc::DlgEdFunc (DlgEditor& rParent_) :
80 rParent(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& )
96 aScrollTimer.Stop();
97 return true;
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();
114 switch ( nCode )
116 case KEY_ESCAPE:
118 if ( rView.IsAction() )
120 rView.BrkAction();
121 bReturn = true;
123 else if ( rView.AreObjectsMarked() )
125 const SdrHdlList& rHdlList = rView.GetHdlList();
126 SdrHdl* pHdl = rHdlList.GetFocusHdl();
127 if ( pHdl )
128 const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
129 else
130 rView.UnmarkAll();
132 bReturn = true;
135 break;
136 case KEY_TAB:
138 if ( !aCode.IsMod1() && !aCode.IsMod2() )
140 // mark next object
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 );
151 bReturn = true;
153 else if ( aCode.IsMod1() )
155 // selected handle
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 );
167 bReturn = true;
170 break;
171 case KEY_UP:
172 case KEY_DOWN:
173 case KEY_LEFT:
174 case KEY_RIGHT:
176 long nX = 0;
177 long nY = 0;
179 if ( nCode == KEY_UP )
181 // scroll up
182 nX = 0;
183 nY = -1;
185 else if ( nCode == KEY_DOWN )
187 // scroll down
188 nX = 0;
189 nY = 1;
191 else if ( nCode == KEY_LEFT )
193 // scroll left
194 nX = -1;
195 nY = 0;
197 else if ( nCode == KEY_RIGHT )
199 // scroll right
200 nX = 1;
201 nY = 0;
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();
213 else
215 // move in 1 mm distance
216 nX *= 100;
217 nY *= 100;
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 );
259 else
261 // move the handle
262 if ( pHdl && ( nX || nY ) )
264 Point aStartPoint( pHdl->GetPos() );
265 Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
266 const SdrDragStat& rDragStat = rView.GetDragStat();
268 // start dragging
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
277 if ( !bWasNoSnap )
278 const_cast<SdrDragStat&>(rDragStat).SetNoSnap();
279 if ( bWasSnapEnabled )
280 rView.SetSnapEnabled(false);
282 rView.MovAction( aEndPoint );
283 rView.EndDragObj();
285 // restore snap
286 if ( !bWasNoSnap )
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 );
298 else
300 // scroll page
301 ScrollBar* pScrollBar = ( nX != 0 ) ? rParent.GetHScroll() : rParent.GetVScroll();
302 if ( pScrollBar )
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 );
312 rParent.DoScroll();
316 bReturn = true;
318 break;
319 default:
322 break;
325 if ( bReturn )
326 rWindow.ReleaseMouse();
328 return bReturn;
331 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor& rParent_) :
332 DlgEdFunc(rParent_)
334 rParent.GetView().SetCreateMode();
337 DlgEdFuncInsert::~DlgEdFuncInsert()
339 rParent.GetView().SetEditMode();
342 void DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
344 if( !rMEvt.IsLeft() )
345 return;
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() )
365 rView.UnmarkAll();
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();
403 else
405 if ( rView.IsDragObj() )
406 rView.EndDragObj( rMEvt.IsMod1() );
407 return true;
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())
422 ForceScroll(aPos);
423 rView.MovAction(aPos);
426 rWindow.SetPointer( rView.GetPreferredPointer( aPos, &rWindow, nHitLog ) );
429 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor& rParent_) :
430 DlgEdFunc(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);
458 else
460 // if not multi selection, unmark all
461 if ( !rMEvt.IsShift() )
462 rView.UnmarkAll();
463 else
465 SdrPageView* pPV;
466 SdrObject* pObj = rView.PickObj(aMDPos, nHitLog, pPV);
467 if (pObj)
469 //if (dynamic_cast<DlgEdForm*>(pObj))
470 // rView.UnmarkAll();
471 //else
472 // rParent.UnmarkDialog();
476 if ( rView.MarkObj(aMDPos, nHitLog) )
478 // drag object
479 pHdl = rView.PickHandle(aMDPos);
480 rView.BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
482 else
484 // select object
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())
519 rView.EndAction();
523 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
524 rWindow.ReleaseMouse();
526 return true;
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);
543 ForceScroll(aPnt_);
544 rView.MovAction(aPnt_);
547 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
550 } // namespace basctl
552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */