2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:20:55 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 03:27:28 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_svx.hxx"
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// include ---------------------------------------------------------------
|
|
|
|
|
2007-06-27 16:20:49 +00:00
|
|
|
#include <svx/svdomeas.hxx>
|
|
|
|
#include <svx/svdmodel.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2010-04-20 15:55:51 +02:00
|
|
|
#include "svx/measctrl.hxx"
|
2007-06-27 16:20:49 +00:00
|
|
|
#include <svx/dialmgr.hxx>
|
2010-04-20 15:55:51 +02:00
|
|
|
#include "svx/dlgutil.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
SvxXMeasurePreview::SvxXMeasurePreview
|
|
|
|
(
|
|
|
|
Window* pParent,
|
|
|
|
const ResId& rResId,
|
|
|
|
const SfxItemSet& rInAttrs
|
|
|
|
) :
|
|
|
|
|
|
|
|
Control ( pParent, rResId ),
|
|
|
|
rAttrs ( rInAttrs )
|
|
|
|
|
|
|
|
{
|
|
|
|
SetMapMode( MAP_100TH_MM );
|
|
|
|
|
|
|
|
Size aSize = GetOutputSize();
|
|
|
|
|
2011-02-21 23:29:31 +01:00
|
|
|
// Scale: 1:2
|
2000-09-18 16:07:07 +00:00
|
|
|
MapMode aMapMode = GetMapMode();
|
|
|
|
aMapMode.SetScaleX( Fraction( 1, 2 ) );
|
|
|
|
aMapMode.SetScaleY( Fraction( 1, 2 ) );
|
|
|
|
SetMapMode( aMapMode );
|
|
|
|
|
|
|
|
aSize = GetOutputSize();
|
|
|
|
Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
|
|
|
|
Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
|
|
|
|
|
|
|
|
pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
|
|
|
|
pModel = new SdrModel();
|
|
|
|
pMeasureObj->SetModel( pModel );
|
|
|
|
|
2003-11-24 15:35:01 +00:00
|
|
|
pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2009-11-03 18:12:19 +01:00
|
|
|
SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
|
2002-06-06 08:08:03 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
SvxXMeasurePreview::~SvxXMeasurePreview()
|
|
|
|
{
|
2003-11-24 15:35:01 +00:00
|
|
|
// No one is deleting the MeasureObj? This is not only an error but also
|
|
|
|
// a memory leak (!). Main problem is that this object is still listening to
|
|
|
|
// a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
|
|
|
|
// set the modfel to 0L, if object is not needed (seems to be the case here),
|
|
|
|
// delete it.
|
|
|
|
delete pMeasureObj;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
delete pModel;
|
|
|
|
}
|
|
|
|
|
2006-06-19 14:18:37 +00:00
|
|
|
void SvxXMeasurePreview::Paint( const Rectangle& )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-02-21 23:29:31 +01:00
|
|
|
pMeasureObj->SingleObjectPainter(*this);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
|
|
|
|
{
|
2003-11-24 15:35:01 +00:00
|
|
|
pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
|
2000-10-30 09:48:03 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
|
|
|
|
{
|
2011-01-10 16:11:35 +01:00
|
|
|
sal_Bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
|
|
|
|
sal_Bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
|
|
|
|
sal_Bool bCtrl = rMEvt.IsMod1();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if( bZoomIn || bZoomOut )
|
|
|
|
{
|
|
|
|
MapMode aMapMode = GetMapMode();
|
|
|
|
Fraction aXFrac = aMapMode.GetScaleX();
|
|
|
|
Fraction aYFrac = aMapMode.GetScaleY();
|
|
|
|
Fraction* pMultFrac;
|
|
|
|
|
|
|
|
if( bZoomIn )
|
|
|
|
{
|
|
|
|
if( bCtrl )
|
|
|
|
pMultFrac = new Fraction( 3, 2 );
|
|
|
|
else
|
|
|
|
pMultFrac = new Fraction( 11, 10 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( bCtrl )
|
|
|
|
pMultFrac = new Fraction( 2, 3 );
|
|
|
|
else
|
|
|
|
pMultFrac = new Fraction( 10, 11 );
|
|
|
|
}
|
|
|
|
|
|
|
|
aXFrac *= *pMultFrac;
|
|
|
|
aYFrac *= *pMultFrac;
|
|
|
|
if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
|
|
|
|
(double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
|
|
|
|
{
|
|
|
|
aMapMode.SetScaleX( aXFrac );
|
|
|
|
aMapMode.SetScaleY( aYFrac );
|
|
|
|
SetMapMode( aMapMode );
|
|
|
|
|
|
|
|
Size aOutSize( GetOutputSize() );
|
|
|
|
|
|
|
|
Point aPt( aMapMode.GetOrigin() );
|
|
|
|
long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
|
|
|
|
long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
|
|
|
|
aPt.X() += nX;
|
|
|
|
aPt.Y() += nY;
|
|
|
|
|
|
|
|
aMapMode.SetOrigin( aPt );
|
|
|
|
SetMapMode( aMapMode );
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
delete pMultFrac;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-06 08:08:03 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
|
|
|
|
{
|
|
|
|
Control::DataChanged( rDCEvt );
|
|
|
|
|
|
|
|
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
|
|
|
|
{
|
2009-11-03 18:12:19 +01:00
|
|
|
SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
|
2002-06-06 08:08:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|