Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / printopt.cxx
blobbe1da7e93e49cec7e0c72bb18283cd63daa5f1b7
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>
23 #include "printopt.hxx"
24 #include "miscuno.hxx"
26 using namespace utl;
27 using namespace com::sun::star::uno;
29 TYPEINIT1(ScTpPrintItem, SfxPoolItem);
31 ScPrintOptions::ScPrintOptions()
33 SetDefaults();
36 ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
37 bSkipEmpty( rCpy.bSkipEmpty ),
38 bAllSheets( rCpy.bAllSheets ),
39 bForceBreaks( rCpy.bForceBreaks )
43 ScPrintOptions::~ScPrintOptions()
47 void ScPrintOptions::SetDefaults()
49 bSkipEmpty = sal_True;
50 bAllSheets = false;
51 bForceBreaks = false;
54 const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
56 bSkipEmpty = rCpy.bSkipEmpty;
57 bAllSheets = rCpy.bAllSheets;
58 bForceBreaks = rCpy.bForceBreaks;
59 return *this;
62 bool ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
64 return bSkipEmpty == rOpt.bSkipEmpty
65 && bAllSheets == rOpt.bAllSheets
66 && bForceBreaks == rOpt.bForceBreaks;
69 bool ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
71 return !(operator==(rOpt));
74 ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
75 SfxPoolItem ( nWhichP ),
76 theOptions ( rOpt )
80 ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
81 SfxPoolItem ( rItem ),
82 theOptions ( rItem.theOptions )
86 ScTpPrintItem::~ScTpPrintItem()
90 OUString ScTpPrintItem::GetValueText() const
92 return OUString("ScTpPrintItem");
95 int ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
97 OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
99 const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
100 return ( theOptions == rPItem.theOptions );
103 SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
105 return new ScTpPrintItem( *this );
108 #define CFGPATH_PRINT "Office.Calc/Print"
110 #define SCPRINTOPT_EMPTYPAGES 0
111 #define SCPRINTOPT_ALLSHEETS 1
112 #define SCPRINTOPT_FORCEBREAKS 2
113 #define SCPRINTOPT_COUNT 3
115 Sequence<OUString> ScPrintCfg::GetPropertyNames()
117 static const char* aPropNames[] =
119 "Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
120 "Other/AllSheets", // SCPRINTOPT_ALLSHEETS
121 "Page/ForceBreaks" // SCPRINTOPT_FORCEBREAKS
123 Sequence<OUString> aNames(SCPRINTOPT_COUNT);
124 OUString* pNames = aNames.getArray();
125 for(int i = 0; i < SCPRINTOPT_COUNT; i++)
126 pNames[i] = OUString::createFromAscii(aPropNames[i]);
128 return aNames;
131 ScPrintCfg::ScPrintCfg() :
132 ConfigItem( OUString( CFGPATH_PRINT ) )
134 Sequence<OUString> aNames = GetPropertyNames();
135 Sequence<Any> aValues = GetProperties(aNames);
136 const Any* pValues = aValues.getConstArray();
137 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
138 if(aValues.getLength() == aNames.getLength())
140 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
142 OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
143 if(pValues[nProp].hasValue())
145 switch(nProp)
147 case SCPRINTOPT_EMPTYPAGES:
148 // reversed
149 SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
150 break;
151 case SCPRINTOPT_ALLSHEETS:
152 SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
153 break;
154 case SCPRINTOPT_FORCEBREAKS:
155 SetForceBreaks( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
156 break;
163 void ScPrintCfg::Commit()
165 Sequence<OUString> aNames = GetPropertyNames();
166 Sequence<Any> aValues(aNames.getLength());
167 Any* pValues = aValues.getArray();
169 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
171 switch(nProp)
173 case SCPRINTOPT_EMPTYPAGES:
174 // reversed
175 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
176 break;
177 case SCPRINTOPT_ALLSHEETS:
178 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
179 break;
180 case SCPRINTOPT_FORCEBREAKS:
181 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetForceBreaks() );
182 break;
185 PutProperties(aNames, aValues);
188 void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
190 *(ScPrintOptions*)this = rNew;
191 SetModified();
194 void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */