Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / measctrl.cxx
blob5d2910f981456a4c5672bbfe068104a94548b625
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/dialoghelper.hxx>
21 #include <svx/svdomeas.hxx>
22 #include <svx/svdmodel.hxx>
23 #include "svx/measctrl.hxx"
24 #include <svx/dialmgr.hxx>
25 #include "svx/dlgutil.hxx"
26 #include <vcl/builder.hxx>
27 #include <vcl/settings.hxx>
29 SvxXMeasurePreview::SvxXMeasurePreview( Window* pParent, WinBits nStyle)
30 : Control(pParent, nStyle)
32 SetMapMode( MAP_100TH_MM );
34 // Scale: 1:2
35 MapMode aMapMode = GetMapMode();
36 aMapMode.SetScaleX( Fraction( 1, 2 ) );
37 aMapMode.SetScaleY( Fraction( 1, 2 ) );
38 SetMapMode( aMapMode );
40 Size aSize = GetOutputSize();
41 Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
42 Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
44 pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
45 pModel = new SdrModel();
46 pMeasureObj->SetModel( pModel );
48 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
50 Invalidate();
53 void SvxXMeasurePreview::Resize()
55 Control::Resize();
57 Size aSize = GetOutputSize();
58 Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
59 pMeasureObj->SetPoint(aPt1, 0);
60 Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
61 pMeasureObj->SetPoint(aPt2, 1);
64 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxXMeasurePreview(Window *pParent, VclBuilder::stringmap &rMap)
66 WinBits nWinStyle = 0;
67 OString sBorder = VclBuilder::extractCustomProperty(rMap);
68 if (!sBorder.isEmpty())
69 nWinStyle |= WB_BORDER;
70 return new SvxXMeasurePreview(pParent, nWinStyle);
73 Size SvxXMeasurePreview::GetOptimalSize() const
75 return getPreviewStripSize(this);
78 SvxXMeasurePreview::~SvxXMeasurePreview()
80 // No one is deleting the MeasureObj? This is not only an error but also
81 // a memory leak (!). Main problem is that this object is still listening to
82 // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
83 // set the modfel to 0L, if object is not needed (seems to be the case here),
84 // delete it.
85 delete pMeasureObj;
87 delete pModel;
90 void SvxXMeasurePreview::Paint( const Rectangle& )
92 pMeasureObj->SingleObjectPainter(*this);
95 void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
97 pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
99 Invalidate();
102 void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
104 bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
105 bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
106 bool bCtrl = rMEvt.IsMod1();
108 if( bZoomIn || bZoomOut )
110 MapMode aMapMode = GetMapMode();
111 Fraction aXFrac = aMapMode.GetScaleX();
112 Fraction aYFrac = aMapMode.GetScaleY();
113 Fraction* pMultFrac;
115 if( bZoomIn )
117 if( bCtrl )
118 pMultFrac = new Fraction( 3, 2 );
119 else
120 pMultFrac = new Fraction( 11, 10 );
122 else
124 if( bCtrl )
125 pMultFrac = new Fraction( 2, 3 );
126 else
127 pMultFrac = new Fraction( 10, 11 );
130 aXFrac *= *pMultFrac;
131 aYFrac *= *pMultFrac;
132 if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
133 (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
135 aMapMode.SetScaleX( aXFrac );
136 aMapMode.SetScaleY( aYFrac );
137 SetMapMode( aMapMode );
139 Size aOutSize( GetOutputSize() );
141 Point aPt( aMapMode.GetOrigin() );
142 long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
143 long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
144 aPt.X() += nX;
145 aPt.Y() += nY;
147 aMapMode.SetOrigin( aPt );
148 SetMapMode( aMapMode );
150 Invalidate();
152 delete pMultFrac;
158 void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
160 Control::DataChanged( rDCEvt );
162 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
164 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */