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