1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/svdomeas.hxx>
21 #include <svx/svdmodel.hxx>
23 #include "svx/measctrl.hxx"
24 #include <svx/dialmgr.hxx>
25 #include "svx/dlgutil.hxx"
27 SvxXMeasurePreview::SvxXMeasurePreview
31 const SfxItemSet
& rInAttrs
34 Control ( pParent
, rResId
),
38 SetMapMode( MAP_100TH_MM
);
40 Size aSize
= GetOutputSize();
43 MapMode aMapMode
= GetMapMode();
44 aMapMode
.SetScaleX( Fraction( 1, 2 ) );
45 aMapMode
.SetScaleY( Fraction( 1, 2 ) );
46 SetMapMode( aMapMode
);
48 aSize
= GetOutputSize();
49 Point aPt1
= Point( aSize
.Width() / 5, (long) ( aSize
.Height() / 2 ) );
50 Point aPt2
= Point( aSize
.Width() * 4 / 5, (long) ( aSize
.Height() / 2 ) );
52 pMeasureObj
= new SdrMeasureObj( aPt1
, aPt2
);
53 pModel
= new SdrModel();
54 pMeasureObj
->SetModel( pModel
);
56 pMeasureObj
->SetMergedItemSetAndBroadcast(rInAttrs
);
58 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
63 SvxXMeasurePreview::~SvxXMeasurePreview()
65 // No one is deleting the MeasureObj? This is not only an error but also
66 // a memory leak (!). Main problem is that this object is still listening to
67 // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
68 // set the modfel to 0L, if object is not needed (seems to be the case here),
75 void SvxXMeasurePreview::Paint( const Rectangle
& )
77 pMeasureObj
->SingleObjectPainter(*this);
80 void SvxXMeasurePreview::SetAttributes( const SfxItemSet
& rInAttrs
)
82 pMeasureObj
->SetMergedItemSetAndBroadcast(rInAttrs
);
87 void SvxXMeasurePreview::MouseButtonDown( const MouseEvent
& rMEvt
)
89 bool bZoomIn
= rMEvt
.IsLeft() && !rMEvt
.IsShift();
90 bool bZoomOut
= rMEvt
.IsRight() || rMEvt
.IsShift();
91 sal_Bool bCtrl
= rMEvt
.IsMod1();
93 if( bZoomIn
|| bZoomOut
)
95 MapMode aMapMode
= GetMapMode();
96 Fraction aXFrac
= aMapMode
.GetScaleX();
97 Fraction aYFrac
= aMapMode
.GetScaleY();
103 pMultFrac
= new Fraction( 3, 2 );
105 pMultFrac
= new Fraction( 11, 10 );
110 pMultFrac
= new Fraction( 2, 3 );
112 pMultFrac
= new Fraction( 10, 11 );
115 aXFrac
*= *pMultFrac
;
116 aYFrac
*= *pMultFrac
;
117 if( (double)aXFrac
> 0.001 && (double)aXFrac
< 1000.0 &&
118 (double)aYFrac
> 0.001 && (double)aYFrac
< 1000.0 )
120 aMapMode
.SetScaleX( aXFrac
);
121 aMapMode
.SetScaleY( aYFrac
);
122 SetMapMode( aMapMode
);
124 Size
aOutSize( GetOutputSize() );
126 Point
aPt( aMapMode
.GetOrigin() );
127 long nX
= (long)( ( (double)aOutSize
.Width() - ( (double)aOutSize
.Width() * (double)*pMultFrac
) ) / 2.0 + 0.5 );
128 long nY
= (long)( ( (double)aOutSize
.Height() - ( (double)aOutSize
.Height() * (double)*pMultFrac
) ) / 2.0 + 0.5 );
132 aMapMode
.SetOrigin( aPt
);
133 SetMapMode( aMapMode
);
141 // -----------------------------------------------------------------------
143 void SvxXMeasurePreview::DataChanged( const DataChangedEvent
& rDCEvt
)
145 Control::DataChanged( rDCEvt
);
147 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
149 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */