Files
libreoffice/basctl/source/dlged/dlgedfunc.cxx

568 lines
17 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-12 17:02:47 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2001-02-26 09:41:22 +00:00
#include <vcl/scrbar.hxx>
#include <svx/svdview.hxx>
#include "dlgedfunc.hxx"
2001-03-23 15:13:46 +00:00
#include "dlged.hxx"
#include "dlgedview.hxx"
2001-02-26 09:41:22 +00:00
#include <vcl/seleng.hxx>
namespace basctl
{
IMPL_LINK_TYPED( DlgEdFunc, ScrollTimeout, Timer *, pTimer, void )
2001-02-26 09:41:22 +00:00
{
(void)pTimer;
vcl::Window& rWindow = rParent.GetWindow();
Point aPos = rWindow.ScreenToOutputPixel( rWindow.GetPointerPosPixel() );
aPos = rWindow.PixelToLogic( aPos );
2001-02-26 09:41:22 +00:00
ForceScroll( aPos );
}
void DlgEdFunc::ForceScroll( const Point& rPos )
{
aScrollTimer.Stop();
vcl::Window& rWindow = rParent.GetWindow();
2001-02-26 09:41:22 +00:00
static Point aDefPoint;
Rectangle aOutRect( aDefPoint, rWindow.GetOutputSizePixel() );
aOutRect = rWindow.PixelToLogic( aOutRect );
2001-02-26 09:41:22 +00:00
ScrollBar* pHScroll = rParent.GetHScroll();
ScrollBar* pVScroll = rParent.GetVScroll();
2001-02-26 09:41:22 +00:00
long nDeltaX = pHScroll->GetLineSize();
long nDeltaY = pVScroll->GetLineSize();
if( !aOutRect.IsInside( rPos ) )
{
if( rPos.X() < aOutRect.Left() )
nDeltaX = -nDeltaX;
else if( rPos.X() <= aOutRect.Right() )
2001-02-26 09:41:22 +00:00
nDeltaX = 0;
if( rPos.Y() < aOutRect.Top() )
nDeltaY = -nDeltaY;
else if( rPos.Y() <= aOutRect.Bottom() )
2001-02-26 09:41:22 +00:00
nDeltaY = 0;
if( nDeltaX )
pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
if( nDeltaY )
pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
if( nDeltaX )
rParent.DoScroll( pHScroll );
2001-02-26 09:41:22 +00:00
if( nDeltaY )
rParent.DoScroll( pVScroll );
2001-02-26 09:41:22 +00:00
}
aScrollTimer.Start();
}
DlgEdFunc::DlgEdFunc (DlgEditor& rParent_) :
rParent(rParent_)
2001-02-26 09:41:22 +00:00
{
aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
}
DlgEdFunc::~DlgEdFunc()
{
}
bool DlgEdFunc::MouseButtonDown( const MouseEvent& )
2001-02-26 09:41:22 +00:00
{
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFunc::MouseButtonUp( const MouseEvent& )
2001-02-26 09:41:22 +00:00
{
aScrollTimer.Stop();
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFunc::MouseMove( const MouseEvent& )
2001-02-26 09:41:22 +00:00
{
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFunc::KeyInput( const KeyEvent& rKEvt )
2001-02-26 09:41:22 +00:00
{
bool bReturn = false;
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
vcl::KeyCode aCode = rKEvt.GetKeyCode();
sal_uInt16 nCode = aCode.GetCode();
switch ( nCode )
2001-02-26 09:41:22 +00:00
{
case KEY_ESCAPE:
2001-02-26 09:41:22 +00:00
{
if ( rView.IsAction() )
{
rView.BrkAction();
bReturn = true;
}
else if ( rView.AreObjectsMarked() )
{
const SdrHdlList& rHdlList = rView.GetHdlList();
SdrHdl* pHdl = rHdlList.GetFocusHdl();
if ( pHdl )
const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
else
rView.UnmarkAll();
bReturn = true;
}
}
break;
case KEY_TAB:
{
if ( !aCode.IsMod1() && !aCode.IsMod2() )
{
// mark next object
if ( !rView.MarkNextObj( !aCode.IsShift() ) )
{
// if no next object, mark first/last
rView.UnmarkAllObj();
rView.MarkNextObj( !aCode.IsShift() );
}
if ( rView.AreObjectsMarked() )
rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
bReturn = true;
}
else if ( aCode.IsMod1() )
{
// selected handle
const SdrHdlList& rHdlList = rView.GetHdlList();
const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl( !aCode.IsShift() );
// guarantee visibility of focused handle
if (SdrHdl* pHdl = rHdlList.GetFocusHdl())
{
Point aHdlPosition( pHdl->GetPos() );
Rectangle aVisRect( aHdlPosition - Point( 100, 100 ), Size( 200, 200 ) );
rView.MakeVisible( aVisRect, rWindow );
}
bReturn = true;
}
2001-02-26 09:41:22 +00:00
}
break;
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
case KEY_RIGHT:
{
long nX = 0;
long nY = 0;
if ( nCode == KEY_UP )
{
// scroll up
nX = 0;
nY = -1;
}
else if ( nCode == KEY_DOWN )
{
// scroll down
nX = 0;
nY = 1;
}
else if ( nCode == KEY_LEFT )
{
// scroll left
nX = -1;
nY = 0;
}
else if ( nCode == KEY_RIGHT )
{
// scroll right
nX = 1;
nY = 0;
}
if ( rView.AreObjectsMarked() && !aCode.IsMod1() )
{
if ( aCode.IsMod2() )
{
// move in 1 pixel distance
Size aPixelSize = rWindow.PixelToLogic(Size(1, 1));
nX *= aPixelSize.Width();
nY *= aPixelSize.Height();
}
else
{
// move in 1 mm distance
nX *= 100;
nY *= 100;
}
const SdrHdlList& rHdlList = rView.GetHdlList();
SdrHdl* pHdl = rHdlList.GetFocusHdl();
if ( pHdl == 0 )
{
// no handle selected
if ( rView.IsMoveAllowed() )
{
// restrict movement to work area
const Rectangle& rWorkArea = rView.GetWorkArea();
if ( !rWorkArea.IsEmpty() )
{
Rectangle aMarkRect( rView.GetMarkedObjRect() );
aMarkRect.Move( nX, nY );
if ( !rWorkArea.IsInside( aMarkRect ) )
{
if ( aMarkRect.Left() < rWorkArea.Left() )
nX += rWorkArea.Left() - aMarkRect.Left();
if ( aMarkRect.Right() > rWorkArea.Right() )
nX -= aMarkRect.Right() - rWorkArea.Right();
if ( aMarkRect.Top() < rWorkArea.Top() )
nY += rWorkArea.Top() - aMarkRect.Top();
if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
}
}
if ( nX != 0 || nY != 0 )
{
rView.MoveAllMarked( Size( nX, nY ) );
rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
}
}
}
else
{
// move the handle
if ( pHdl && ( nX || nY ) )
{
Point aStartPoint( pHdl->GetPos() );
Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
const SdrDragStat& rDragStat = rView.GetDragStat();
// start dragging
rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
if ( rView.IsDragObj() )
{
bool const bWasNoSnap = rDragStat.IsNoSnap();
bool const bWasSnapEnabled = rView.IsSnapEnabled();
// switch snapping off
if ( !bWasNoSnap )
const_cast<SdrDragStat&>(rDragStat).SetNoSnap(true);
if ( bWasSnapEnabled )
rView.SetSnapEnabled(false);
rView.MovAction( aEndPoint );
rView.EndDragObj();
// restore snap
if ( !bWasNoSnap )
const_cast<SdrDragStat&>(rDragStat).SetNoSnap( bWasNoSnap );
if ( bWasSnapEnabled )
rView.SetSnapEnabled( bWasSnapEnabled );
}
// make moved handle visible
Rectangle aVisRect( aEndPoint - Point( 100, 100 ), Size( 200, 200 ) );
rView.MakeVisible( aVisRect, rWindow );
}
}
}
else
{
// scroll page
ScrollBar* pScrollBar = ( nX != 0 ) ? rParent.GetHScroll() : rParent.GetVScroll();
if ( pScrollBar )
{
long nRangeMin = pScrollBar->GetRangeMin();
long nRangeMax = pScrollBar->GetRangeMax();
long nThumbPos = pScrollBar->GetThumbPos() + ( ( nX != 0 ) ? nX : nY ) * pScrollBar->GetLineSize();
if ( nThumbPos < nRangeMin )
nThumbPos = nRangeMin;
if ( nThumbPos > nRangeMax )
nThumbPos = nRangeMax;
pScrollBar->SetThumbPos( nThumbPos );
rParent.DoScroll( pScrollBar );
}
}
bReturn = true;
}
break;
default:
{
}
break;
2001-02-26 09:41:22 +00:00
}
if ( bReturn )
rWindow.ReleaseMouse();
return bReturn;
2001-02-26 09:41:22 +00:00
}
DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor& rParent_) :
DlgEdFunc(rParent_)
2001-02-26 09:41:22 +00:00
{
rParent.GetView().SetCreateMode(true);
2001-02-26 09:41:22 +00:00
}
DlgEdFuncInsert::~DlgEdFuncInsert()
{
rParent.GetView().SetEditMode( true );
2001-02-26 09:41:22 +00:00
}
bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
if( !rMEvt.IsLeft() )
return true;
2001-02-26 09:41:22 +00:00
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
Point aPos = rWindow.PixelToLogic( rMEvt.GetPosPixel() );
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
2001-02-26 09:41:22 +00:00
rWindow.CaptureMouse();
2001-02-26 09:41:22 +00:00
if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
{
SdrHdl* pHdl = rView.PickHandle(aPos);
2001-02-26 09:41:22 +00:00
// if selected object was hit, drag object
if ( pHdl!=NULL || rView.IsMarkedHit(aPos, nHitLog) )
rView.BegDragObj(aPos, nullptr, pHdl, nDrgLog);
else if ( rView.AreObjectsMarked() )
rView.UnmarkAll();
2001-02-26 09:41:22 +00:00
// if no action, create object
if ( !rView.IsAction() )
rView.BegCreateObj(aPos);
}
else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
{
// if object was hit, show property browser
if ( rView.IsMarkedHit(aPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
rParent.ShowProperties();
}
2001-02-26 09:41:22 +00:00
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
DlgEdFunc::MouseButtonUp( rMEvt );
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
rWindow.ReleaseMouse();
2001-02-26 09:41:22 +00:00
2001-03-23 15:13:46 +00:00
// object creation active?
if ( rView.IsCreateObj() )
2001-02-26 09:41:22 +00:00
{
rView.EndCreateObj(SDRCREATE_FORCEEND);
2001-02-26 09:41:22 +00:00
if ( !rView.AreObjectsMarked() )
2001-02-26 09:41:22 +00:00
{
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
Point aPos( rWindow.PixelToLogic( rMEvt.GetPosPixel() ) );
rView.MarkObj(aPos, nHitLog);
2001-02-26 09:41:22 +00:00
}
return rView.AreObjectsMarked();
2001-02-26 09:41:22 +00:00
}
else
{
if ( rView.IsDragObj() )
rView.EndDragObj( rMEvt.IsMod1() );
return true;
2001-02-26 09:41:22 +00:00
}
}
bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
Point aPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
2001-02-26 09:41:22 +00:00
if (rView.IsAction())
2001-02-26 09:41:22 +00:00
{
ForceScroll(aPos);
rView.MovAction(aPos);
2001-02-26 09:41:22 +00:00
}
rWindow.SetPointer( rView.GetPreferredPointer( aPos, &rWindow, nHitLog ) );
2001-02-26 09:41:22 +00:00
return true;
2001-02-26 09:41:22 +00:00
}
DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor& rParent_) :
DlgEdFunc(rParent_),
bMarkAction(false)
2001-02-26 09:41:22 +00:00
{
}
DlgEdFuncSelect::~DlgEdFuncSelect()
{
}
bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
2001-03-23 15:13:46 +00:00
// get view from parent
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
Point aMDPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
2001-02-26 09:41:22 +00:00
if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
2001-02-26 09:41:22 +00:00
{
SdrHdl* pHdl = rView.PickHandle(aMDPos);
2001-02-26 09:41:22 +00:00
2001-03-23 15:13:46 +00:00
// hit selected object?
if ( pHdl!=NULL || rView.IsMarkedHit(aMDPos, nHitLog) )
2001-02-26 09:41:22 +00:00
{
rView.BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
2001-02-26 09:41:22 +00:00
}
else
{
2001-03-23 15:13:46 +00:00
// if not multi selection, unmark all
2001-02-26 09:41:22 +00:00
if ( !rMEvt.IsShift() )
rView.UnmarkAll();
2001-02-26 09:41:22 +00:00
else
{
SdrObject* pObj;
SdrPageView* pPV;
if( rView.PickObj( aMDPos, nHitLog, pObj, pPV ) )
2001-02-26 09:41:22 +00:00
{
//if (dynamic_cast<DlgEdForm*>(pObj))
// rView.UnmarkAll();
2001-04-10 14:18:14 +00:00
//else
// rParent.UnmarkDialog();
2001-02-26 09:41:22 +00:00
}
}
if ( rView.MarkObj(aMDPos, nHitLog) )
2001-02-26 09:41:22 +00:00
{
2001-03-23 15:13:46 +00:00
// drag object
pHdl = rView.PickHandle(aMDPos);
rView.BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
2001-02-26 09:41:22 +00:00
}
else
{
2001-03-23 15:13:46 +00:00
// select object
rView.BegMarkObj(aMDPos);
bMarkAction = true;
2001-02-26 09:41:22 +00:00
}
}
}
else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
{
// if object was hit, show property browser
if ( rView.IsMarkedHit(aMDPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
rParent.ShowProperties();
}
2001-02-26 09:41:22 +00:00
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
DlgEdFunc::MouseButtonUp( rMEvt );
2001-03-23 15:13:46 +00:00
// get view from parent
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
2001-02-26 09:41:22 +00:00
if ( rMEvt.IsLeft() )
{
if (rView.IsDragObj())
2001-02-26 09:41:22 +00:00
{
2001-03-23 15:13:46 +00:00
// object was dragged
rView.EndDragObj( rMEvt.IsMod1() );
rView.ForceMarkedToAnotherPage();
2001-02-26 09:41:22 +00:00
}
else if (rView.IsAction())
2001-02-26 09:41:22 +00:00
{
rView.EndAction();
2001-02-26 09:41:22 +00:00
}
}
bMarkAction = false;
2001-02-26 09:41:22 +00:00
rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
rWindow.ReleaseMouse();
2001-02-26 09:41:22 +00:00
return true;
2001-02-26 09:41:22 +00:00
}
bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
2001-02-26 09:41:22 +00:00
{
SdrView& rView = rParent.GetView();
vcl::Window& rWindow = rParent.GetWindow();
rView.SetActualWin(&rWindow);
2001-02-26 09:41:22 +00:00
Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
2001-02-26 09:41:22 +00:00
if ( rView.IsAction() )
2001-02-26 09:41:22 +00:00
{
Point aPix = rMEvt.GetPosPixel();
Point aPnt_ = rWindow.PixelToLogic(aPix);
2001-02-26 09:41:22 +00:00
ForceScroll(aPnt_);
rView.MovAction(aPnt_);
2001-02-26 09:41:22 +00:00
}
rWindow.SetPointer( rView.GetPreferredPointer( aPnt, &rWindow, nHitLog ) );
2001-02-26 09:41:22 +00:00
return true;
2001-02-26 09:41:22 +00:00
}
} // namespace basctl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */