Update ooo320-m1
[ooovba.git] / svx / source / dialog / measctrl.cxx
blobc7a4786a0f6be8e39b8618325eb58b7e7b87ecdb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: measctrl.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
36 #include <svx/svdomeas.hxx>
37 #include <svx/svdmodel.hxx>
39 #include "measctrl.hxx"
40 #include <svx/dialmgr.hxx>
41 #include "dlgutil.hxx"
43 /*************************************************************************
45 |* Ctor SvxXMeasurePreview
47 *************************************************************************/
49 SvxXMeasurePreview::SvxXMeasurePreview
51 Window* pParent,
52 const ResId& rResId,
53 const SfxItemSet& rInAttrs
54 ) :
56 Control ( pParent, rResId ),
57 rAttrs ( rInAttrs )
60 SetMapMode( MAP_100TH_MM );
62 Size aSize = GetOutputSize();
64 // Massstab: 1:2
65 MapMode aMapMode = GetMapMode();
66 aMapMode.SetScaleX( Fraction( 1, 2 ) );
67 aMapMode.SetScaleY( Fraction( 1, 2 ) );
68 SetMapMode( aMapMode );
70 aSize = GetOutputSize();
71 Rectangle aRect = Rectangle( Point(), aSize );
72 Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
73 Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
75 pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
76 pModel = new SdrModel();
77 pMeasureObj->SetModel( pModel );
79 //pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
80 pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
82 SetDrawMode( GetDisplayBackground().GetColor().IsDark() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
84 Invalidate();
87 /*************************************************************************
89 |* Dtor SvxXMeasurePreview
91 *************************************************************************/
93 SvxXMeasurePreview::~SvxXMeasurePreview()
95 // #111111#
96 // No one is deleting the MeasureObj? This is not only an error but also
97 // a memory leak (!). Main problem is that this object is still listening to
98 // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
99 // set the modfel to 0L, if object is not needed (seems to be the case here),
100 // delete it.
101 delete pMeasureObj;
103 delete pModel;
106 /*************************************************************************
108 |* SvxXMeasurePreview: Paint()
110 *************************************************************************/
112 void SvxXMeasurePreview::Paint( const Rectangle& )
114 pMeasureObj->SingleObjectPainter(*this); // #110094#-17
117 /*************************************************************************
119 |* SvxXMeasurePreview: SetAttributes()
121 *************************************************************************/
123 void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
125 //pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
126 pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
128 Invalidate();
131 /*************************************************************************
133 |* SvxXMeasurePreview: SetAttributes()
135 *************************************************************************/
137 void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
139 BOOL bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
140 BOOL bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
141 BOOL bCtrl = rMEvt.IsMod1();
143 if( bZoomIn || bZoomOut )
145 MapMode aMapMode = GetMapMode();
146 Fraction aXFrac = aMapMode.GetScaleX();
147 Fraction aYFrac = aMapMode.GetScaleY();
148 Fraction* pMultFrac;
150 if( bZoomIn )
152 if( bCtrl )
153 pMultFrac = new Fraction( 3, 2 );
154 else
155 pMultFrac = new Fraction( 11, 10 );
157 else
159 if( bCtrl )
160 pMultFrac = new Fraction( 2, 3 );
161 else
162 pMultFrac = new Fraction( 10, 11 );
165 aXFrac *= *pMultFrac;
166 aYFrac *= *pMultFrac;
167 if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
168 (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
170 aMapMode.SetScaleX( aXFrac );
171 aMapMode.SetScaleY( aYFrac );
172 SetMapMode( aMapMode );
174 Size aOutSize( GetOutputSize() );
176 Point aPt( aMapMode.GetOrigin() );
177 long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
178 long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
179 aPt.X() += nX;
180 aPt.Y() += nY;
182 aMapMode.SetOrigin( aPt );
183 SetMapMode( aMapMode );
185 Invalidate();
187 delete pMultFrac;
191 // -----------------------------------------------------------------------
193 void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
195 Control::DataChanged( rDCEvt );
197 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
199 SetDrawMode( GetDisplayBackground().GetColor().IsDark() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );