Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/uno/Any.hxx>
21 : #include <com/sun/star/uno/Sequence.hxx>
22 :
23 : #include "printopt.hxx"
24 : #include "miscuno.hxx"
25 :
26 : using namespace utl;
27 : using namespace com::sun::star::uno;
28 :
29 0 : TYPEINIT1(ScTpPrintItem, SfxPoolItem);
30 :
31 0 : ScPrintOptions::ScPrintOptions()
32 : {
33 0 : SetDefaults();
34 0 : }
35 :
36 0 : ScPrintOptions::ScPrintOptions( const ScPrintOptions& rCpy ) :
37 : bSkipEmpty( rCpy.bSkipEmpty ),
38 : bAllSheets( rCpy.bAllSheets ),
39 0 : bForceBreaks( rCpy.bForceBreaks )
40 : {
41 0 : }
42 :
43 0 : ScPrintOptions::~ScPrintOptions()
44 : {
45 0 : }
46 :
47 0 : void ScPrintOptions::SetDefaults()
48 : {
49 0 : bSkipEmpty = true;
50 0 : bAllSheets = false;
51 0 : bForceBreaks = false;
52 0 : }
53 :
54 0 : const ScPrintOptions& ScPrintOptions::operator=( const ScPrintOptions& rCpy )
55 : {
56 0 : bSkipEmpty = rCpy.bSkipEmpty;
57 0 : bAllSheets = rCpy.bAllSheets;
58 0 : bForceBreaks = rCpy.bForceBreaks;
59 0 : return *this;
60 : }
61 :
62 0 : bool ScPrintOptions::operator==( const ScPrintOptions& rOpt ) const
63 : {
64 0 : return bSkipEmpty == rOpt.bSkipEmpty
65 0 : && bAllSheets == rOpt.bAllSheets
66 0 : && bForceBreaks == rOpt.bForceBreaks;
67 : }
68 :
69 0 : bool ScPrintOptions::operator!=( const ScPrintOptions& rOpt ) const
70 : {
71 0 : return !(operator==(rOpt));
72 : }
73 :
74 0 : ScTpPrintItem::ScTpPrintItem( sal_uInt16 nWhichP, const ScPrintOptions& rOpt ) :
75 : SfxPoolItem ( nWhichP ),
76 0 : theOptions ( rOpt )
77 : {
78 0 : }
79 :
80 0 : ScTpPrintItem::ScTpPrintItem( const ScTpPrintItem& rItem ) :
81 : SfxPoolItem ( rItem ),
82 0 : theOptions ( rItem.theOptions )
83 : {
84 0 : }
85 :
86 0 : ScTpPrintItem::~ScTpPrintItem()
87 : {
88 0 : }
89 :
90 0 : OUString ScTpPrintItem::GetValueText() const
91 : {
92 0 : return OUString("ScTpPrintItem");
93 : }
94 :
95 0 : bool ScTpPrintItem::operator==( const SfxPoolItem& rItem ) const
96 : {
97 : OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
98 :
99 0 : const ScTpPrintItem& rPItem = (const ScTpPrintItem&)rItem;
100 0 : return ( theOptions == rPItem.theOptions );
101 : }
102 :
103 0 : SfxPoolItem* ScTpPrintItem::Clone( SfxItemPool * ) const
104 : {
105 0 : return new ScTpPrintItem( *this );
106 : }
107 :
108 : #define CFGPATH_PRINT "Office.Calc/Print"
109 :
110 : #define SCPRINTOPT_EMPTYPAGES 0
111 : #define SCPRINTOPT_ALLSHEETS 1
112 : #define SCPRINTOPT_FORCEBREAKS 2
113 : #define SCPRINTOPT_COUNT 3
114 :
115 0 : Sequence<OUString> ScPrintCfg::GetPropertyNames()
116 : {
117 : static const char* aPropNames[] =
118 : {
119 : "Page/EmptyPages", // SCPRINTOPT_EMPTYPAGES
120 : "Other/AllSheets", // SCPRINTOPT_ALLSHEETS
121 : "Page/ForceBreaks" // SCPRINTOPT_FORCEBREAKS
122 : };
123 0 : Sequence<OUString> aNames(SCPRINTOPT_COUNT);
124 0 : OUString* pNames = aNames.getArray();
125 0 : for(int i = 0; i < SCPRINTOPT_COUNT; i++)
126 0 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
127 :
128 0 : return aNames;
129 : }
130 :
131 0 : ScPrintCfg::ScPrintCfg() :
132 0 : ConfigItem( OUString( CFGPATH_PRINT ) )
133 : {
134 0 : Sequence<OUString> aNames = GetPropertyNames();
135 0 : Sequence<Any> aValues = GetProperties(aNames);
136 0 : const Any* pValues = aValues.getConstArray();
137 : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
138 0 : if(aValues.getLength() == aNames.getLength())
139 : {
140 0 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
141 : {
142 : OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
143 0 : if(pValues[nProp].hasValue())
144 : {
145 0 : switch(nProp)
146 : {
147 : case SCPRINTOPT_EMPTYPAGES:
148 : // reversed
149 0 : SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
150 0 : break;
151 : case SCPRINTOPT_ALLSHEETS:
152 0 : SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
153 0 : break;
154 : case SCPRINTOPT_FORCEBREAKS:
155 0 : SetForceBreaks( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
156 0 : break;
157 : }
158 : }
159 : }
160 0 : }
161 0 : }
162 :
163 0 : void ScPrintCfg::Commit()
164 : {
165 0 : Sequence<OUString> aNames = GetPropertyNames();
166 0 : Sequence<Any> aValues(aNames.getLength());
167 0 : Any* pValues = aValues.getArray();
168 :
169 0 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
170 : {
171 0 : switch(nProp)
172 : {
173 : case SCPRINTOPT_EMPTYPAGES:
174 : // reversed
175 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], !GetSkipEmpty() );
176 0 : break;
177 : case SCPRINTOPT_ALLSHEETS:
178 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetAllSheets() );
179 0 : break;
180 : case SCPRINTOPT_FORCEBREAKS:
181 0 : ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetForceBreaks() );
182 0 : break;
183 : }
184 : }
185 0 : PutProperties(aNames, aValues);
186 0 : }
187 :
188 0 : void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
189 : {
190 0 : *(ScPrintOptions*)this = rNew;
191 0 : SetModified();
192 0 : }
193 :
194 0 : void ScPrintCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|