Bump version to 4.3-4
[LibreOffice.git] / basctl / source / dlged / dlgedfunc.cxx
blobf5f2c4137b998c73a11326a9ebfd2aba51cd2625
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_INLINE_START( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
32 (void)pTimer;
33 Window& rWindow = rParent.GetWindow();
34 Point aPos = rWindow.ScreenToOutputPixel( rWindow.GetPointerPosPixel() );
35 aPos = rWindow.PixelToLogic( aPos );
36 ForceScroll( aPos );
37 return 0;
39 IMPL_LINK_INLINE_END( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
41 void DlgEdFunc::ForceScroll( const Point& rPos )
43 aScrollTimer.Stop();
45 Window& rWindow = rParent.GetWindow();
47 static Point aDefPoint;
48 Rectangle aOutRect( aDefPoint, rWindow.GetOutputSizePixel() );
49 aOutRect = rWindow.PixelToLogic( aOutRect );
51 ScrollBar* pHScroll = rParent.GetHScroll();
52 ScrollBar* pVScroll = rParent.GetVScroll();
53 long nDeltaX = pHScroll->GetLineSize();
54 long nDeltaY = pVScroll->GetLineSize();
56 if( !aOutRect.IsInside( rPos ) )
58 if( rPos.X() < aOutRect.Left() )
59 nDeltaX = -nDeltaX;
60 else if( rPos.X() <= aOutRect.Right() )
61 nDeltaX = 0;
63 if( rPos.Y() < aOutRect.Top() )
64 nDeltaY = -nDeltaY;
65 else if( rPos.Y() <= aOutRect.Bottom() )
66 nDeltaY = 0;
68 if( nDeltaX )
69 pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
70 if( nDeltaY )
71 pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
73 if( nDeltaX )
74 rParent.DoScroll( pHScroll );
75 if( nDeltaY )
76 rParent.DoScroll( pVScroll );
79 aScrollTimer.Start();
82 DlgEdFunc::DlgEdFunc (DlgEditor& rParent_) :
83 rParent(rParent_)
85 aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
86 aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
89 DlgEdFunc::~DlgEdFunc()
93 bool DlgEdFunc::MouseButtonDown( const MouseEvent& )
95 return true;
98 bool DlgEdFunc::MouseButtonUp( const MouseEvent& )
100 aScrollTimer.Stop();
101 return true;
104 bool DlgEdFunc::MouseMove( const MouseEvent& )
106 return true;
109 bool DlgEdFunc::KeyInput( const KeyEvent& rKEvt )
111 bool bReturn = false;
113 SdrView& rView = rParent.GetView();
114 Window& rWindow = rParent.GetWindow();
116 KeyCode aCode = rKEvt.GetKeyCode();
117 sal_uInt16 nCode = aCode.GetCode();
119 switch ( nCode )
121 case KEY_ESCAPE:
123 if ( rView.IsAction() )
125 rView.BrkAction();
126 bReturn = true;
128 else if ( rView.AreObjectsMarked() )
130 const SdrHdlList& rHdlList = rView.GetHdlList();
131 SdrHdl* pHdl = rHdlList.GetFocusHdl();
132 if ( pHdl )
133 const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
134 else
135 rView.UnmarkAll();
137 bReturn = true;
140 break;
141 case KEY_TAB:
143 if ( !aCode.IsMod1() && !aCode.IsMod2() )
145 // mark next object
146 if ( !rView.MarkNextObj( !aCode.IsShift() ) )
148 // if no next object, mark first/last
149 rView.UnmarkAllObj();
150 rView.MarkNextObj( !aCode.IsShift() );
153 if ( rView.AreObjectsMarked() )
154 rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
156 bReturn = true;
158 else if ( aCode.IsMod1() )
160 // selected handle
161 const SdrHdlList& rHdlList = rView.GetHdlList();
162 const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl( !aCode.IsShift() );
164 // guarantee visibility of focused handle
165 if (SdrHdl* pHdl = rHdlList.GetFocusHdl())
167 Point aHdlPosition( pHdl->GetPos() );
168 Rectangle aVisRect( aHdlPosition - Point( 100, 100 ), Size( 200, 200 ) );
169 rView.MakeVisible( aVisRect, rWindow );
172 bReturn = true;
175 break;
176 case KEY_UP:
177 case KEY_DOWN:
178 case KEY_LEFT:
179 case KEY_RIGHT:
181 long nX = 0;
182 long nY = 0;
184 if ( nCode == KEY_UP )
186 // scroll up
187 nX = 0;
188 nY = -1;
190 else if ( nCode == KEY_DOWN )
192 // scroll down
193 nX = 0;
194 nY = 1;
196 else if ( nCode == KEY_LEFT )
198 // scroll left
199 nX = -1;
200 nY = 0;
202 else if ( nCode == KEY_RIGHT )
204 // scroll right
205 nX = 1;
206 nY = 0;
209 if ( rView.AreObjectsMarked() && !aCode.IsMod1() )
211 if ( aCode.IsMod2() )
213 // move in 1 pixel distance
214 Size aPixelSize = rWindow.PixelToLogic(Size(1, 1));
215 nX *= aPixelSize.Width();
216 nY *= aPixelSize.Height();
218 else
220 // move in 1 mm distance
221 nX *= 100;
222 nY *= 100;
225 const SdrHdlList& rHdlList = rView.GetHdlList();
226 SdrHdl* pHdl = rHdlList.GetFocusHdl();
228 if ( pHdl == 0 )
230 // no handle selected
231 if ( rView.IsMoveAllowed() )
233 // restrict movement to work area
234 const Rectangle& rWorkArea = rView.GetWorkArea();
236 if ( !rWorkArea.IsEmpty() )
238 Rectangle aMarkRect( rView.GetMarkedObjRect() );
239 aMarkRect.Move( nX, nY );
241 if ( !rWorkArea.IsInside( aMarkRect ) )
243 if ( aMarkRect.Left() < rWorkArea.Left() )
244 nX += rWorkArea.Left() - aMarkRect.Left();
246 if ( aMarkRect.Right() > rWorkArea.Right() )
247 nX -= aMarkRect.Right() - rWorkArea.Right();
249 if ( aMarkRect.Top() < rWorkArea.Top() )
250 nY += rWorkArea.Top() - aMarkRect.Top();
252 if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
253 nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
257 if ( nX != 0 || nY != 0 )
259 rView.MoveAllMarked( Size( nX, nY ) );
260 rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
264 else
266 // move the handle
267 if ( pHdl && ( nX || nY ) )
269 Point aStartPoint( pHdl->GetPos() );
270 Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
271 const SdrDragStat& rDragStat = rView.GetDragStat();
273 // start dragging
274 rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
276 if ( rView.IsDragObj() )
278 bool const bWasNoSnap = rDragStat.IsNoSnap();
279 bool const bWasSnapEnabled = rView.IsSnapEnabled();
281 // switch snapping off
282 if ( !bWasNoSnap )
283 const_cast<SdrDragStat&>(rDragStat).SetNoSnap(true);
284 if ( bWasSnapEnabled )
285 rView.SetSnapEnabled(false);
287 rView.MovAction( aEndPoint );
288 rView.EndDragObj();
290 // restore snap
291 if ( !bWasNoSnap )
292 const_cast<SdrDragStat&>(rDragStat).SetNoSnap( bWasNoSnap );
293 if ( bWasSnapEnabled )
294 rView.SetSnapEnabled( bWasSnapEnabled );
297 // make moved handle visible
298 Rectangle aVisRect( aEndPoint - Point( 100, 100 ), Size( 200, 200 ) );
299 rView.MakeVisible( aVisRect, rWindow );
303 else
305 // scroll page
306 ScrollBar* pScrollBar = ( nX != 0 ) ? rParent.GetHScroll() : rParent.GetVScroll();
307 if ( pScrollBar )
309 long nRangeMin = pScrollBar->GetRangeMin();
310 long nRangeMax = pScrollBar->GetRangeMax();
311 long nThumbPos = pScrollBar->GetThumbPos() + ( ( nX != 0 ) ? nX : nY ) * pScrollBar->GetLineSize();
312 if ( nThumbPos < nRangeMin )
313 nThumbPos = nRangeMin;
314 if ( nThumbPos > nRangeMax )
315 nThumbPos = nRangeMax;
316 pScrollBar->SetThumbPos( nThumbPos );
317 rParent.DoScroll( pScrollBar );
321 bReturn = true;
323 break;
324 default:
327 break;
330 if ( bReturn )
331 rWindow.ReleaseMouse();
333 return bReturn;
336 DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor& rParent_) :
337 DlgEdFunc(rParent_)
339 rParent.GetView().SetCreateMode(true);
342 DlgEdFuncInsert::~DlgEdFuncInsert()
344 rParent.GetView().SetEditMode( true );
347 bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
349 if( !rMEvt.IsLeft() )
350 return true;
352 SdrView& rView = rParent.GetView();
353 Window& rWindow = rParent.GetWindow();
354 rView.SetActualWin(&rWindow);
356 Point aPos = rWindow.PixelToLogic( rMEvt.GetPosPixel() );
357 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
358 sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
360 rWindow.CaptureMouse();
362 if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
364 SdrHdl* pHdl = rView.PickHandle(aPos);
366 // if selected object was hit, drag object
367 if ( pHdl!=NULL || rView.IsMarkedHit(aPos, nHitLog) )
368 rView.BegDragObj(aPos, (OutputDevice*) NULL, pHdl, nDrgLog);
369 else if ( rView.AreObjectsMarked() )
370 rView.UnmarkAll();
372 // if no action, create object
373 if ( !rView.IsAction() )
374 rView.BegCreateObj(aPos);
376 else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
378 // if object was hit, show property browser
379 if ( rView.IsMarkedHit(aPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
380 rParent.ShowProperties();
383 return true;
386 bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
388 DlgEdFunc::MouseButtonUp( rMEvt );
390 SdrView& rView = rParent.GetView();
391 Window& rWindow = rParent.GetWindow();
392 rView.SetActualWin(&rWindow);
394 rWindow.ReleaseMouse();
396 // object creation active?
397 if ( rView.IsCreateObj() )
399 rView.EndCreateObj(SDRCREATE_FORCEEND);
401 if ( !rView.AreObjectsMarked() )
403 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
404 Point aPos( rWindow.PixelToLogic( rMEvt.GetPosPixel() ) );
405 rView.MarkObj(aPos, nHitLog);
408 return rView.AreObjectsMarked();
410 else
412 if ( rView.IsDragObj() )
413 rView.EndDragObj( rMEvt.IsMod1() );
414 return true;
418 bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
420 SdrView& rView = rParent.GetView();
421 Window& rWindow = rParent.GetWindow();
422 rView.SetActualWin(&rWindow);
424 Point aPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
425 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
427 if (rView.IsAction())
429 ForceScroll(aPos);
430 rView.MovAction(aPos);
433 rWindow.SetPointer( rView.GetPreferredPointer( aPos, &rWindow, nHitLog ) );
435 return true;
438 DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor& rParent_) :
439 DlgEdFunc(rParent_),
440 bMarkAction(false)
444 DlgEdFuncSelect::~DlgEdFuncSelect()
448 bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
450 // get view from parent
451 SdrView& rView = rParent.GetView();
452 Window& rWindow = rParent.GetWindow();
453 rView.SetActualWin(&rWindow);
455 sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
456 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
457 Point aMDPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
459 if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
461 SdrHdl* pHdl = rView.PickHandle(aMDPos);
462 SdrObject* pObj;
463 SdrPageView* pPV;
465 // hit selected object?
466 if ( pHdl!=NULL || rView.IsMarkedHit(aMDPos, nHitLog) )
468 rView.BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
470 else
472 // if not multi selection, unmark all
473 if ( !rMEvt.IsShift() )
474 rView.UnmarkAll();
475 else
477 if( rView.PickObj( aMDPos, nHitLog, pObj, pPV ) )
479 //if (dynamic_cast<DlgEdForm*>(pObj))
480 // rView.UnmarkAll();
481 //else
482 // rParent.UnmarkDialog();
486 if ( rView.MarkObj(aMDPos, nHitLog) )
488 // drag object
489 pHdl = rView.PickHandle(aMDPos);
490 rView.BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
492 else
494 // select object
495 rView.BegMarkObj(aMDPos);
496 bMarkAction = true;
500 else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
502 // if object was hit, show property browser
503 if ( rView.IsMarkedHit(aMDPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
504 rParent.ShowProperties();
507 return true;
510 bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
512 DlgEdFunc::MouseButtonUp( rMEvt );
514 // get view from parent
515 SdrView& rView = rParent.GetView();
516 Window& rWindow = rParent.GetWindow();
517 rView.SetActualWin(&rWindow);
519 Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
520 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
522 if ( rMEvt.IsLeft() )
524 if (rView.IsDragObj())
526 // object was dragged
527 rView.EndDragObj( rMEvt.IsMod1() );
528 rView.ForceMarkedToAnotherPage();
530 else if (rView.IsAction())
532 rView.EndAction();
536 bMarkAction = false;
538 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
539 rWindow.ReleaseMouse();
541 return true;
544 bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
546 SdrView& rView = rParent.GetView();
547 Window& rWindow = rParent.GetWindow();
548 rView.SetActualWin(&rWindow);
550 Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
551 sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
553 if ( rView.IsAction() )
555 Point aPix = rMEvt.GetPosPixel();
556 Point aPnt_ = rWindow.PixelToLogic(aPix);
558 ForceScroll(aPnt_);
559 rView.MovAction(aPnt_);
562 rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
564 return true;
567 } // namespace basctl
569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */