1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: measctrl.cxx,v $
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
53 const SfxItemSet
& rInAttrs
56 Control ( pParent
, rResId
),
60 SetMapMode( MAP_100TH_MM
);
62 Size aSize
= GetOutputSize();
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
);
87 /*************************************************************************
89 |* Dtor SvxXMeasurePreview
91 *************************************************************************/
93 SvxXMeasurePreview::~SvxXMeasurePreview()
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),
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
);
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();
153 pMultFrac
= new Fraction( 3, 2 );
155 pMultFrac
= new Fraction( 11, 10 );
160 pMultFrac
= new Fraction( 2, 3 );
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 );
182 aMapMode
.SetOrigin( aPt
);
183 SetMapMode( aMapMode
);
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
);