Update ooo320-m1
[ooovba.git] / sc / source / core / tool / printopt.cxx
blobbc5f595df2b629074528d5c361fea82ff4bbdfab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: printopt.cxx,v $
10 * $Revision: 1.7.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
39 #include "printopt.hxx"
40 #include "miscuno.hxx"
42 using namespace utl;
43 using namespace rtl;
44 using namespace com::sun::star::uno;
46 // -----------------------------------------------------------------------
48 TYPEINIT1(ScTpPrintItem, SfxPoolItem);
50 // -----------------------------------------------------------------------
52 ScPrintOptions::ScPrintOptions()
54 SetDefaults();
57 ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
58 bSkipEmpty( rCpy.bSkipEmpty ),
59 bAllSheets( rCpy.bAllSheets )
63 ScPrintOptions::~ScPrintOptions()
67 void ScPrintOptions::SetDefaults()
69 bSkipEmpty = TRUE;
70 bAllSheets = FALSE;
73 const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
75 bSkipEmpty = rCpy.bSkipEmpty;
76 bAllSheets = rCpy.bAllSheets;
77 return *this;
80 inline int ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
82 return bSkipEmpty == rOpt.bSkipEmpty
83 && bAllSheets == rOpt.bAllSheets;
86 inline int ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
88 return !(operator==(rOpt));
91 // -----------------------------------------------------------------------
93 //UNUSED2008-05 ScTpPrintItem::ScTpPrintItem( USHORT nWhichP ) : SfxPoolItem( nWhichP )
94 //UNUSED2008-05 {
95 //UNUSED2008-05 }
97 ScTpPrintItem::ScTpPrintItem( USHORT nWhichP, const ScPrintOptions& rOpt ) :
98 SfxPoolItem ( nWhichP ),
99 theOptions ( rOpt )
103 ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
104 SfxPoolItem ( rItem ),
105 theOptions ( rItem.theOptions )
109 ScTpPrintItem::~ScTpPrintItem()
113 String ScTpPrintItem::GetValueText() const
115 return String::CreateFromAscii( "ScTpPrintItem" );
118 int ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
120 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
122 const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
123 return ( theOptions == rPItem.theOptions );
126 SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
128 return new ScTpPrintItem( *this );
131 // -----------------------------------------------------------------------
133 #define CFGPATH_PRINT "Office.Calc/Print"
135 #define SCPRINTOPT_EMPTYPAGES 0
136 #define SCPRINTOPT_ALLSHEETS 1
137 #define SCPRINTOPT_COUNT 2
139 Sequence<OUString> ScPrintCfg::GetPropertyNames()
141 static const char* aPropNames[] =
143 "Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
144 "Other/AllSheets" // SCPRINTOPT_ALLSHEETS
146 Sequence<OUString> aNames(SCPRINTOPT_COUNT);
147 OUString* pNames = aNames.getArray();
148 for(int i = 0; i < SCPRINTOPT_COUNT; i++)
149 pNames[i] = OUString::createFromAscii(aPropNames[i]);
151 return aNames;
154 ScPrintCfg::ScPrintCfg() :
155 ConfigItem( OUString::createFromAscii( CFGPATH_PRINT ) )
157 Sequence<OUString> aNames = GetPropertyNames();
158 Sequence<Any> aValues = GetProperties(aNames);
159 // EnableNotification(aNames);
160 const Any* pValues = aValues.getConstArray();
161 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
162 if(aValues.getLength() == aNames.getLength())
164 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
166 DBG_ASSERT(pValues[nProp].hasValue(), "property value missing");
167 if(pValues[nProp].hasValue())
169 switch(nProp)
171 case SCPRINTOPT_EMPTYPAGES:
172 // reversed
173 SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
174 break;
175 case SCPRINTOPT_ALLSHEETS:
176 SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
177 break;
185 void ScPrintCfg::Commit()
187 Sequence<OUString> aNames = GetPropertyNames();
188 Sequence<Any> aValues(aNames.getLength());
189 Any* pValues = aValues.getArray();
191 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
193 switch(nProp)
195 case SCPRINTOPT_EMPTYPAGES:
196 // reversed
197 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
198 break;
199 case SCPRINTOPT_ALLSHEETS:
200 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
201 break;
204 PutProperties(aNames, aValues);
207 void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
209 *(ScPrintOptions*)this = rNew;
210 SetModified();