xref: /aoo42x/main/svx/source/dialog/measctrl.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <svx/svdomeas.hxx>
34*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "svx/measctrl.hxx"
37*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
38*cdf0e10cSrcweir #include "svx/dlgutil.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /*************************************************************************
41*cdf0e10cSrcweir |*
42*cdf0e10cSrcweir |* Ctor SvxXMeasurePreview
43*cdf0e10cSrcweir |*
44*cdf0e10cSrcweir *************************************************************************/
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir SvxXMeasurePreview::SvxXMeasurePreview
47*cdf0e10cSrcweir (
48*cdf0e10cSrcweir 	Window* pParent,
49*cdf0e10cSrcweir 	const ResId& rResId,
50*cdf0e10cSrcweir 	const SfxItemSet& rInAttrs
51*cdf0e10cSrcweir ) :
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	Control	( pParent, rResId ),
54*cdf0e10cSrcweir 	rAttrs	( rInAttrs )
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 	SetMapMode( MAP_100TH_MM );
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 	Size aSize = GetOutputSize();
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	// Massstab: 1:2
62*cdf0e10cSrcweir 	MapMode aMapMode = GetMapMode();
63*cdf0e10cSrcweir 	aMapMode.SetScaleX( Fraction( 1, 2 ) );
64*cdf0e10cSrcweir 	aMapMode.SetScaleY( Fraction( 1, 2 ) );
65*cdf0e10cSrcweir 	SetMapMode( aMapMode );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	aSize = GetOutputSize();
68*cdf0e10cSrcweir 	Rectangle aRect = Rectangle( Point(), aSize );
69*cdf0e10cSrcweir 	Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
70*cdf0e10cSrcweir 	Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
73*cdf0e10cSrcweir 	pModel = new SdrModel();
74*cdf0e10cSrcweir 	pMeasureObj->SetModel( pModel );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	//pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
77*cdf0e10cSrcweir 	pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 	Invalidate();
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir /*************************************************************************
85*cdf0e10cSrcweir |*
86*cdf0e10cSrcweir |* Dtor SvxXMeasurePreview
87*cdf0e10cSrcweir |*
88*cdf0e10cSrcweir *************************************************************************/
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir SvxXMeasurePreview::~SvxXMeasurePreview()
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir 	// #111111#
93*cdf0e10cSrcweir 	// No one is deleting the MeasureObj? This is not only an error but also
94*cdf0e10cSrcweir 	// a memory leak (!). Main problem is that this object is still listening to
95*cdf0e10cSrcweir 	// a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
96*cdf0e10cSrcweir 	// set the modfel to 0L, if object is not needed (seems to be the case here),
97*cdf0e10cSrcweir 	// delete it.
98*cdf0e10cSrcweir 	delete pMeasureObj;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	delete pModel;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir /*************************************************************************
104*cdf0e10cSrcweir |*
105*cdf0e10cSrcweir |* SvxXMeasurePreview: Paint()
106*cdf0e10cSrcweir |*
107*cdf0e10cSrcweir *************************************************************************/
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir void SvxXMeasurePreview::Paint( const Rectangle&  )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	pMeasureObj->SingleObjectPainter(*this); // #110094#-17
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir /*************************************************************************
115*cdf0e10cSrcweir |*
116*cdf0e10cSrcweir |* SvxXMeasurePreview: SetAttributes()
117*cdf0e10cSrcweir |*
118*cdf0e10cSrcweir *************************************************************************/
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	//pMeasureObj->SetItemSetAndBroadcast(rInAttrs);
123*cdf0e10cSrcweir 	pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	Invalidate();
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir /*************************************************************************
129*cdf0e10cSrcweir |*
130*cdf0e10cSrcweir |* SvxXMeasurePreview: SetAttributes()
131*cdf0e10cSrcweir |*
132*cdf0e10cSrcweir *************************************************************************/
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	sal_Bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
137*cdf0e10cSrcweir 	sal_Bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
138*cdf0e10cSrcweir 	sal_Bool bCtrl	  = rMEvt.IsMod1();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	if( bZoomIn || bZoomOut )
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		MapMode aMapMode = GetMapMode();
143*cdf0e10cSrcweir 		Fraction aXFrac = aMapMode.GetScaleX();
144*cdf0e10cSrcweir 		Fraction aYFrac = aMapMode.GetScaleY();
145*cdf0e10cSrcweir 		Fraction* pMultFrac;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		if( bZoomIn )
148*cdf0e10cSrcweir 		{
149*cdf0e10cSrcweir 			if( bCtrl )
150*cdf0e10cSrcweir 				pMultFrac = new Fraction( 3, 2 );
151*cdf0e10cSrcweir 			else
152*cdf0e10cSrcweir 				pMultFrac = new Fraction( 11, 10 );
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 		else
155*cdf0e10cSrcweir 		{
156*cdf0e10cSrcweir 			if( bCtrl )
157*cdf0e10cSrcweir 				pMultFrac = new Fraction( 2, 3 );
158*cdf0e10cSrcweir 			else
159*cdf0e10cSrcweir 				pMultFrac = new Fraction( 10, 11 );
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		aXFrac *= *pMultFrac;
163*cdf0e10cSrcweir 		aYFrac *= *pMultFrac;
164*cdf0e10cSrcweir 		if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
165*cdf0e10cSrcweir 			(double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
166*cdf0e10cSrcweir 		{
167*cdf0e10cSrcweir 			aMapMode.SetScaleX( aXFrac );
168*cdf0e10cSrcweir 			aMapMode.SetScaleY( aYFrac );
169*cdf0e10cSrcweir 			SetMapMode( aMapMode );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 			Size aOutSize( GetOutputSize() );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 			Point aPt( aMapMode.GetOrigin() );
174*cdf0e10cSrcweir 			long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
175*cdf0e10cSrcweir 			long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
176*cdf0e10cSrcweir 			aPt.X() +=  nX;
177*cdf0e10cSrcweir 			aPt.Y() +=  nY;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 			aMapMode.SetOrigin( aPt );
180*cdf0e10cSrcweir 			SetMapMode( aMapMode );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 			Invalidate();
183*cdf0e10cSrcweir 		}
184*cdf0e10cSrcweir 		delete pMultFrac;
185*cdf0e10cSrcweir 	}
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir // -----------------------------------------------------------------------
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir 	Control::DataChanged( rDCEvt );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir 		SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
197*cdf0e10cSrcweir 	}
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200