LCOV - code coverage report
Current view: top level - svx/source/dialog - measctrl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 89 1.1 %
Date: 2015-06-13 12:38:46 Functions: 2 13 15.4 %
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/builderfactory.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 :     bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
      50           0 :     SetDrawMode(bHighContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
      51             : 
      52           0 :     Invalidate();
      53           0 : }
      54             : 
      55           0 : void SvxXMeasurePreview::Resize()
      56             : {
      57           0 :     Control::Resize();
      58             : 
      59           0 :     Size aSize = GetOutputSize();
      60           0 :     Point aPt1 = Point(aSize.Width() / 5, (long) (aSize.Height() / 2));
      61           0 :     pMeasureObj->SetPoint(aPt1, 0);
      62           0 :     Point aPt2 = Point(aSize.Width() * 4 / 5, (long) (aSize.Height() / 2));
      63           0 :     pMeasureObj->SetPoint(aPt2, 1);
      64           0 : }
      65             : 
      66           0 : VCL_BUILDER_DECL_FACTORY(SvxXMeasurePreview)
      67             : {
      68           0 :     WinBits nWinStyle = 0;
      69           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      70           0 :     if (!sBorder.isEmpty())
      71           0 :         nWinStyle |= WB_BORDER;
      72           0 :     rRet = VclPtr<SvxXMeasurePreview>::Create(pParent, nWinStyle);
      73           0 : }
      74             : 
      75           0 : Size SvxXMeasurePreview::GetOptimalSize() const
      76             : {
      77           0 :     return getPreviewStripSize(this);
      78             : }
      79             : 
      80           0 : SvxXMeasurePreview::~SvxXMeasurePreview()
      81             : {
      82           0 :     disposeOnce();
      83           0 : }
      84             : 
      85           0 : void SvxXMeasurePreview::dispose()
      86             : {
      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),
      91             :     // delete it.
      92           0 :     delete pMeasureObj;
      93             : 
      94           0 :     delete pModel;
      95           0 :     Control::dispose();
      96           0 : }
      97             : 
      98           0 : void SvxXMeasurePreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
      99             : {
     100           0 :     pMeasureObj->SingleObjectPainter(rRenderContext);
     101           0 : }
     102             : 
     103           0 : void SvxXMeasurePreview::SetAttributes(const SfxItemSet& rInAttrs)
     104             : {
     105           0 :     pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
     106             : 
     107           0 :     Invalidate();
     108           0 : }
     109             : 
     110           0 : void SvxXMeasurePreview::MouseButtonDown(const MouseEvent& rMEvt)
     111             : {
     112           0 :     bool bZoomIn  = rMEvt.IsLeft() && !rMEvt.IsShift();
     113           0 :     bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
     114           0 :     bool bCtrl    = rMEvt.IsMod1();
     115             : 
     116           0 :     if (bZoomIn || bZoomOut)
     117             :     {
     118           0 :         MapMode aMapMode = GetMapMode();
     119           0 :         Fraction aXFrac = aMapMode.GetScaleX();
     120           0 :         Fraction aYFrac = aMapMode.GetScaleY();
     121           0 :         boost::scoped_ptr<Fraction> pMultFrac;
     122             : 
     123           0 :         if (bZoomIn)
     124             :         {
     125           0 :             if (bCtrl)
     126           0 :                 pMultFrac.reset(new Fraction(3, 2));
     127             :             else
     128           0 :                 pMultFrac.reset(new Fraction(11, 10));
     129             :         }
     130             :         else
     131             :         {
     132           0 :             if (bCtrl)
     133           0 :                 pMultFrac.reset(new Fraction(2, 3));
     134             :             else
     135           0 :                 pMultFrac.reset(new Fraction(10, 11));
     136             :         }
     137             : 
     138           0 :         aXFrac *= *pMultFrac;
     139           0 :         aYFrac *= *pMultFrac;
     140             : 
     141           0 :         if (double(aXFrac) > 0.001 && double(aXFrac) < 1000.0 &&
     142           0 :             double(aYFrac) > 0.001 && double(aYFrac) < 1000.0)
     143             :         {
     144           0 :             aMapMode.SetScaleX(aXFrac);
     145           0 :             aMapMode.SetScaleY(aYFrac);
     146           0 :             SetMapMode(aMapMode);
     147             : 
     148           0 :             Size aOutSize(GetOutputSize());
     149             : 
     150           0 :             Point aPt(aMapMode.GetOrigin());
     151           0 :             long nX = long((double(aOutSize.Width()) - (double(aOutSize.Width()) * double(*pMultFrac))) / 2.0 + 0.5);
     152           0 :             long nY = long((double(aOutSize.Height()) - (double(aOutSize.Height()) * double(*pMultFrac))) / 2.0 + 0.5);
     153           0 :             aPt.X() += nX;
     154           0 :             aPt.Y() += nY;
     155             : 
     156           0 :             aMapMode.SetOrigin(aPt);
     157           0 :             SetMapMode(aMapMode);
     158             : 
     159           0 :             Invalidate();
     160           0 :         }
     161             :     }
     162           0 : }
     163             : 
     164           0 : void SvxXMeasurePreview::DataChanged( const DataChangedEvent& rDCEvt )
     165             : {
     166           0 :     Control::DataChanged( rDCEvt );
     167             : 
     168           0 :     if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
     169             :     {
     170           0 :         bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
     171           0 :         SetDrawMode(bHighContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
     172             :     }
     173         390 : }
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11