xref: /aoo42x/main/svx/source/dialog/measctrl.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2*f6e50924SAndrew Rist  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svx/svdomeas.hxx>
30cdf0e10cSrcweir #include <svx/svdmodel.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "svx/measctrl.hxx"
33cdf0e10cSrcweir #include <svx/dialmgr.hxx>
34cdf0e10cSrcweir #include "svx/dlgutil.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /*************************************************************************
37cdf0e10cSrcweir |*
38cdf0e10cSrcweir |* Ctor SvxXMeasurePreview
39cdf0e10cSrcweir |*
40cdf0e10cSrcweir *************************************************************************/
41cdf0e10cSrcweir 
SvxXMeasurePreview(Window * pParent,const ResId & rResId,const SfxItemSet & rInAttrs)42cdf0e10cSrcweir SvxXMeasurePreview::SvxXMeasurePreview
43cdf0e10cSrcweir (
44cdf0e10cSrcweir 	Window* pParent,
45cdf0e10cSrcweir 	const ResId& rResId,
46cdf0e10cSrcweir 	const SfxItemSet& rInAttrs
47cdf0e10cSrcweir ) :
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	Control	( pParent, rResId ),
50cdf0e10cSrcweir 	rAttrs	( rInAttrs )
51cdf0e10cSrcweir 
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	SetMapMode( MAP_100TH_MM );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	Size aSize = GetOutputSize();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	// Massstab: 1:2
58cdf0e10cSrcweir 	MapMode aMapMode = GetMapMode();
59cdf0e10cSrcweir 	aMapMode.SetScaleX( Fraction( 1, 2 ) );
60cdf0e10cSrcweir 	aMapMode.SetScaleY( Fraction( 1, 2 ) );
61cdf0e10cSrcweir 	SetMapMode( aMapMode );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	aSize = GetOutputSize();
64cdf0e10cSrcweir 	Rectangle aRect = Rectangle( Point(), aSize );
65cdf0e10cSrcweir 	Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
66cdf0e10cSrcweir 	Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
69cdf0e10cSrcweir 	pModel = new SdrModel();
70cdf0e10cSrcweir 	pMeasureObj->SetModel( pModel );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	//pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
73cdf0e10cSrcweir 	pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	Invalidate();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir /*************************************************************************
81cdf0e10cSrcweir |*
82cdf0e10cSrcweir |* Dtor SvxXMeasurePreview
83cdf0e10cSrcweir |*
84cdf0e10cSrcweir *************************************************************************/
85cdf0e10cSrcweir 
~SvxXMeasurePreview()86cdf0e10cSrcweir SvxXMeasurePreview::~SvxXMeasurePreview()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	// #111111#
89cdf0e10cSrcweir 	// No one is deleting the MeasureObj? This is not only an error but also
90cdf0e10cSrcweir 	// a memory leak (!). Main problem is that this object is still listening to
91cdf0e10cSrcweir 	// a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
92cdf0e10cSrcweir 	// set the modfel to 0L, if object is not needed (seems to be the case here),
93cdf0e10cSrcweir 	// delete it.
94cdf0e10cSrcweir 	delete pMeasureObj;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	delete pModel;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir /*************************************************************************
100cdf0e10cSrcweir |*
101cdf0e10cSrcweir |* SvxXMeasurePreview: Paint()
102cdf0e10cSrcweir |*
103cdf0e10cSrcweir *************************************************************************/
104cdf0e10cSrcweir 
Paint(const Rectangle &)105cdf0e10cSrcweir void SvxXMeasurePreview::Paint( const Rectangle&  )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	pMeasureObj->SingleObjectPainter(*this); // #110094#-17
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir /*************************************************************************
111cdf0e10cSrcweir |*
112cdf0e10cSrcweir |* SvxXMeasurePreview: SetAttributes()
113cdf0e10cSrcweir |*
114cdf0e10cSrcweir *************************************************************************/
115cdf0e10cSrcweir 
SetAttributes(const SfxItemSet & rInAttrs)116cdf0e10cSrcweir void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	//pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
119cdf0e10cSrcweir 	pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	Invalidate();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir /*************************************************************************
125cdf0e10cSrcweir |*
126cdf0e10cSrcweir |* SvxXMeasurePreview: SetAttributes()
127cdf0e10cSrcweir |*
128cdf0e10cSrcweir *************************************************************************/
129cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)130cdf0e10cSrcweir void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	sal_Bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
133cdf0e10cSrcweir 	sal_Bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
134cdf0e10cSrcweir 	sal_Bool bCtrl	  = rMEvt.IsMod1();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	if( bZoomIn || bZoomOut )
137cdf0e10cSrcweir 	{
138cdf0e10cSrcweir 		MapMode aMapMode = GetMapMode();
139cdf0e10cSrcweir 		Fraction aXFrac = aMapMode.GetScaleX();
140cdf0e10cSrcweir 		Fraction aYFrac = aMapMode.GetScaleY();
141cdf0e10cSrcweir 		Fraction* pMultFrac;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if( bZoomIn )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			if( bCtrl )
146cdf0e10cSrcweir 				pMultFrac = new Fraction( 3, 2 );
147cdf0e10cSrcweir 			else
148cdf0e10cSrcweir 				pMultFrac = new Fraction( 11, 10 );
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 		else
151cdf0e10cSrcweir 		{
152cdf0e10cSrcweir 			if( bCtrl )
153cdf0e10cSrcweir 				pMultFrac = new Fraction( 2, 3 );
154cdf0e10cSrcweir 			else
155cdf0e10cSrcweir 				pMultFrac = new Fraction( 10, 11 );
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		aXFrac *= *pMultFrac;
159cdf0e10cSrcweir 		aYFrac *= *pMultFrac;
160cdf0e10cSrcweir 		if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
161cdf0e10cSrcweir 			(double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
162cdf0e10cSrcweir 		{
163cdf0e10cSrcweir 			aMapMode.SetScaleX( aXFrac );
164cdf0e10cSrcweir 			aMapMode.SetScaleY( aYFrac );
165cdf0e10cSrcweir 			SetMapMode( aMapMode );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 			Size aOutSize( GetOutputSize() );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 			Point aPt( aMapMode.GetOrigin() );
170cdf0e10cSrcweir 			long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
171cdf0e10cSrcweir 			long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
172cdf0e10cSrcweir 			aPt.X() +=  nX;
173cdf0e10cSrcweir 			aPt.Y() +=  nY;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 			aMapMode.SetOrigin( aPt );
176cdf0e10cSrcweir 			SetMapMode( aMapMode );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 			Invalidate();
179cdf0e10cSrcweir 		}
180cdf0e10cSrcweir 		delete pMultFrac;
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // -----------------------------------------------------------------------
185cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)186cdf0e10cSrcweir void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	Control::DataChanged( rDCEvt );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
193cdf0e10cSrcweir 	}
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196