1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_unotools.hxx" 30*cdf0e10cSrcweir #ifndef GCC 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir // includes 35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <unotools/localisationoptions.hxx> 38*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 39*cdf0e10cSrcweir #include <unotools/configitem.hxx> 40*cdf0e10cSrcweir #include <tools/debug.hxx> 41*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 42*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <rtl/logfile.hxx> 45*cdf0e10cSrcweir #include "itemholder1.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 48*cdf0e10cSrcweir // namespaces 49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir using namespace ::utl ; 52*cdf0e10cSrcweir using namespace ::rtl ; 53*cdf0e10cSrcweir using namespace ::osl ; 54*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir // const 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #define ROOTNODE_LOCALISATION OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/View/Localisation")) 61*cdf0e10cSrcweir #define DEFAULT_AUTOMNEMONIC sal_False 62*cdf0e10cSrcweir #define DEFAULT_DIALOGSCALE 0 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #define PROPERTYNAME_AUTOMNEMONIC OUString(RTL_CONSTASCII_USTRINGPARAM("AutoMnemonic" )) 65*cdf0e10cSrcweir #define PROPERTYNAME_DIALOGSCALE OUString(RTL_CONSTASCII_USTRINGPARAM("DialogScale" )) 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir #define PROPERTYHANDLE_AUTOMNEMONIC 0 68*cdf0e10cSrcweir #define PROPERTYHANDLE_DIALOGSCALE 1 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir #define PROPERTYCOUNT 2 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 73*cdf0e10cSrcweir // private declarations! 74*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir class SvtLocalisationOptions_Impl : public ConfigItem 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 79*cdf0e10cSrcweir // public methods 80*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir public: 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 85*cdf0e10cSrcweir // constructor / destructor 86*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir SvtLocalisationOptions_Impl(); 89*cdf0e10cSrcweir ~SvtLocalisationOptions_Impl(); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 92*cdf0e10cSrcweir // overloaded methods of baseclass 93*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir /*-****************************************************************************************************//** 96*cdf0e10cSrcweir @short called for notify of configmanager 97*cdf0e10cSrcweir @descr These method is called from the ConfigManager before application ends or from the 98*cdf0e10cSrcweir PropertyChangeListener if the sub tree broadcasts changes. You must update your 99*cdf0e10cSrcweir internal values. 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir @seealso baseclass ConfigItem 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir @param "seqPropertyNames" is the list of properties which should be updated. 104*cdf0e10cSrcweir @return - 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir @onerror - 107*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir virtual void Notify( const Sequence< OUString >& seqPropertyNames ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir /*-****************************************************************************************************//** 112*cdf0e10cSrcweir @short write changes to configuration 113*cdf0e10cSrcweir @descr These method writes the changed values into the sub tree 114*cdf0e10cSrcweir and should always called in our destructor to guarantee consistency of config data. 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir @seealso baseclass ConfigItem 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir @param - 119*cdf0e10cSrcweir @return - 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir @onerror - 122*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir virtual void Commit(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 127*cdf0e10cSrcweir // public interface 128*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir /*-****************************************************************************************************//** 131*cdf0e10cSrcweir @short access method to get internal values 132*cdf0e10cSrcweir @descr These method give us a chance to regulate acces to ouer internal values. 133*cdf0e10cSrcweir It's not used in the moment - but it's possible for the feature! 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir @seealso - 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir @param - 138*cdf0e10cSrcweir @return - 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir @onerror - 141*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir sal_Bool IsAutoMnemonic ( ) const ; 144*cdf0e10cSrcweir void SetAutoMnemonic ( sal_Bool bState ) ; 145*cdf0e10cSrcweir sal_Int32 GetDialogScale ( ) const ; 146*cdf0e10cSrcweir void SetDialogScale ( sal_Int32 nScale ) ; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 149*cdf0e10cSrcweir // private methods 150*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir private: 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir /*-****************************************************************************************************//** 155*cdf0e10cSrcweir @short return list of key names of ouer configuration management which represent oue module tree 156*cdf0e10cSrcweir @descr These methods return a static const list of key names. We need it to get needed values from our 157*cdf0e10cSrcweir configuration management. 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir @seealso - 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir @param - 162*cdf0e10cSrcweir @return A list of needed configuration keys is returned. 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir @onerror - 165*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir static Sequence< OUString > GetPropertyNames(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 170*cdf0e10cSrcweir // private member 171*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir private: 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir sal_Bool m_bAutoMnemonic ; 176*cdf0e10cSrcweir sal_Int32 m_nDialogScale ; 177*cdf0e10cSrcweir }; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 180*cdf0e10cSrcweir // definitions 181*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir //***************************************************************************************************************** 184*cdf0e10cSrcweir // constructor 185*cdf0e10cSrcweir //***************************************************************************************************************** 186*cdf0e10cSrcweir SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl() 187*cdf0e10cSrcweir // Init baseclasses first 188*cdf0e10cSrcweir : ConfigItem ( ROOTNODE_LOCALISATION ) 189*cdf0e10cSrcweir // Init member then. 190*cdf0e10cSrcweir , m_bAutoMnemonic ( DEFAULT_AUTOMNEMONIC ) 191*cdf0e10cSrcweir , m_nDialogScale ( DEFAULT_DIALOGSCALE ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir // Use our static list of configuration keys to get his values. 194*cdf0e10cSrcweir Sequence< OUString > seqNames = GetPropertyNames ( ); 195*cdf0e10cSrcweir Sequence< Any > seqValues = GetProperties ( seqNames ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // Safe impossible cases. 198*cdf0e10cSrcweir // We need values from ALL configuration keys. 199*cdf0e10cSrcweir // Follow assignment use order of values in relation to our list of key names! 200*cdf0e10cSrcweir DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nI miss some values of configuration keys!\n" ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // Copy values from list in right order to ouer internal member. 203*cdf0e10cSrcweir sal_Int32 nPropertyCount = seqValues.getLength(); 204*cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir // Safe impossible cases. 207*cdf0e10cSrcweir // Check any for valid value. 208*cdf0e10cSrcweir DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nInvalid property value detected!\n" ); 209*cdf0e10cSrcweir switch( nProperty ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir case PROPERTYHANDLE_AUTOMNEMONIC : { 212*cdf0e10cSrcweir DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" ); 213*cdf0e10cSrcweir seqValues[nProperty] >>= m_bAutoMnemonic; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir case PROPERTYHANDLE_DIALOGSCALE : { 218*cdf0e10cSrcweir DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_LONG), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" ); 219*cdf0e10cSrcweir seqValues[nProperty] >>= m_nDialogScale; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir break; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // Enable notification mechanism of ouer baseclass. 226*cdf0e10cSrcweir // We need it to get information about changes outside these class on ouer used configuration keys! 227*cdf0e10cSrcweir EnableNotification( seqNames ); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //***************************************************************************************************************** 231*cdf0e10cSrcweir // destructor 232*cdf0e10cSrcweir //***************************************************************************************************************** 233*cdf0e10cSrcweir SvtLocalisationOptions_Impl::~SvtLocalisationOptions_Impl() 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir // We must save our current values .. if user forget it! 236*cdf0e10cSrcweir if( IsModified() == sal_True ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir Commit(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir //***************************************************************************************************************** 243*cdf0e10cSrcweir // public method 244*cdf0e10cSrcweir //***************************************************************************************************************** 245*cdf0e10cSrcweir void SvtLocalisationOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir // Use given list of updated properties to get his values from configuration directly! 248*cdf0e10cSrcweir Sequence< Any > seqValues = GetProperties( seqPropertyNames ); 249*cdf0e10cSrcweir // Safe impossible cases. 250*cdf0e10cSrcweir // We need values from ALL notified configuration keys. 251*cdf0e10cSrcweir DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtLocalisationOptions_Impl::Notify()\nI miss some values of configuration keys!\n" ); 252*cdf0e10cSrcweir // Step over list of property names and get right value from coreesponding value list to set it on internal members! 253*cdf0e10cSrcweir sal_Int32 nCount = seqPropertyNames.getLength(); 254*cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if( seqPropertyNames[nProperty] == PROPERTYNAME_AUTOMNEMONIC ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" ); 259*cdf0e10cSrcweir seqValues[nProperty] >>= m_bAutoMnemonic; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir else 262*cdf0e10cSrcweir if( seqPropertyNames[nProperty] == PROPERTYNAME_DIALOGSCALE ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_LONG), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" ); 265*cdf0e10cSrcweir seqValues[nProperty] >>= m_nDialogScale; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 268*cdf0e10cSrcweir else DBG_ASSERT( sal_False, "SvtLocalisationOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" ); 269*cdf0e10cSrcweir #endif 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir NotifyListeners(0); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir //***************************************************************************************************************** 276*cdf0e10cSrcweir // public method 277*cdf0e10cSrcweir //***************************************************************************************************************** 278*cdf0e10cSrcweir void SvtLocalisationOptions_Impl::Commit() 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir // Get names of supported properties, create a list for values and copy current values to it. 281*cdf0e10cSrcweir Sequence< OUString > seqNames = GetPropertyNames (); 282*cdf0e10cSrcweir sal_Int32 nCount = seqNames.getLength(); 283*cdf0e10cSrcweir Sequence< Any > seqValues ( nCount ); 284*cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir switch( nProperty ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir case PROPERTYHANDLE_AUTOMNEMONIC : { 289*cdf0e10cSrcweir seqValues[nProperty] <<= m_bAutoMnemonic; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir break; 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir case PROPERTYHANDLE_DIALOGSCALE : { 294*cdf0e10cSrcweir seqValues[nProperty] <<= m_nDialogScale; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir break; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir // Set properties in configuration. 300*cdf0e10cSrcweir PutProperties( seqNames, seqValues ); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir //***************************************************************************************************************** 304*cdf0e10cSrcweir // public method 305*cdf0e10cSrcweir //***************************************************************************************************************** 306*cdf0e10cSrcweir sal_Bool SvtLocalisationOptions_Impl::IsAutoMnemonic() const 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir return m_bAutoMnemonic; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir //***************************************************************************************************************** 312*cdf0e10cSrcweir // public method 313*cdf0e10cSrcweir //***************************************************************************************************************** 314*cdf0e10cSrcweir void SvtLocalisationOptions_Impl::SetAutoMnemonic( sal_Bool bState ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir m_bAutoMnemonic = bState; 317*cdf0e10cSrcweir SetModified(); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir //***************************************************************************************************************** 321*cdf0e10cSrcweir // public method 322*cdf0e10cSrcweir //***************************************************************************************************************** 323*cdf0e10cSrcweir sal_Int32 SvtLocalisationOptions_Impl::GetDialogScale() const 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir return m_nDialogScale; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir //***************************************************************************************************************** 329*cdf0e10cSrcweir // public method 330*cdf0e10cSrcweir //***************************************************************************************************************** 331*cdf0e10cSrcweir void SvtLocalisationOptions_Impl::SetDialogScale( sal_Int32 nScale ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir m_nDialogScale = nScale; 334*cdf0e10cSrcweir SetModified(); 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir //***************************************************************************************************************** 338*cdf0e10cSrcweir // private method 339*cdf0e10cSrcweir //***************************************************************************************************************** 340*cdf0e10cSrcweir Sequence< OUString > SvtLocalisationOptions_Impl::GetPropertyNames() 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir // Build static list of configuration key names. 343*cdf0e10cSrcweir static const OUString pProperties[] = 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir PROPERTYNAME_AUTOMNEMONIC , 346*cdf0e10cSrcweir PROPERTYNAME_DIALOGSCALE , 347*cdf0e10cSrcweir }; 348*cdf0e10cSrcweir // Initialize return sequence with these list ... 349*cdf0e10cSrcweir static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT ); 350*cdf0e10cSrcweir // ... and return it. 351*cdf0e10cSrcweir return seqPropertyNames; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir //***************************************************************************************************************** 355*cdf0e10cSrcweir // initialize static member 356*cdf0e10cSrcweir // DON'T DO IT IN YOUR HEADER! 357*cdf0e10cSrcweir // see definition for further informations 358*cdf0e10cSrcweir //***************************************************************************************************************** 359*cdf0e10cSrcweir SvtLocalisationOptions_Impl* SvtLocalisationOptions::m_pDataContainer = NULL ; 360*cdf0e10cSrcweir sal_Int32 SvtLocalisationOptions::m_nRefCount = 0 ; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir //***************************************************************************************************************** 363*cdf0e10cSrcweir // constructor 364*cdf0e10cSrcweir //***************************************************************************************************************** 365*cdf0e10cSrcweir SvtLocalisationOptions::SvtLocalisationOptions() 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir // Global access, must be guarded (multithreading!). 368*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 369*cdf0e10cSrcweir // Increase ouer refcount ... 370*cdf0e10cSrcweir ++m_nRefCount; 371*cdf0e10cSrcweir // ... and initialize ouer data container only if it not already exist! 372*cdf0e10cSrcweir if( m_pDataContainer == NULL ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtLocalisationOptions_Impl::ctor()"); 375*cdf0e10cSrcweir m_pDataContainer = new SvtLocalisationOptions_Impl; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir ItemHolder1::holdConfigItem(E_LOCALISATIONOPTIONS); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir //***************************************************************************************************************** 382*cdf0e10cSrcweir // destructor 383*cdf0e10cSrcweir //***************************************************************************************************************** 384*cdf0e10cSrcweir SvtLocalisationOptions::~SvtLocalisationOptions() 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir // Global access, must be guarded (multithreading!) 387*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 388*cdf0e10cSrcweir // Decrease ouer refcount. 389*cdf0e10cSrcweir --m_nRefCount; 390*cdf0e10cSrcweir // If last instance was deleted ... 391*cdf0e10cSrcweir // we must destroy ouer static data container! 392*cdf0e10cSrcweir if( m_nRefCount <= 0 ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir delete m_pDataContainer; 395*cdf0e10cSrcweir m_pDataContainer = NULL; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir //***************************************************************************************************************** 400*cdf0e10cSrcweir // public method 401*cdf0e10cSrcweir //***************************************************************************************************************** 402*cdf0e10cSrcweir sal_Bool SvtLocalisationOptions::IsAutoMnemonic() const 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 405*cdf0e10cSrcweir return m_pDataContainer->IsAutoMnemonic(); 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir //***************************************************************************************************************** 409*cdf0e10cSrcweir // public method 410*cdf0e10cSrcweir //***************************************************************************************************************** 411*cdf0e10cSrcweir void SvtLocalisationOptions::SetAutoMnemonic( sal_Bool bState ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 414*cdf0e10cSrcweir m_pDataContainer->SetAutoMnemonic( bState ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir //***************************************************************************************************************** 418*cdf0e10cSrcweir // public method 419*cdf0e10cSrcweir //***************************************************************************************************************** 420*cdf0e10cSrcweir sal_Int32 SvtLocalisationOptions::GetDialogScale() const 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 423*cdf0e10cSrcweir return m_pDataContainer->GetDialogScale(); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir //***************************************************************************************************************** 427*cdf0e10cSrcweir // public method 428*cdf0e10cSrcweir //***************************************************************************************************************** 429*cdf0e10cSrcweir void SvtLocalisationOptions::SetDialogScale( sal_Int32 nScale ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 432*cdf0e10cSrcweir m_pDataContainer->SetDialogScale( nScale ); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //***************************************************************************************************************** 436*cdf0e10cSrcweir // private method 437*cdf0e10cSrcweir //***************************************************************************************************************** 438*cdf0e10cSrcweir Mutex& SvtLocalisationOptions::GetOwnStaticMutex() 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir // Initialize static mutex only for one time! 441*cdf0e10cSrcweir static Mutex* pMutex = NULL; 442*cdf0e10cSrcweir // If these method first called (Mutex not already exist!) ... 443*cdf0e10cSrcweir if( pMutex == NULL ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir // ... we must create a new one. Protect follow code with the global mutex - 446*cdf0e10cSrcweir // It must be - we create a static variable! 447*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 448*cdf0e10cSrcweir // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these! 449*cdf0e10cSrcweir if( pMutex == NULL ) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir // Create the new mutex and set it for return on static variable. 452*cdf0e10cSrcweir static Mutex aMutex; 453*cdf0e10cSrcweir pMutex = &aMutex; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir // Return new created or already existing mutex object. 457*cdf0e10cSrcweir return *pMutex; 458*cdf0e10cSrcweir } 459