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