LCOV - code coverage report
Current view: top level - svx/source/items - viewlayoutitem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 47 66 71.2 %
Date: 2015-06-13 12:38:46 Functions: 13 15 86.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 <tools/stream.hxx>
      21             : 
      22             : #include <svx/viewlayoutitem.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : 
      26             : #include <osl/diagnose.h>
      27             : 
      28             : 
      29        6560 : TYPEINIT1_FACTORY(SvxViewLayoutItem,SfxUInt16Item, new SvxViewLayoutItem);
      30             : 
      31             : #define VIEWLAYOUT_PARAM_COLUMNS    "Columns"
      32             : #define VIEWLAYOUT_PARAM_BOOKMODE   "BookMode"
      33             : #define VIEWLAYOUT_PARAMS           2
      34             : 
      35             : 
      36             : 
      37        1478 : SvxViewLayoutItem::SvxViewLayoutItem
      38             : (
      39             :     sal_uInt16      nColumns,
      40             :     bool        bBookMode,
      41             :     sal_uInt16  _nWhich
      42             : )
      43             : :   SfxUInt16Item( _nWhich, nColumns ),
      44        1478 :     mbBookMode( bBookMode )
      45             : {
      46        1478 : }
      47             : 
      48             : 
      49             : 
      50        1742 : SvxViewLayoutItem::SvxViewLayoutItem( const SvxViewLayoutItem& rOrig )
      51        3484 : :   SfxUInt16Item( rOrig.Which(), rOrig.GetValue() ),
      52        3484 :     mbBookMode( rOrig.IsBookMode() )
      53             : {
      54        1742 : }
      55             : 
      56             : 
      57             : 
      58        5570 : SvxViewLayoutItem::~SvxViewLayoutItem()
      59             : {
      60        5570 : }
      61             : 
      62             : 
      63             : 
      64        1742 : SfxPoolItem* SvxViewLayoutItem::Clone( SfxItemPool * /*pPool*/ ) const
      65             : {
      66        1742 :     return new SvxViewLayoutItem( *this );
      67             : }
      68             : 
      69             : 
      70             : 
      71           0 : SfxPoolItem* SvxViewLayoutItem::Create( SvStream& /*rStrm*/, sal_uInt16 /*nVersion*/ ) const
      72             : {
      73           0 :     return 0;
      74             : }
      75             : 
      76             : 
      77             : 
      78           0 : SvStream& SvxViewLayoutItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
      79             : {
      80           0 :     return rStrm;
      81             : }
      82             : 
      83             : 
      84             : 
      85         262 : bool SvxViewLayoutItem::operator==( const SfxPoolItem& rAttr ) const
      86             : {
      87             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
      88             : 
      89         262 :     const SvxViewLayoutItem& rItem = static_cast<const SvxViewLayoutItem&>(rAttr);
      90             : 
      91         524 :     return ( GetValue() == rItem.GetValue()     &&
      92         524 :              mbBookMode == rItem.IsBookMode() );
      93             : }
      94             : 
      95         608 : bool SvxViewLayoutItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
      96             : {
      97         608 :     nMemberId &= ~CONVERT_TWIPS;
      98         608 :     switch ( nMemberId )
      99             :     {
     100             :         case 0 :
     101             :         {
     102         608 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq( VIEWLAYOUT_PARAMS );
     103         608 :             aSeq[0].Name = VIEWLAYOUT_PARAM_COLUMNS;
     104         608 :             aSeq[0].Value <<= sal_Int32( GetValue() );
     105         608 :             aSeq[1].Name = VIEWLAYOUT_PARAM_BOOKMODE;
     106         608 :             aSeq[1].Value <<= mbBookMode;
     107         608 :             rVal <<= aSeq;
     108             :         }
     109         608 :         break;
     110             : 
     111           0 :         case MID_VIEWLAYOUT_COLUMNS : rVal <<= (sal_Int32) GetValue(); break;
     112           0 :         case MID_VIEWLAYOUT_BOOKMODE: rVal <<= mbBookMode; break;
     113             :         default:
     114             :             OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
     115           0 :             return false;
     116             :     }
     117             : 
     118         608 :     return true;
     119             : }
     120             : 
     121         608 : bool SvxViewLayoutItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
     122             : {
     123         608 :     nMemberId &= ~CONVERT_TWIPS;
     124         608 :     switch ( nMemberId )
     125             :     {
     126             :         case 0 :
     127             :         {
     128         608 :             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSeq;
     129         608 :             if (( rVal >>= aSeq ) && ( aSeq.getLength() == VIEWLAYOUT_PARAMS ))
     130             :             {
     131         608 :                 sal_Int32 nColumns( 0 );
     132         608 :                 bool  bBookMode = false;
     133         608 :                 bool bAllConverted( true );
     134         608 :                 sal_Int16 nConvertedCount( 0 );
     135        1824 :                 for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
     136             :                 {
     137        1216 :                     if ( aSeq[i].Name == VIEWLAYOUT_PARAM_COLUMNS )
     138             :                     {
     139         608 :                         bAllConverted &= ( aSeq[i].Value >>= nColumns );
     140         608 :                         ++nConvertedCount;
     141             :                     }
     142         608 :                     else if ( aSeq[i].Name == VIEWLAYOUT_PARAM_BOOKMODE )
     143             :                     {
     144         608 :                         bAllConverted &= ( aSeq[i].Value >>= bBookMode );
     145         608 :                         ++nConvertedCount;
     146             :                     }
     147             :                 }
     148             : 
     149         608 :                 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
     150             :                 {
     151         608 :                     SetValue( (sal_uInt16)nColumns );
     152         608 :                     mbBookMode = bBookMode;
     153         608 :                     return true;
     154             :                 }
     155             :             }
     156             : 
     157           0 :             return false;
     158             :         }
     159             : 
     160             :         case MID_VIEWLAYOUT_COLUMNS:
     161             :         {
     162           0 :             sal_Int32 nVal = 0;
     163           0 :             if ( rVal >>= nVal )
     164             :             {
     165           0 :                 SetValue( (sal_uInt16)nVal );
     166           0 :                 return true;
     167             :             }
     168             :             else
     169           0 :                 return false;
     170             :         }
     171             : 
     172             :         case MID_VIEWLAYOUT_BOOKMODE:
     173             :         {
     174           0 :             bool bBookMode = false;
     175           0 :             if ( rVal >>= bBookMode )
     176             :             {
     177           0 :                 mbBookMode = bBookMode;
     178           0 :                 return true;
     179             :             }
     180             :             else
     181           0 :                 return false;
     182             :         }
     183             : 
     184             :         default:
     185             :             OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
     186           0 :             return false;
     187             :     }
     188             : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11