LCOV - code coverage report
Current view: top level - vcl/source/gdi - mapmod.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 118 0.0 %
Date: 2014-04-14 Functions: 0 20 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 <tools/stream.hxx>
      21             : #include <tools/vcompat.hxx>
      22             : #include <tools/debug.hxx>
      23             : #include <vcl/mapmod.hxx>
      24             : 
      25           0 : ImplMapMode::ImplMapMode() :
      26             :     maOrigin( 0, 0 ),
      27             :     maScaleX( 1, 1 ),
      28           0 :     maScaleY( 1, 1 )
      29             : {
      30           0 :     mnRefCount  = 1;
      31           0 :     meUnit      = MAP_PIXEL;
      32           0 :     mbSimple    = false;
      33           0 : }
      34             : 
      35           0 : ImplMapMode::ImplMapMode( const ImplMapMode& rImplMapMode ) :
      36             :     maOrigin( rImplMapMode.maOrigin ),
      37             :     maScaleX( rImplMapMode.maScaleX ),
      38           0 :     maScaleY( rImplMapMode.maScaleY )
      39             : {
      40           0 :     mnRefCount      = 1;
      41           0 :     meUnit          = rImplMapMode.meUnit;
      42           0 :     mbSimple        = false;
      43           0 : }
      44             : 
      45           0 : SvStream& ReadImplMapMode( SvStream& rIStm, ImplMapMode& rImplMapMode )
      46             : {
      47           0 :     VersionCompat   aCompat( rIStm, STREAM_READ );
      48             :     sal_uInt16          nTmp16;
      49             : 
      50           0 :     rIStm.ReadUInt16( nTmp16 ); rImplMapMode.meUnit = (MapUnit) nTmp16;
      51           0 :     ReadPair( rIStm, rImplMapMode.maOrigin );
      52           0 :     ReadFraction( rIStm, rImplMapMode.maScaleX );
      53           0 :     ReadFraction( rIStm, rImplMapMode.maScaleY );
      54           0 :     rIStm.ReadCharAsBool( rImplMapMode.mbSimple );
      55             : 
      56           0 :     return rIStm;
      57             : }
      58             : 
      59           0 : SvStream& WriteImplMapMode( SvStream& rOStm, const ImplMapMode& rImplMapMode )
      60             : {
      61           0 :     VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
      62             : 
      63           0 :     rOStm.WriteUInt16( (sal_uInt16) rImplMapMode.meUnit );
      64           0 :     WritePair( rOStm, rImplMapMode.maOrigin );
      65           0 :     WriteFraction( rOStm, rImplMapMode.maScaleX );
      66           0 :     WriteFraction( rOStm, rImplMapMode.maScaleY );
      67           0 :     rOStm.WriteUChar( rImplMapMode.mbSimple );
      68             : 
      69           0 :     return rOStm;
      70             : }
      71             : 
      72           0 : ImplMapMode* ImplMapMode::ImplGetStaticMapMode( MapUnit eUnit )
      73             : {
      74             :     static long aStaticImplMapModeAry[(MAP_LASTENUMDUMMY)*sizeof(ImplMapMode)/sizeof(long)];
      75             : 
      76             :     // #i19496 check for out-of-bounds
      77           0 :      if( eUnit >= MAP_LASTENUMDUMMY )
      78           0 :         return (ImplMapMode*)aStaticImplMapModeAry;
      79             : 
      80           0 :     ImplMapMode* pImplMapMode = ((ImplMapMode*)aStaticImplMapModeAry)+eUnit;
      81           0 :     if ( !pImplMapMode->mbSimple )
      82             :     {
      83           0 :         Fraction aDefFraction( 1, 1 );
      84           0 :         pImplMapMode->maScaleX  = aDefFraction;
      85           0 :         pImplMapMode->maScaleY  = aDefFraction;
      86           0 :         pImplMapMode->meUnit    = eUnit;
      87           0 :         pImplMapMode->mbSimple  = true;
      88             :     }
      89             : 
      90           0 :     return pImplMapMode;
      91             : }
      92             : 
      93           0 : inline void MapMode::ImplMakeUnique()
      94             : {
      95             :     // If there are other references, copy
      96           0 :     if ( mpImplMapMode->mnRefCount != 1 )
      97             :     {
      98           0 :         if ( mpImplMapMode->mnRefCount )
      99           0 :             mpImplMapMode->mnRefCount--;
     100           0 :         mpImplMapMode = new ImplMapMode( *mpImplMapMode );
     101             :     }
     102           0 : }
     103             : 
     104           0 : MapMode::MapMode()
     105             : {
     106             : 
     107           0 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     108           0 : }
     109             : 
     110           0 : MapMode::MapMode( const MapMode& rMapMode )
     111             : {
     112             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     113             : 
     114             :     // Take over Shared Instance Data and increment refcount
     115           0 :     mpImplMapMode = rMapMode.mpImplMapMode;
     116             :     // RefCount == 0 for static objects
     117           0 :     if ( mpImplMapMode->mnRefCount )
     118           0 :         mpImplMapMode->mnRefCount++;
     119           0 : }
     120             : 
     121           0 : MapMode::MapMode( MapUnit eUnit )
     122             : {
     123             : 
     124           0 :     mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( eUnit );
     125           0 : }
     126             : 
     127           0 : MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
     128             :                   const Fraction& rScaleX, const Fraction& rScaleY )
     129             : {
     130             : 
     131           0 :     mpImplMapMode           = new ImplMapMode;
     132           0 :     mpImplMapMode->meUnit   = eUnit;
     133           0 :     mpImplMapMode->maOrigin = rLogicOrg;
     134           0 :     mpImplMapMode->maScaleX = rScaleX;
     135           0 :     mpImplMapMode->maScaleY = rScaleY;
     136           0 : }
     137             : 
     138           0 : MapMode::~MapMode()
     139             : {
     140             : 
     141             :     // If it's not static ImpData and it's the last reference, delete it,
     142             :     // else decrement refcounter
     143           0 :     if ( mpImplMapMode->mnRefCount )
     144             :     {
     145           0 :         if ( mpImplMapMode->mnRefCount == 1 )
     146           0 :             delete mpImplMapMode;
     147             :         else
     148           0 :             mpImplMapMode->mnRefCount--;
     149             :     }
     150           0 : }
     151             : 
     152           0 : void MapMode::SetMapUnit( MapUnit eUnit )
     153             : {
     154             : 
     155           0 :     ImplMakeUnique();
     156           0 :     mpImplMapMode->meUnit = eUnit;
     157           0 : }
     158             : 
     159           0 : void MapMode::SetOrigin( const Point& rLogicOrg )
     160             : {
     161             : 
     162           0 :     ImplMakeUnique();
     163           0 :     mpImplMapMode->maOrigin = rLogicOrg;
     164           0 : }
     165             : 
     166           0 : void MapMode::SetScaleX( const Fraction& rScaleX )
     167             : {
     168             : 
     169           0 :     ImplMakeUnique();
     170           0 :     mpImplMapMode->maScaleX = rScaleX;
     171           0 : }
     172             : 
     173           0 : void MapMode::SetScaleY( const Fraction& rScaleY )
     174             : {
     175             : 
     176           0 :     ImplMakeUnique();
     177           0 :     mpImplMapMode->maScaleY = rScaleY;
     178           0 : }
     179             : 
     180           0 : MapMode& MapMode::operator=( const MapMode& rMapMode )
     181             : {
     182             :     DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
     183             : 
     184             :     // First increment refcount so that we can reference ourselves
     185             :     // RefCount == 0 for static objects
     186           0 :     if ( rMapMode.mpImplMapMode->mnRefCount )
     187           0 :         rMapMode.mpImplMapMode->mnRefCount++;
     188             : 
     189             :     // If it's not static ImpData and it's the last reference, delete it,
     190             :     // else decrement refcounter
     191           0 :     if ( mpImplMapMode->mnRefCount )
     192             :     {
     193           0 :         if ( mpImplMapMode->mnRefCount == 1 )
     194           0 :             delete mpImplMapMode;
     195             :         else
     196           0 :             mpImplMapMode->mnRefCount--;
     197             :     }
     198             : 
     199           0 :     mpImplMapMode = rMapMode.mpImplMapMode;
     200             : 
     201           0 :     return *this;
     202             : }
     203             : 
     204           0 : bool MapMode::operator==( const MapMode& rMapMode ) const
     205             : {
     206             : 
     207           0 :     if ( mpImplMapMode == rMapMode.mpImplMapMode )
     208           0 :         return true;
     209             : 
     210           0 :     if ( (mpImplMapMode->meUnit   == rMapMode.mpImplMapMode->meUnit)   &&
     211           0 :          (mpImplMapMode->maOrigin == rMapMode.mpImplMapMode->maOrigin) &&
     212           0 :          (mpImplMapMode->maScaleX == rMapMode.mpImplMapMode->maScaleX) &&
     213           0 :          (mpImplMapMode->maScaleY == rMapMode.mpImplMapMode->maScaleY) )
     214           0 :         return true;
     215             :     else
     216           0 :         return false;
     217             : }
     218             : 
     219           0 : bool MapMode::IsDefault() const
     220             : {
     221             : 
     222           0 :     ImplMapMode* pDefMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
     223           0 :     if ( mpImplMapMode == pDefMapMode )
     224           0 :         return true;
     225             : 
     226           0 :     if ( (mpImplMapMode->meUnit   == pDefMapMode->meUnit)   &&
     227           0 :          (mpImplMapMode->maOrigin == pDefMapMode->maOrigin) &&
     228           0 :          (mpImplMapMode->maScaleX == pDefMapMode->maScaleX) &&
     229           0 :          (mpImplMapMode->maScaleY == pDefMapMode->maScaleY) )
     230           0 :         return true;
     231             :     else
     232           0 :         return false;
     233             : }
     234             : 
     235           0 : SvStream& ReadMapMode( SvStream& rIStm, MapMode& rMapMode )
     236             : {
     237           0 :     rMapMode.ImplMakeUnique();
     238           0 :     return ReadImplMapMode( rIStm, *rMapMode.mpImplMapMode );
     239             : }
     240             : 
     241           0 : SvStream& WriteMapMode( SvStream& rOStm, const MapMode& rMapMode )
     242             : {
     243           0 :     return WriteImplMapMode( rOStm, *rMapMode.mpImplMapMode );
     244             : }
     245             : 
     246             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10