LCOV - code coverage report
Current view: top level - svx/source/dialog - measctrl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 81 0.0 %
Date: 2014-04-11 Functions: 0 10 0.0 %
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             : 
      29           0 : SvxXMeasurePreview::SvxXMeasurePreview( Window* pParent, WinBits nStyle)
      30           0 :     : Control(pParent, nStyle)
      31             : {
      32           0 :     SetMapMode( MAP_100TH_MM );
      33             : 
      34             :     // Scale: 1:2
      35           0 :     MapMode aMapMode = GetMapMode();
      36           0 :     aMapMode.SetScaleX( Fraction( 1, 2 ) );
      37           0 :     aMapMode.SetScaleY( Fraction( 1, 2 ) );
      38           0 :     SetMapMode( aMapMode );
      39             : 
      40           0 :     Size aSize = GetOutputSize();
      41           0 :     Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
      42           0 :     Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
      43             : 
      44           0 :     pMeasureObj = new SdrMeasureObj( aPt1, aPt2 );
      45           0 :     pModel = new SdrModel();
      46           0 :     pMeasureObj->SetModel( pModel );
      47             : 
      48           0 :     SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
      49             : 
      50           0 :     Invalidate();
      51           0 : }
      52             : 
      53           0 : void SvxXMeasurePreview::Resize()
      54             : {
      55           0 :     Control::Resize();
      56             : 
      57           0 :     Size aSize = GetOutputSize();
      58           0 :     Point aPt1 = Point( aSize.Width() / 5, (long) ( aSize.Height() / 2 ) );
      59           0 :     pMeasureObj->SetPoint(aPt1, 0);
      60           0 :     Point aPt2 = Point( aSize.Width() * 4 / 5, (long) ( aSize.Height() / 2 ) );
      61           0 :     pMeasureObj->SetPoint(aPt2, 1);
      62           0 : }
      63             : 
      64           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxXMeasurePreview(Window *pParent, VclBuilder::stringmap &rMap)
      65             : {
      66           0 :     WinBits nWinStyle = 0;
      67           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      68           0 :     if (!sBorder.isEmpty())
      69           0 :         nWinStyle |= WB_BORDER;
      70           0 :     return new SvxXMeasurePreview(pParent, nWinStyle);
      71             : }
      72             : 
      73           0 : Size SvxXMeasurePreview::GetOptimalSize() const
      74             : {
      75           0 :     return getPreviewStripSize(this);
      76             : }
      77             : 
      78           0 : SvxXMeasurePreview::~SvxXMeasurePreview()
      79             : {
      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           0 :     delete pMeasureObj;
      86             : 
      87           0 :     delete pModel;
      88           0 : }
      89             : 
      90           0 : void SvxXMeasurePreview::Paint( const Rectangle&  )
      91             : {
      92           0 :     pMeasureObj->SingleObjectPainter(*this);
      93           0 : }
      94             : 
      95           0 : void SvxXMeasurePreview::SetAttributes( const SfxItemSet& rInAttrs )
      96             : {
      97           0 :     pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
      98             : 
      99           0 :     Invalidate();
     100           0 : }
     101             : 
     102           0 : void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
     103             : {
     104           0 :     bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
     105           0 :     bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
     106           0 :     sal_Bool bCtrl    = rMEvt.IsMod1();
     107             : 
     108           0 :     if( bZoomIn || bZoomOut )
     109             :     {
     110           0 :         MapMode aMapMode = GetMapMode();
     111           0 :         Fraction aXFrac = aMapMode.GetScaleX();
     112           0 :         Fraction aYFrac = aMapMode.GetScaleY();
     113             :         Fraction* pMultFrac;
     114             : 
     115           0 :         if( bZoomIn )
     116             :         {
     117           0 :             if( bCtrl )
     118           0 :                 pMultFrac = new Fraction( 3, 2 );
     119             :             else
     120           0 :                 pMultFrac = new Fraction( 11, 10 );
     121             :         }
     122             :         else
     123             :         {
     124           0 :             if( bCtrl )
     125           0 :                 pMultFrac = new Fraction( 2, 3 );
     126             :             else
     127           0 :                 pMultFrac = new Fraction( 10, 11 );
     128             :         }
     129             : 
     130           0 :         aXFrac *= *pMultFrac;
     131           0 :         aYFrac *= *pMultFrac;
     132           0 :         if( (double)aXFrac > 0.001 && (double)aXFrac < 1000.0 &&
     133           0 :             (double)aYFrac > 0.001 && (double)aYFrac < 1000.0 )
     134             :         {
     135           0 :             aMapMode.SetScaleX( aXFrac );
     136           0 :             aMapMode.SetScaleY( aYFrac );
     137           0 :             SetMapMode( aMapMode );
     138             : 
     139           0 :             Size aOutSize( GetOutputSize() );
     140             : 
     141           0 :             Point aPt( aMapMode.GetOrigin() );
     142           0 :             long nX = (long)( ( (double)aOutSize.Width() - ( (double)aOutSize.Width() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     143           0 :             long nY = (long)( ( (double)aOutSize.Height() - ( (double)aOutSize.Height() * (double)*pMultFrac  ) ) / 2.0 + 0.5 );
     144           0 :             aPt.X() +=  nX;
     145           0 :             aPt.Y() +=  nY;
     146             : 
     147           0 :             aMapMode.SetOrigin( aPt );
     148           0 :             SetMapMode( aMapMode );
     149             : 
     150           0 :             Invalidate();
     151             :         }
     152           0 :         delete pMultFrac;
     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           0 : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10