1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/builderfactory.hxx>
27 #include <vcl/settings.hxx>
28 #include <boost/scoped_ptr.hpp>
30 SvxXMeasurePreview::SvxXMeasurePreview(vcl::Window
* pParent
, WinBits nStyle
)
31 : Control(pParent
, nStyle
)
33 SetMapMode(MAP_100TH_MM
);
36 MapMode aMapMode
= GetMapMode();
37 aMapMode
.SetScaleX(Fraction(1, 2));
38 aMapMode
.SetScaleY(Fraction(1, 2));
41 Size aSize
= GetOutputSize();
42 Point aPt1
= Point(aSize
.Width() / 5, (long) (aSize
.Height() / 2));
43 Point aPt2
= Point(aSize
.Width() * 4 / 5, (long) (aSize
.Height() / 2));
45 pMeasureObj
= new SdrMeasureObj(aPt1
, aPt2
);
46 pModel
= new SdrModel();
47 pMeasureObj
->SetModel(pModel
);
49 bool bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
50 SetDrawMode(bHighContrast
? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
55 void SvxXMeasurePreview::Resize()
59 Size aSize
= GetOutputSize();
60 Point aPt1
= Point(aSize
.Width() / 5, (long) (aSize
.Height() / 2));
61 pMeasureObj
->SetPoint(aPt1
, 0);
62 Point aPt2
= Point(aSize
.Width() * 4 / 5, (long) (aSize
.Height() / 2));
63 pMeasureObj
->SetPoint(aPt2
, 1);
66 VCL_BUILDER_DECL_FACTORY(SvxXMeasurePreview
)
68 WinBits nWinStyle
= 0;
69 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
70 if (!sBorder
.isEmpty())
71 nWinStyle
|= WB_BORDER
;
72 rRet
= VclPtr
<SvxXMeasurePreview
>::Create(pParent
, nWinStyle
);
75 Size
SvxXMeasurePreview::GetOptimalSize() const
77 return getPreviewStripSize(this);
80 SvxXMeasurePreview::~SvxXMeasurePreview()
85 void SvxXMeasurePreview::dispose()
87 // No one is deleting the MeasureObj? This is not only an error but also
88 // a memory leak (!). Main problem is that this object is still listening to
89 // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
90 // set the modfel to 0L, if object is not needed (seems to be the case here),
98 void SvxXMeasurePreview::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
&)
100 pMeasureObj
->SingleObjectPainter(rRenderContext
);
103 void SvxXMeasurePreview::SetAttributes(const SfxItemSet
& rInAttrs
)
105 pMeasureObj
->SetMergedItemSetAndBroadcast(rInAttrs
);
110 void SvxXMeasurePreview::MouseButtonDown(const MouseEvent
& rMEvt
)
112 bool bZoomIn
= rMEvt
.IsLeft() && !rMEvt
.IsShift();
113 bool bZoomOut
= rMEvt
.IsRight() || rMEvt
.IsShift();
114 bool bCtrl
= rMEvt
.IsMod1();
116 if (bZoomIn
|| bZoomOut
)
118 MapMode aMapMode
= GetMapMode();
119 Fraction aXFrac
= aMapMode
.GetScaleX();
120 Fraction aYFrac
= aMapMode
.GetScaleY();
121 boost::scoped_ptr
<Fraction
> pMultFrac
;
126 pMultFrac
.reset(new Fraction(3, 2));
128 pMultFrac
.reset(new Fraction(11, 10));
133 pMultFrac
.reset(new Fraction(2, 3));
135 pMultFrac
.reset(new Fraction(10, 11));
138 aXFrac
*= *pMultFrac
;
139 aYFrac
*= *pMultFrac
;
141 if (double(aXFrac
) > 0.001 && double(aXFrac
) < 1000.0 &&
142 double(aYFrac
) > 0.001 && double(aYFrac
) < 1000.0)
144 aMapMode
.SetScaleX(aXFrac
);
145 aMapMode
.SetScaleY(aYFrac
);
146 SetMapMode(aMapMode
);
148 Size
aOutSize(GetOutputSize());
150 Point
aPt(aMapMode
.GetOrigin());
151 long nX
= long((double(aOutSize
.Width()) - (double(aOutSize
.Width()) * double(*pMultFrac
))) / 2.0 + 0.5);
152 long nY
= long((double(aOutSize
.Height()) - (double(aOutSize
.Height()) * double(*pMultFrac
))) / 2.0 + 0.5);
156 aMapMode
.SetOrigin(aPt
);
157 SetMapMode(aMapMode
);
164 void SvxXMeasurePreview::DataChanged( const DataChangedEvent
& rDCEvt
)
166 Control::DataChanged( rDCEvt
);
168 if ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) && (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
170 bool bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
171 SetDrawMode(bHighContrast
? OUTPUT_DRAWMODE_CONTRAST
: OUTPUT_DRAWMODE_COLOR
);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */