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