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_unotools.hxx" 30 31 #include <unotools/misccfg.hxx> 32 #include "rtl/instance.hxx" 33 #include <unotools/configmgr.hxx> 34 #include <unotools/configitem.hxx> 35 #include <tools/debug.hxx> 36 #include <com/sun/star/uno/Any.hxx> 37 #include <com/sun/star/uno/Sequence.hxx> 38 #include <vos/mutex.hxx> 39 #include <osl/mutex.hxx> 40 #include <rtl/logfile.hxx> 41 #include "itemholder1.hxx" 42 43 #define DEFAULT_TAB 2000 44 45 #define DEF_INCH 2540L 46 #define DEF_RELTWIP 1440L 47 48 using namespace rtl; 49 using namespace com::sun::star::uno; 50 51 #define C2U(cChar) OUString::createFromAscii(cChar) 52 53 namespace utl 54 { 55 56 static SfxMiscCfg* pOptions = NULL; 57 static sal_Int32 nRefCount = 0; 58 59 class SfxMiscCfg : public utl::ConfigItem 60 { 61 sal_Bool bPaperSize; // printer warnings 62 sal_Bool bPaperOrientation; 63 sal_Bool bNotFound; 64 sal_Int32 nYear2000; // two digit year representation 65 66 const com::sun::star::uno::Sequence<rtl::OUString>& GetPropertyNames(); 67 void Load(); 68 69 public: 70 SfxMiscCfg( ); 71 ~SfxMiscCfg( ); 72 73 virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); 74 virtual void Commit(); 75 76 sal_Bool IsNotFoundWarning() const {return bNotFound;} 77 void SetNotFoundWarning( sal_Bool bSet); 78 79 sal_Bool IsPaperSizeWarning() const {return bPaperSize;} 80 void SetPaperSizeWarning(sal_Bool bSet); 81 82 sal_Bool IsPaperOrientationWarning() const {return bPaperOrientation;} 83 void SetPaperOrientationWarning( sal_Bool bSet); 84 85 // 0 ... 99 86 sal_Int32 GetYear2000() const { return nYear2000; } 87 void SetYear2000( sal_Int32 nSet ); 88 89 }; 90 91 /*-------------------------------------------------------------------- 92 Beschreibung: 93 --------------------------------------------------------------------*/ 94 SfxMiscCfg::SfxMiscCfg() : 95 ConfigItem(C2U("Office.Common") ), 96 bPaperSize(sal_False), 97 bPaperOrientation (sal_False), 98 bNotFound (sal_False), 99 nYear2000( 1930 ) 100 { 101 RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()"); 102 103 Load(); 104 } 105 /* -----------------------------02.03.01 15:31-------------------------------- 106 107 ---------------------------------------------------------------------------*/ 108 SfxMiscCfg::~SfxMiscCfg() 109 { 110 } 111 /*-------------------------------------------------------------------- 112 Beschreibung: 113 --------------------------------------------------------------------*/ 114 115 void SfxMiscCfg::SetNotFoundWarning( sal_Bool bSet) 116 { 117 if(bNotFound != bSet) 118 SetModified(); 119 bNotFound = bSet; 120 } 121 122 /*-------------------------------------------------------------------- 123 Beschreibung: 124 --------------------------------------------------------------------*/ 125 126 void SfxMiscCfg::SetPaperSizeWarning( sal_Bool bSet) 127 { 128 if(bPaperSize != bSet) 129 SetModified(); 130 bPaperSize = bSet; 131 } 132 133 /*-------------------------------------------------------------------- 134 Beschreibung: 135 --------------------------------------------------------------------*/ 136 void SfxMiscCfg::SetPaperOrientationWarning( sal_Bool bSet) 137 { 138 if(bPaperOrientation != bSet) 139 SetModified(); 140 bPaperOrientation = bSet; 141 } 142 /*-------------------------------------------------------------------- 143 Beschreibung: 144 --------------------------------------------------------------------*/ 145 146 void SfxMiscCfg::SetYear2000( sal_Int32 nSet ) 147 { 148 if(nYear2000 != nSet) 149 SetModified(); 150 nYear2000 = nSet; 151 } 152 /* -----------------------------02.03.01 15:31-------------------------------- 153 154 ---------------------------------------------------------------------------*/ 155 const Sequence<OUString>& SfxMiscCfg::GetPropertyNames() 156 { 157 static Sequence<OUString> aNames; 158 if(!aNames.getLength()) 159 { 160 static const char* aPropNames[] = 161 { 162 "Print/Warning/PaperSize", // 0 163 "Print/Warning/PaperOrientation", // 1 164 "Print/Warning/NotFound", // 2 165 "DateFormat/TwoDigitYear", // 3 166 }; 167 const int nCount = 4; 168 aNames.realloc(nCount); 169 OUString* pNames = aNames.getArray(); 170 for(int i = 0; i < nCount; i++) 171 pNames[i] = OUString::createFromAscii(aPropNames[i]); 172 } 173 return aNames; 174 } 175 /* -----------------------------02.03.01 15:31-------------------------------- 176 177 ---------------------------------------------------------------------------*/ 178 void SfxMiscCfg::Load() 179 { 180 const Sequence<OUString>& aNames = GetPropertyNames(); 181 Sequence<Any> aValues = GetProperties(aNames); 182 EnableNotification(aNames); 183 const Any* pValues = aValues.getConstArray(); 184 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed"); 185 if(aValues.getLength() == aNames.getLength()) 186 { 187 for(int nProp = 0; nProp < aNames.getLength(); nProp++) 188 { 189 if(pValues[nProp].hasValue()) 190 { 191 switch(nProp) 192 { 193 case 0: bPaperSize = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperSize", 194 case 1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue(); break; //"Print/Warning/PaperOrientation", 195 case 2: bNotFound = *(sal_Bool*)pValues[nProp].getValue() ; break; //"Print/Warning/NotFound", 196 case 3: pValues[nProp] >>= nYear2000;break; //"DateFormat/TwoDigitYear", 197 } 198 } 199 } 200 } 201 } 202 /* -----------------------------02.03.01 15:31-------------------------------- 203 204 ---------------------------------------------------------------------------*/ 205 void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& ) 206 { 207 Load(); 208 } 209 /* -----------------------------02.03.01 15:31-------------------------------- 210 211 ---------------------------------------------------------------------------*/ 212 void SfxMiscCfg::Commit() 213 { 214 const Sequence<OUString>& aNames = GetPropertyNames(); 215 Sequence<Any> aValues(aNames.getLength()); 216 Any* pValues = aValues.getArray(); 217 218 const Type& rType = ::getBooleanCppuType(); 219 for(int nProp = 0; nProp < aNames.getLength(); nProp++) 220 { 221 switch(nProp) 222 { 223 case 0: pValues[nProp].setValue(&bPaperSize, rType);break; //"Print/Warning/PaperSize", 224 case 1: pValues[nProp].setValue(&bPaperOrientation, rType);break; //"Print/Warning/PaperOrientation", 225 case 2: pValues[nProp].setValue(&bNotFound, rType);break; //"Print/Warning/NotFound", 226 case 3: pValues[nProp] <<= nYear2000;break; //"DateFormat/TwoDigitYear", 227 } 228 } 229 PutProperties(aNames, aValues); 230 } 231 // ----------------------------------------------------------------------- 232 namespace 233 { 234 class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton > 235 { 236 }; 237 } 238 239 MiscCfg::MiscCfg( ) 240 { 241 // Global access, must be guarded (multithreading) 242 ::osl::MutexGuard aGuard( LocalSingleton::get() ); 243 if ( !pOptions ) 244 { 245 RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()"); 246 pOptions = new SfxMiscCfg; 247 248 ItemHolder1::holdConfigItem(E_MISCCFG); 249 } 250 251 ++nRefCount; 252 pImpl = pOptions; 253 pImpl->AddListener(this); 254 } 255 256 MiscCfg::~MiscCfg( ) 257 { 258 // Global access, must be guarded (multithreading) 259 ::osl::MutexGuard aGuard( LocalSingleton::get() ); 260 pImpl->RemoveListener(this); 261 if ( !--nRefCount ) 262 { 263 if ( pOptions->IsModified() ) 264 pOptions->Commit(); 265 DELETEZ( pOptions ); 266 } 267 } 268 269 sal_Bool MiscCfg::IsNotFoundWarning() const 270 { 271 return pImpl->IsNotFoundWarning(); 272 } 273 274 void MiscCfg::SetNotFoundWarning( sal_Bool bSet) 275 { 276 pImpl->SetNotFoundWarning( bSet ); 277 } 278 279 sal_Bool MiscCfg::IsPaperSizeWarning() const 280 { 281 return pImpl->IsPaperSizeWarning(); 282 } 283 284 void MiscCfg::SetPaperSizeWarning(sal_Bool bSet) 285 { 286 pImpl->SetPaperSizeWarning( bSet ); 287 } 288 289 sal_Bool MiscCfg::IsPaperOrientationWarning() const 290 { 291 return pImpl->IsPaperOrientationWarning(); 292 } 293 294 void MiscCfg::SetPaperOrientationWarning( sal_Bool bSet) 295 { 296 pImpl->SetPaperOrientationWarning( bSet ); 297 } 298 299 sal_Int32 MiscCfg::GetYear2000() const 300 { 301 return pImpl->GetYear2000(); 302 } 303 304 void MiscCfg::SetYear2000( sal_Int32 nSet ) 305 { 306 pImpl->SetYear2000( nSet ); 307 } 308 309 } 310 311