xref: /aoo41x/main/sc/source/core/tool/printopt.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "printopt.hxx"
33cdf0e10cSrcweir #include "miscuno.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace utl;
36cdf0e10cSrcweir using namespace rtl;
37cdf0e10cSrcweir using namespace com::sun::star::uno;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // -----------------------------------------------------------------------
40cdf0e10cSrcweir 
41cdf0e10cSrcweir TYPEINIT1(ScTpPrintItem, SfxPoolItem);
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // -----------------------------------------------------------------------
44cdf0e10cSrcweir 
ScPrintOptions()45cdf0e10cSrcweir ScPrintOptions::ScPrintOptions()
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	SetDefaults();
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
ScPrintOptions(const ScPrintOptions & rCpy)50cdf0e10cSrcweir ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
51cdf0e10cSrcweir 	bSkipEmpty( rCpy.bSkipEmpty ),
52cdf0e10cSrcweir 	bAllSheets( rCpy.bAllSheets )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
~ScPrintOptions()56cdf0e10cSrcweir ScPrintOptions::~ScPrintOptions()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
SetDefaults()60cdf0e10cSrcweir void ScPrintOptions::SetDefaults()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	bSkipEmpty = sal_True;
63cdf0e10cSrcweir 	bAllSheets = sal_False;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
operator =(const ScPrintOptions & rCpy)66cdf0e10cSrcweir const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	bSkipEmpty = rCpy.bSkipEmpty;
69cdf0e10cSrcweir 	bAllSheets = rCpy.bAllSheets;
70cdf0e10cSrcweir 	return *this;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
operator ==(const ScPrintOptions & rOpt) const73cdf0e10cSrcweir int ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	return bSkipEmpty == rOpt.bSkipEmpty
76cdf0e10cSrcweir 		&& bAllSheets == rOpt.bAllSheets;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
operator !=(const ScPrintOptions & rOpt) const79cdf0e10cSrcweir int ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	return !(operator==(rOpt));
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // -----------------------------------------------------------------------
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //UNUSED2008-05  ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP ) : SfxPoolItem( nWhichP )
87cdf0e10cSrcweir //UNUSED2008-05  {
88cdf0e10cSrcweir //UNUSED2008-05  }
89cdf0e10cSrcweir 
ScTpPrintItem(sal_uInt16 nWhichP,const ScPrintOptions & rOpt)90cdf0e10cSrcweir ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
91cdf0e10cSrcweir     SfxPoolItem ( nWhichP ),
92cdf0e10cSrcweir 	theOptions	( rOpt )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
ScTpPrintItem(const ScTpPrintItem & rItem)96cdf0e10cSrcweir ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
97cdf0e10cSrcweir 	SfxPoolItem	( rItem ),
98cdf0e10cSrcweir 	theOptions	( rItem.theOptions )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
~ScTpPrintItem()102cdf0e10cSrcweir ScTpPrintItem::~ScTpPrintItem()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
GetValueText() const106cdf0e10cSrcweir String ScTpPrintItem::GetValueText() const
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return String::CreateFromAscii( "ScTpPrintItem" );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rItem) const111cdf0e10cSrcweir int ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
116cdf0e10cSrcweir 	return ( theOptions == rPItem.theOptions );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
Clone(SfxItemPool *) const119cdf0e10cSrcweir SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	return new ScTpPrintItem( *this );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // -----------------------------------------------------------------------
125cdf0e10cSrcweir 
126cdf0e10cSrcweir #define CFGPATH_PRINT			"Office.Calc/Print"
127cdf0e10cSrcweir 
128cdf0e10cSrcweir #define SCPRINTOPT_EMPTYPAGES		0
129cdf0e10cSrcweir #define SCPRINTOPT_ALLSHEETS		1
130cdf0e10cSrcweir #define SCPRINTOPT_COUNT			2
131cdf0e10cSrcweir 
GetPropertyNames()132cdf0e10cSrcweir Sequence<OUString> ScPrintCfg::GetPropertyNames()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	static const char* aPropNames[] =
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir 		"Page/EmptyPages",			// SCPRINTOPT_EMPTYPAGES
137cdf0e10cSrcweir 		"Other/AllSheets"			// SCPRINTOPT_ALLSHEETS
138cdf0e10cSrcweir 	};
139cdf0e10cSrcweir 	Sequence<OUString> aNames(SCPRINTOPT_COUNT);
140cdf0e10cSrcweir 	OUString* pNames = aNames.getArray();
141cdf0e10cSrcweir 	for(int i = 0; i < SCPRINTOPT_COUNT; i++)
142cdf0e10cSrcweir 		pNames[i] = OUString::createFromAscii(aPropNames[i]);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	return aNames;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
ScPrintCfg()147cdf0e10cSrcweir ScPrintCfg::ScPrintCfg() :
148cdf0e10cSrcweir 	ConfigItem( OUString::createFromAscii( CFGPATH_PRINT ) )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	Sequence<OUString> aNames = GetPropertyNames();
151cdf0e10cSrcweir 	Sequence<Any> aValues = GetProperties(aNames);
152cdf0e10cSrcweir //	EnableNotification(aNames);
153cdf0e10cSrcweir 	const Any* pValues = aValues.getConstArray();
154cdf0e10cSrcweir 	DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
155cdf0e10cSrcweir 	if(aValues.getLength() == aNames.getLength())
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		for(int nProp = 0; nProp < aNames.getLength(); nProp++)
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			DBG_ASSERT(pValues[nProp].hasValue(), "property value missing");
160cdf0e10cSrcweir 			if(pValues[nProp].hasValue())
161cdf0e10cSrcweir 			{
162cdf0e10cSrcweir 				switch(nProp)
163cdf0e10cSrcweir 				{
164cdf0e10cSrcweir 					case SCPRINTOPT_EMPTYPAGES:
165cdf0e10cSrcweir 						// reversed
166cdf0e10cSrcweir 						SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
167cdf0e10cSrcweir 						break;
168cdf0e10cSrcweir 					case SCPRINTOPT_ALLSHEETS:
169cdf0e10cSrcweir 						SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
170cdf0e10cSrcweir 						break;
171cdf0e10cSrcweir 				}
172cdf0e10cSrcweir 			}
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
Commit()178cdf0e10cSrcweir void ScPrintCfg::Commit()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	Sequence<OUString> aNames = GetPropertyNames();
181cdf0e10cSrcweir 	Sequence<Any> aValues(aNames.getLength());
182cdf0e10cSrcweir 	Any* pValues = aValues.getArray();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	for(int nProp = 0; nProp < aNames.getLength(); nProp++)
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		switch(nProp)
187cdf0e10cSrcweir 		{
188cdf0e10cSrcweir 			case SCPRINTOPT_EMPTYPAGES:
189cdf0e10cSrcweir 				// reversed
190cdf0e10cSrcweir 				ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
191cdf0e10cSrcweir 				break;
192cdf0e10cSrcweir 			case SCPRINTOPT_ALLSHEETS:
193cdf0e10cSrcweir 				ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
194cdf0e10cSrcweir 				break;
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 	PutProperties(aNames, aValues);
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
SetOptions(const ScPrintOptions & rNew)200cdf0e10cSrcweir void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	*(ScPrintOptions*)this = rNew;
203cdf0e10cSrcweir 	SetModified();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
Notify(const::com::sun::star::uno::Sequence<rtl::OUString> &)206cdf0e10cSrcweir void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
207cdf0e10cSrcweir 
208