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

Generated by: LCOV version 1.10