LCOV - code coverage report
Current view: top level - svx/source/dialog - measctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 82 1.2 %
Date: 2014-11-03 Functions: 2 12 16.7 %
Legend: Lines: hit not hit

          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 <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>
      28             : #include <boost/scoped_ptr.hpp>
      29             : 
      30           0 : SvxXMeasurePreview::SvxXMeasurePreview( vcl::Window* pParent, WinBits nStyle)
      31           0 :     : Control(pParent, nStyle)
      32             : {
      33           0 :     SetMapMode( MAP_100TH_MM );
      34             : 
      35             :     // Scale: 1:2
      36           0 :     MapMode aMapMode = GetMapMode();
      37           0 :     aMapMode.SetScaleX( Fraction( 1, 2 ) );
      38           0 :     aMapMode.SetScaleY( Fraction( 1, 2 ) );
      39           0 :     SetMapMode( aMapMode );
      40             : 
      41           0 :     Size aSize = GetOutputSize();
      42           0 :     Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
      43           0 :     Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
      44             : 
      45           0 :     pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
      46           0 :     pModel = new SdrModel();
      47           0 :     pMeasureObj->SetModel( pModel );
      48             : 
      49           0 :     SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
      50             : 
      51           0 :     Invalidate();
      52           0 : }
      53             : 
      54           0 : void SvxXMeasurePreview::Resize()
      55             : {
      56           0 :     Control::Resize();
      57             : 
      58           0 :     Size aSize = GetOutputSize();
      59           0 :     Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
      60           0 :     pMeasureObj->SetPoint(aPt1, 0);
      61           0 :     Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
      62           0 :     pMeasureObj->SetPoint(aPt2, 1);
      63           0 : }
      64             : 
      65           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSvxXMeasurePreview(vcl::Window *pParent, VclBuilder::stringmap &rMap)
      66             : {
      67           0 :     WinBits nWinStyle = 0;
      68           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      69           0 :     if (!sBorder.isEmpty())
      70           0 :         nWinStyle |= WB_BORDER;
      71           0 :     return new SvxXMeasurePreview(pParent, nWinStyle);
      72             : }
      73             : 
      74           0 : Size SvxXMeasurePreview::GetOptimalSize() const
      75             : {
      76           0 :     return getPreviewStripSize(this);
      77             : }
      78             : 
      79           0 : SvxXMeasurePreview::~SvxXMeasurePreview()
      80             : {
      81             :     // No one is deleting the MeasureObj? This is not only an error but also
      82             :     // a memory leak (!). Main problem is that this object is still listening to
      83             :     // a StyleSheet of the model which was set. Thus, if You want to keep the obnject,
      84             :     // set the modfel to 0L, if object is not needed (seems to be the case here),
      85             :     // delete it.
      86           0 :     delete pMeasureObj;
      87             : 
      88           0 :     delete pModel;
      89           0 : }
      90             : 
      91           0 : void SvxXMeasurePreview::Paint( const Rectangle&  )
      92             : {
      93           0 :     pMeasureObj->SingleObjectPainter(*this);
      94           0 : }
      95             : 
      96           0 : void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
      97             : {
      98           0 :     pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
      99             : 
     100           0 :     Invalidate();
     101           0 : }
     102             : 
     103           0 : void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
     104             : {
     105           0 :     bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
     106           0 :     bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
     107           0 :     bool bCtrl    = rMEvt.IsMod1();
     108             : 
     109           0 :     if( bZoomIn || bZoomOut )
     110             :     {
     111           0 :         MapMode aMapMode = GetMapMode();
     112           0 :         Fraction aXFrac = aMapMode.GetScaleX();
     113           0 :         Fraction aYFrac = aMapMode.GetScaleY();
     114           0 :         boost::scoped_ptr<Fraction> pMultFrac;
     115             : 
     116           0 :         if( bZoomIn )
     117             :         {
     118           0 :             if( bCtrl )
     119           0 :                 pMultFrac.reset(new Fraction( 3, 2 ));
     120             :             else
     121           0 :                 pMultFrac.reset(new Fraction( 11, 10 ));
     122             :         }
     123             :         else
     124             :         {
     125           0 :             if( bCtrl )
     126           0 :                 pMultFrac.reset(new Fraction( 2, 3 ));
     127             :             else
     128           0 :                 pMultFrac.reset(new Fraction( 10, 11 ));
     129             :         }
     130             : 
     131           0 :         aXFrac *= *pMultFrac;
     132           0 :         aYFrac *= *pMultFrac;
     133           0 :         if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
     134           0 :             (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
     135             :         {
     136           0 :             aMapMode.SetScaleX( aXFrac );
     137           0 :             aMapMode.SetScaleY( aYFrac );
     138           0 :             SetMapMode( aMapMode );
     139             : 
     140           0 :             Size aOutSize( GetOutputSize() );
     141             : 
     142           0 :             Point aPt( aMapMode.GetOrigin() );
     143           0 :             long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     144           0 :             long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     145           0 :             aPt.X() +=  nX;
     146           0 :             aPt.Y() +=  nY;
     147             : 
     148           0 :             aMapMode.SetOrigin( aPt );
     149           0 :             SetMapMode( aMapMode );
     150             : 
     151           0 :             Invalidate();
     152           0 :         }
     153             :     }
     154           0 : }
     155             : 
     156             : 
     157             : 
     158           0 : void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
     159             : {
     160           0 :     Control::DataChanged( rDCEvt );
     161             : 
     162           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     163             :     {
     164           0 :         SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
     165             :     }
     166         594 : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10