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