Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svx/svdomeas.hxx>
21 : #include <svx/svdmodel.hxx>
22 :
23 : #include "svx/measctrl.hxx"
24 : #include <svx/dialmgr.hxx>
25 : #include "svx/dlgutil.hxx"
26 :
27 0 : SvxXMeasurePreview::SvxXMeasurePreview
28 : (
29 : Window* pParent,
30 : const ResId& rResId,
31 : const SfxItemSet& rInAttrs
32 : ) :
33 :
34 : Control ( pParent, rResId ),
35 0 : rAttrs ( rInAttrs )
36 :
37 : {
38 0 : SetMapMode( MAP_100TH_MM );
39 :
40 0 : Size aSize = GetOutputSize();
41 :
42 : // Scale: 1:2
43 0 : MapMode aMapMode = GetMapMode();
44 0 : aMapMode.SetScaleX( Fraction( 1, 2 ) );
45 0 : aMapMode.SetScaleY( Fraction( 1, 2 ) );
46 0 : SetMapMode( aMapMode );
47 :
48 0 : aSize = GetOutputSize();
49 0 : Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
50 0 : Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
51 :
52 0 : pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
53 0 : pModel = new SdrModel();
54 0 : pMeasureObj->SetModel( pModel );
55 :
56 0 : pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
57 :
58 0 : SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
59 :
60 0 : Invalidate();
61 0 : }
62 :
63 0 : SvxXMeasurePreview::~SvxXMeasurePreview()
64 : {
65 : // No one is deleting the MeasureObj? This is not only an error but also
66 : // a memory leak (!). Main problem is that this object is still listening to
67 : // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
68 : // set the modfel to 0L, if object is not needed (seems to be the case here),
69 : // delete it.
70 0 : delete pMeasureObj;
71 :
72 0 : delete pModel;
73 0 : }
74 :
75 0 : void SvxXMeasurePreview::Paint( const Rectangle& )
76 : {
77 0 : pMeasureObj->SingleObjectPainter(*this);
78 0 : }
79 :
80 0 : void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
81 : {
82 0 : pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
83 :
84 0 : Invalidate();
85 0 : }
86 :
87 0 : void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
88 : {
89 0 : sal_Bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
90 0 : sal_Bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
91 0 : sal_Bool bCtrl = rMEvt.IsMod1();
92 :
93 0 : if( bZoomIn || bZoomOut )
94 : {
95 0 : MapMode aMapMode = GetMapMode();
96 0 : Fraction aXFrac = aMapMode.GetScaleX();
97 0 : Fraction aYFrac = aMapMode.GetScaleY();
98 : Fraction* pMultFrac;
99 :
100 0 : if( bZoomIn )
101 : {
102 0 : if( bCtrl )
103 0 : pMultFrac = new Fraction( 3, 2 );
104 : else
105 0 : pMultFrac = new Fraction( 11, 10 );
106 : }
107 : else
108 : {
109 0 : if( bCtrl )
110 0 : pMultFrac = new Fraction( 2, 3 );
111 : else
112 0 : pMultFrac = new Fraction( 10, 11 );
113 : }
114 :
115 0 : aXFrac *= *pMultFrac;
116 0 : aYFrac *= *pMultFrac;
117 0 : if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
118 0 : (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
119 : {
120 0 : aMapMode.SetScaleX( aXFrac );
121 0 : aMapMode.SetScaleY( aYFrac );
122 0 : SetMapMode( aMapMode );
123 :
124 0 : Size aOutSize( GetOutputSize() );
125 :
126 0 : Point aPt( aMapMode.GetOrigin() );
127 0 : long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
128 0 : long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac ) ) / 2.0 + 0.5 );
129 0 : aPt.X() += nX;
130 0 : aPt.Y() += nY;
131 :
132 0 : aMapMode.SetOrigin( aPt );
133 0 : SetMapMode( aMapMode );
134 :
135 0 : Invalidate();
136 : }
137 0 : delete pMultFrac;
138 : }
139 0 : }
140 :
141 : // -----------------------------------------------------------------------
142 :
143 0 : void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
144 : {
145 0 : Control::DataChanged( rDCEvt );
146 :
147 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
148 : {
149 0 : SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
150 : }
151 0 : }
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|