fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / tool / printopt.cxx
blob209b8968614edd9120986e295dfe86bc83070114
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
22 #include <osl/diagnose.h>
24 #include "printopt.hxx"
25 #include "miscuno.hxx"
27 using namespace utl;
28 using namespace com::sun::star::uno;
30 TYPEINIT1(ScTpPrintItem, SfxPoolItem);
32 ScPrintOptions::ScPrintOptions()
34 SetDefaults();
37 ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
38 bSkipEmpty( rCpy.bSkipEmpty ),
39 bAllSheets( rCpy.bAllSheets ),
40 bForceBreaks( rCpy.bForceBreaks )
44 ScPrintOptions::~ScPrintOptions()
48 void ScPrintOptions::SetDefaults()
50 bSkipEmpty = true;
51 bAllSheets = false;
52 bForceBreaks = false;
55 const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
57 bSkipEmpty = rCpy.bSkipEmpty;
58 bAllSheets = rCpy.bAllSheets;
59 bForceBreaks = rCpy.bForceBreaks;
60 return *this;
63 bool ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
65 return bSkipEmpty == rOpt.bSkipEmpty
66 && bAllSheets == rOpt.bAllSheets
67 && bForceBreaks == rOpt.bForceBreaks;
70 bool ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
72 return !(operator==(rOpt));
75 ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
76 SfxPoolItem ( nWhichP ),
77 theOptions ( rOpt )
81 ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
82 SfxPoolItem ( rItem ),
83 theOptions ( rItem.theOptions )
87 ScTpPrintItem::~ScTpPrintItem()
91 bool ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
93 assert(SfxPoolItem::operator==(rItem));
95 const ScTpPrintItem& rPItem = static_cast<const ScTpPrintItem&>(rItem);
96 return ( theOptions == rPItem.theOptions );
99 SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
101 return new ScTpPrintItem( *this );
104 #define CFGPATH_PRINT "Office.Calc/Print"
106 #define SCPRINTOPT_EMPTYPAGES 0
107 #define SCPRINTOPT_ALLSHEETS 1
108 #define SCPRINTOPT_FORCEBREAKS 2
109 #define SCPRINTOPT_COUNT 3
111 Sequence<OUString> ScPrintCfg::GetPropertyNames()
113 static const char* aPropNames[] =
115 "Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
116 "Other/AllSheets", // SCPRINTOPT_ALLSHEETS
117 "Page/ForceBreaks" // SCPRINTOPT_FORCEBREAKS
119 Sequence<OUString> aNames(SCPRINTOPT_COUNT);
120 OUString* pNames = aNames.getArray();
121 for(int i = 0; i < SCPRINTOPT_COUNT; i++)
122 pNames[i] = OUString::createFromAscii(aPropNames[i]);
124 return aNames;
127 ScPrintCfg::ScPrintCfg() :
128 ConfigItem( OUString( CFGPATH_PRINT ) )
130 Sequence<OUString> aNames = GetPropertyNames();
131 Sequence<Any> aValues = GetProperties(aNames);
132 const Any* pValues = aValues.getConstArray();
133 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
134 if(aValues.getLength() == aNames.getLength())
136 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
138 OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
139 if(pValues[nProp].hasValue())
141 switch(nProp)
143 case SCPRINTOPT_EMPTYPAGES:
144 // reversed
145 SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
146 break;
147 case SCPRINTOPT_ALLSHEETS:
148 SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
149 break;
150 case SCPRINTOPT_FORCEBREAKS:
151 SetForceBreaks( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
152 break;
159 void ScPrintCfg::ImplCommit()
161 Sequence<OUString> aNames = GetPropertyNames();
162 Sequence<Any> aValues(aNames.getLength());
163 Any* pValues = aValues.getArray();
165 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
167 switch(nProp)
169 case SCPRINTOPT_EMPTYPAGES:
170 // reversed
171 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
172 break;
173 case SCPRINTOPT_ALLSHEETS:
174 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
175 break;
176 case SCPRINTOPT_FORCEBREAKS:
177 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetForceBreaks() );
178 break;
181 PutProperties(aNames, aValues);
184 void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
186 *(ScPrintOptions*)this = rNew;
187 SetModified();
190 void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */