LCOV - code coverage report
Current view: top level - sc/source/core/tool - printopt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 59 80 73.8 %
Date: 2015-06-13 12:38:46 Functions: 9 23 39.1 %
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 <com/sun/star/uno/Any.hxx>
      21             : #include <com/sun/star/uno/Sequence.hxx>
      22             : #include <osl/diagnose.h>
      23             : 
      24             : #include "printopt.hxx"
      25             : #include "miscuno.hxx"
      26             : 
      27             : using namespace utl;
      28             : using namespace com::sun::star::uno;
      29             : 
      30           0 : TYPEINIT1(ScTpPrintItem, SfxPoolItem);
      31             : 
      32           9 : ScPrintOptions::ScPrintOptions()
      33             : {
      34           9 :     SetDefaults();
      35           9 : }
      36             : 
      37          65 : ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
      38             :     bSkipEmpty( rCpy.bSkipEmpty ),
      39             :     bAllSheets( rCpy.bAllSheets ),
      40          65 :     bForceBreaks( rCpy.bForceBreaks )
      41             : {
      42          65 : }
      43             : 
      44          69 : ScPrintOptions::~ScPrintOptions()
      45             : {
      46          69 : }
      47             : 
      48           9 : void ScPrintOptions::SetDefaults()
      49             : {
      50           9 :     bSkipEmpty = true;
      51           9 :     bAllSheets = false;
      52           9 :     bForceBreaks = false;
      53           9 : }
      54             : 
      55           6 : const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
      56             : {
      57           6 :     bSkipEmpty = rCpy.bSkipEmpty;
      58           6 :     bAllSheets = rCpy.bAllSheets;
      59           6 :     bForceBreaks = rCpy.bForceBreaks;
      60           6 :     return *this;
      61             : }
      62             : 
      63           0 : bool ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
      64             : {
      65           0 :     return bSkipEmpty == rOpt.bSkipEmpty
      66           0 :         && bAllSheets == rOpt.bAllSheets
      67           0 :         && bForceBreaks == rOpt.bForceBreaks;
      68             : }
      69             : 
      70           0 : bool ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
      71             : {
      72           0 :     return !(operator==(rOpt));
      73             : }
      74             : 
      75           0 : ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
      76             :     SfxPoolItem ( nWhichP ),
      77           0 :     theOptions  ( rOpt )
      78             : {
      79           0 : }
      80             : 
      81           0 : ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
      82             :     SfxPoolItem ( rItem ),
      83           0 :     theOptions  ( rItem.theOptions )
      84             : {
      85           0 : }
      86             : 
      87           0 : ScTpPrintItem::~ScTpPrintItem()
      88             : {
      89           0 : }
      90             : 
      91           0 : bool ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
      92             : {
      93             :     assert(SfxPoolItem::operator==(rItem));
      94             : 
      95           0 :     const ScTpPrintItem& rPItem = static_cast<const ScTpPrintItem&>(rItem);
      96           0 :     return ( theOptions == rPItem.theOptions );
      97             : }
      98             : 
      99           0 : SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
     100             : {
     101           0 :     return new ScTpPrintItem( *this );
     102             : }
     103             : 
     104             : #define CFGPATH_PRINT           "Office.Calc/Print"
     105             : 
     106             : #define SCPRINTOPT_EMPTYPAGES       0
     107             : #define SCPRINTOPT_ALLSHEETS        1
     108             : #define SCPRINTOPT_FORCEBREAKS      2
     109             : #define SCPRINTOPT_COUNT            3
     110             : 
     111          10 : Sequence<OUString> ScPrintCfg::GetPropertyNames()
     112             : {
     113             :     static const char* aPropNames[] =
     114             :     {
     115             :         "Page/EmptyPages",          // SCPRINTOPT_EMPTYPAGES
     116             :         "Other/AllSheets",          // SCPRINTOPT_ALLSHEETS
     117             :         "Page/ForceBreaks"          // SCPRINTOPT_FORCEBREAKS
     118             :     };
     119          10 :     Sequence<OUString> aNames(SCPRINTOPT_COUNT);
     120          10 :     OUString* pNames = aNames.getArray();
     121          40 :     for(int i = 0; i < SCPRINTOPT_COUNT; i++)
     122          30 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     123             : 
     124          10 :     return aNames;
     125             : }
     126             : 
     127           9 : ScPrintCfg::ScPrintCfg() :
     128           9 :     ConfigItem( OUString( CFGPATH_PRINT ) )
     129             : {
     130           9 :     Sequence<OUString> aNames = GetPropertyNames();
     131          18 :     Sequence<Any> aValues = GetProperties(aNames);
     132           9 :     const Any* pValues = aValues.getConstArray();
     133             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
     134           9 :     if(aValues.getLength() == aNames.getLength())
     135             :     {
     136          36 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     137             :         {
     138             :             OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
     139          27 :             if(pValues[nProp].hasValue())
     140             :             {
     141          27 :                 switch(nProp)
     142             :                 {
     143             :                     case SCPRINTOPT_EMPTYPAGES:
     144             :                         // reversed
     145           9 :                         SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     146           9 :                         break;
     147             :                     case SCPRINTOPT_ALLSHEETS:
     148           9 :                         SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     149           9 :                         break;
     150             :                     case SCPRINTOPT_FORCEBREAKS:
     151           9 :                         SetForceBreaks( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     152           9 :                         break;
     153             :                 }
     154             :             }
     155             :         }
     156           9 :     }
     157           9 : }
     158             : 
     159           1 : void ScPrintCfg::ImplCommit()
     160             : {
     161           1 :     Sequence<OUString> aNames = GetPropertyNames();
     162           2 :     Sequence<Any> aValues(aNames.getLength());
     163           1 :     Any* pValues = aValues.getArray();
     164             : 
     165           4 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     166             :     {
     167           3 :         switch(nProp)
     168             :         {
     169             :             case SCPRINTOPT_EMPTYPAGES:
     170             :                 // reversed
     171           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
     172           1 :                 break;
     173             :             case SCPRINTOPT_ALLSHEETS:
     174           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
     175           1 :                 break;
     176             :             case SCPRINTOPT_FORCEBREAKS:
     177           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetForceBreaks() );
     178           1 :                 break;
     179             :         }
     180             :     }
     181           2 :     PutProperties(aNames, aValues);
     182           1 : }
     183             : 
     184           6 : void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
     185             : {
     186           6 :     *static_cast<ScPrintOptions*>(this) = rNew;
     187           6 :     SetModified();
     188           6 : }
     189             : 
     190           0 : void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11