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

Generated by: LCOV version 1.10