Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
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 com::sun::star::uno;
37 : :
38 : : using ::rtl::OUString;
39 : :
40 : : // -----------------------------------------------------------------------
41 : :
42 [ # # ][ # # ]: 0 : TYPEINIT1(ScTpPrintItem, SfxPoolItem);
43 : :
44 : : // -----------------------------------------------------------------------
45 : :
46 : 2 : ScPrintOptions::ScPrintOptions()
47 : : {
48 : 2 : SetDefaults();
49 : 2 : }
50 : :
51 : 144 : ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
52 : : bSkipEmpty( rCpy.bSkipEmpty ),
53 : 144 : bAllSheets( rCpy.bAllSheets )
54 : : {
55 : 144 : }
56 : :
57 : 146 : ScPrintOptions::~ScPrintOptions()
58 : : {
59 : 146 : }
60 : :
61 : 2 : void ScPrintOptions::SetDefaults()
62 : : {
63 : 2 : bSkipEmpty = sal_True;
64 : 2 : bAllSheets = false;
65 : 2 : }
66 : :
67 : 6 : const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
68 : : {
69 : 6 : bSkipEmpty = rCpy.bSkipEmpty;
70 : 6 : bAllSheets = rCpy.bAllSheets;
71 : 6 : return *this;
72 : : }
73 : :
74 : 0 : bool ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
75 : : {
76 : : return bSkipEmpty == rOpt.bSkipEmpty
77 [ # # ][ # # ]: 0 : && bAllSheets == rOpt.bAllSheets;
78 : : }
79 : :
80 : 0 : bool ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
81 : : {
82 : 0 : return !(operator==(rOpt));
83 : : }
84 : :
85 : : // -----------------------------------------------------------------------
86 : :
87 : :
88 : 0 : ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
89 : : SfxPoolItem ( nWhichP ),
90 [ # # ]: 0 : theOptions ( rOpt )
91 : : {
92 : 0 : }
93 : :
94 : 0 : ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
95 : : SfxPoolItem ( rItem ),
96 [ # # ]: 0 : theOptions ( rItem.theOptions )
97 : : {
98 : 0 : }
99 : :
100 [ # # ]: 0 : ScTpPrintItem::~ScTpPrintItem()
101 : : {
102 [ # # ]: 0 : }
103 : :
104 : 0 : String ScTpPrintItem::GetValueText() const
105 : : {
106 [ # # ]: 0 : return rtl::OUString("ScTpPrintItem");
107 : : }
108 : :
109 : 0 : int ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
110 : : {
111 : : OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
112 : :
113 : 0 : const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
114 : 0 : return ( theOptions == rPItem.theOptions );
115 : : }
116 : :
117 : 0 : SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
118 : : {
119 [ # # ]: 0 : return new ScTpPrintItem( *this );
120 : : }
121 : :
122 : : // -----------------------------------------------------------------------
123 : :
124 : : #define CFGPATH_PRINT "Office.Calc/Print"
125 : :
126 : : #define SCPRINTOPT_EMPTYPAGES 0
127 : : #define SCPRINTOPT_ALLSHEETS 1
128 : : #define SCPRINTOPT_COUNT 2
129 : :
130 : 3 : Sequence<OUString> ScPrintCfg::GetPropertyNames()
131 : : {
132 : : static const char* aPropNames[] =
133 : : {
134 : : "Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
135 : : "Other/AllSheets" // SCPRINTOPT_ALLSHEETS
136 : : };
137 : 3 : Sequence<OUString> aNames(SCPRINTOPT_COUNT);
138 [ + - ]: 3 : OUString* pNames = aNames.getArray();
139 [ + + ]: 9 : for(int i = 0; i < SCPRINTOPT_COUNT; i++)
140 : 6 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
141 : :
142 : 3 : return aNames;
143 : : }
144 : :
145 : 2 : ScPrintCfg::ScPrintCfg() :
146 [ + - ][ + - ]: 2 : ConfigItem( OUString(RTL_CONSTASCII_USTRINGPARAM( CFGPATH_PRINT )) )
147 : : {
148 [ + - ]: 2 : Sequence<OUString> aNames = GetPropertyNames();
149 [ + - ]: 2 : Sequence<Any> aValues = GetProperties(aNames);
150 : 2 : const Any* pValues = aValues.getConstArray();
151 : : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
152 [ + - ]: 2 : if(aValues.getLength() == aNames.getLength())
153 : : {
154 [ + + ]: 6 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
155 : : {
156 : : OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
157 [ + - ]: 4 : if(pValues[nProp].hasValue())
158 : : {
159 [ + + - ]: 4 : switch(nProp)
160 : : {
161 : : case SCPRINTOPT_EMPTYPAGES:
162 : : // reversed
163 [ + - ]: 2 : SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
164 : 2 : break;
165 : : case SCPRINTOPT_ALLSHEETS:
166 [ + - ]: 2 : SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
167 : 4 : break;
168 : : }
169 : : }
170 : : }
171 [ + - ][ + - ]: 2 : }
172 : 2 : }
173 : :
174 : :
175 : 1 : void ScPrintCfg::Commit()
176 : : {
177 [ + - ]: 1 : Sequence<OUString> aNames = GetPropertyNames();
178 [ + - ]: 1 : Sequence<Any> aValues(aNames.getLength());
179 [ + - ]: 1 : Any* pValues = aValues.getArray();
180 : :
181 [ + + ]: 3 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
182 : : {
183 [ + + - ]: 2 : switch(nProp)
184 : : {
185 : : case SCPRINTOPT_EMPTYPAGES:
186 : : // reversed
187 [ + - ]: 1 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
188 : 1 : break;
189 : : case SCPRINTOPT_ALLSHEETS:
190 [ + - ]: 1 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
191 : 1 : break;
192 : : }
193 : : }
194 [ + - ][ + - ]: 1 : PutProperties(aNames, aValues);
[ + - ]
195 : 1 : }
196 : :
197 : 6 : void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
198 : : {
199 : 6 : *(ScPrintOptions*)this = rNew;
200 : 6 : SetModified();
201 : 6 : }
202 : :
203 : 0 : void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
204 : :
205 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|