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 31*cdf0e10cSrcweir #include <unotools/optionsdlg.hxx> 32*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 33*cdf0e10cSrcweir #include <unotools/configitem.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 37*cdf0e10cSrcweir #include <osl/mutex.hxx> 38*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <hash_map> 41*cdf0e10cSrcweir #include "itemholder1.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace utl; 44*cdf0e10cSrcweir using namespace rtl; 45*cdf0e10cSrcweir using namespace com::sun::star::beans ; 46*cdf0e10cSrcweir using namespace com::sun::star::uno; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define CFG_FILENAME OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.OptionsDialog" ) ) 49*cdf0e10cSrcweir #define ROOT_NODE OUString( RTL_CONSTASCII_USTRINGPARAM( "OptionsDialogGroups" ) ) 50*cdf0e10cSrcweir #define PAGES_NODE OUString( RTL_CONSTASCII_USTRINGPARAM( "Pages" ) ) 51*cdf0e10cSrcweir #define OPTIONS_NODE OUString( RTL_CONSTASCII_USTRINGPARAM( "Options" ) ) 52*cdf0e10cSrcweir #define PROPERTY_HIDE OUString( RTL_CONSTASCII_USTRINGPARAM( "Hide" ) ) 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir static SvtOptionsDlgOptions_Impl* pOptions = NULL; 55*cdf0e10cSrcweir static sal_Int32 nRefCount = 0; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir class SvtOptionsDlgOptions_Impl : public utl::ConfigItem 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir private: 60*cdf0e10cSrcweir struct OUStringHashCode 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir size_t operator()( const ::rtl::OUString& sString ) const 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir return sString.hashCode(); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir }; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir typedef std::hash_map< OUString, sal_Bool, OUStringHashCode, ::std::equal_to< OUString > > OptionNodeList; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir OUString m_sPathDelimiter; 71*cdf0e10cSrcweir OptionNodeList m_aOptionNodeList; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir enum NodeType{ NT_Group, NT_Page, NT_Option }; 74*cdf0e10cSrcweir void ReadNode( const OUString& _rNode, NodeType _eType ); 75*cdf0e10cSrcweir sal_Bool IsHidden( const OUString& _rPath ) const; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir public: 78*cdf0e10cSrcweir SvtOptionsDlgOptions_Impl(); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames ); 81*cdf0e10cSrcweir virtual void Commit(); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir static ::osl::Mutex & getInitMutex(); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir sal_Bool IsGroupHidden ( const OUString& _rGroup ) const; 86*cdf0e10cSrcweir sal_Bool IsPageHidden ( const OUString& _rPage, 87*cdf0e10cSrcweir const OUString& _rGroup ) const; 88*cdf0e10cSrcweir sal_Bool IsOptionHidden ( const OUString& _rOption, 89*cdf0e10cSrcweir const OUString& _rPage, 90*cdf0e10cSrcweir const OUString& _rGroup ) const; 91*cdf0e10cSrcweir }; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir ::osl::Mutex & SvtOptionsDlgOptions_Impl::getInitMutex() 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir static ::osl::Mutex *pMutex = 0; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if( ! pMutex ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 100*cdf0e10cSrcweir if( ! pMutex ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir static ::osl::Mutex mutex; 103*cdf0e10cSrcweir pMutex = &mutex; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir return *pMutex; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ----------------------------------------------------------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir SvtOptionsDlgOptions_Impl::SvtOptionsDlgOptions_Impl() 112*cdf0e10cSrcweir : ConfigItem( OUString( CFG_FILENAME ) ), 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir m_sPathDelimiter( RTL_CONSTASCII_USTRINGPARAM( "/" ) ), 115*cdf0e10cSrcweir m_aOptionNodeList( OptionNodeList() ) 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir OUString sRootNode( ROOT_NODE ); 119*cdf0e10cSrcweir Sequence< OUString > aNodeSeq = GetNodeNames( sRootNode ); 120*cdf0e10cSrcweir OUString sNode( sRootNode + m_sPathDelimiter ); 121*cdf0e10cSrcweir sal_uInt32 nCount = aNodeSeq.getLength(); 122*cdf0e10cSrcweir for ( sal_uInt32 n = 0; n < nCount; n++ ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir OUString sSubNode( sNode + aNodeSeq[n] ); 125*cdf0e10cSrcweir ReadNode( sSubNode, NT_Group ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // ----------------------------------------------------------------------- 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir void SvtOptionsDlgOptions_Impl::Commit() 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir // nothing to commit 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // ----------------------------------------------------------------------- 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void SvtOptionsDlgOptions_Impl::Notify( const Sequence< rtl::OUString >& ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir // nothing to notify 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir void SvtOptionsDlgOptions_Impl::ReadNode( const OUString& _rNode, NodeType _eType ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir OUString sNode( _rNode + m_sPathDelimiter ); 146*cdf0e10cSrcweir OUString sSet; 147*cdf0e10cSrcweir sal_Int32 nLen = 0; 148*cdf0e10cSrcweir switch ( _eType ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir case NT_Group : 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir sSet = PAGES_NODE; 153*cdf0e10cSrcweir nLen = 2; 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir case NT_Page : 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir sSet = OPTIONS_NODE; 160*cdf0e10cSrcweir nLen = 2; 161*cdf0e10cSrcweir break; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir case NT_Option : 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir nLen = 1; 167*cdf0e10cSrcweir break; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir Sequence< OUString > lResult( nLen ); 172*cdf0e10cSrcweir lResult[0] = OUString( sNode + PROPERTY_HIDE ); 173*cdf0e10cSrcweir if ( _eType != NT_Option ) 174*cdf0e10cSrcweir lResult[1] = OUString( sNode + sSet ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir Sequence< Any > aValues; 177*cdf0e10cSrcweir aValues = GetProperties( lResult ); 178*cdf0e10cSrcweir sal_Bool bHide = sal_False; 179*cdf0e10cSrcweir if ( aValues[0] >>= bHide ) 180*cdf0e10cSrcweir m_aOptionNodeList.insert( OptionNodeList::value_type( sNode, bHide ) ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir if ( _eType != NT_Option ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir OUString sNodes( sNode + sSet ); 185*cdf0e10cSrcweir Sequence< OUString > aNodes = GetNodeNames( sNodes ); 186*cdf0e10cSrcweir if ( aNodes.getLength() > 0 ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir for ( sal_uInt32 n = 0; n < (sal_uInt32)aNodes.getLength(); ++n ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir OUString sSubNodeName( sNodes + m_sPathDelimiter + aNodes[n] ); 191*cdf0e10cSrcweir ReadNode( sSubNodeName, _eType == NT_Group ? NT_Page : NT_Option ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // ----------------------------------------------------------------------- 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir OUString getGroupPath( const OUString& _rGroup ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir return OUString( ROOT_NODE + OUString('/') + _rGroup + OUString('/') ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir OUString getPagePath( const OUString& _rPage ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir return OUString( PAGES_NODE + OUString('/') + _rPage + OUString('/') ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir OUString getOptionPath( const OUString& _rOption ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir return OUString( OPTIONS_NODE + OUString('/') + _rOption + OUString('/') ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir // ----------------------------------------------------------------------- 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir sal_Bool SvtOptionsDlgOptions_Impl::IsHidden( const OUString& _rPath ) const 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir sal_Bool bRet = sal_False; 217*cdf0e10cSrcweir OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath ); 218*cdf0e10cSrcweir if ( pIter != m_aOptionNodeList.end() ) 219*cdf0e10cSrcweir bRet = pIter->second; 220*cdf0e10cSrcweir return bRet; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // ----------------------------------------------------------------------- 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_Bool SvtOptionsDlgOptions_Impl::IsGroupHidden( const OUString& _rGroup ) const 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir return IsHidden( getGroupPath( _rGroup ) ); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // ----------------------------------------------------------------------- 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir sal_Bool SvtOptionsDlgOptions_Impl::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) ); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // ----------------------------------------------------------------------- 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir sal_Bool SvtOptionsDlgOptions_Impl::IsOptionHidden( 240*cdf0e10cSrcweir const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) + getOptionPath( _rOption ) ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // ----------------------------------------------------------------------- 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir SvtOptionsDialogOptions::SvtOptionsDialogOptions() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir // Global access, must be guarded (multithreading) 250*cdf0e10cSrcweir ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() ); 251*cdf0e10cSrcweir ++nRefCount; 252*cdf0e10cSrcweir if ( !pOptions ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir pOptions = new SvtOptionsDlgOptions_Impl; 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir m_pImp = pOptions; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // ----------------------------------------------------------------------- 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir SvtOptionsDialogOptions::~SvtOptionsDialogOptions() 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir // Global access, must be guarded (multithreading) 266*cdf0e10cSrcweir ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() ); 267*cdf0e10cSrcweir if ( !--nRefCount ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if ( pOptions->IsModified() ) 270*cdf0e10cSrcweir pOptions->Commit(); 271*cdf0e10cSrcweir DELETEZ( pOptions ); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir sal_Bool SvtOptionsDialogOptions::IsGroupHidden( const String& _rGroup ) const 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir return m_pImp->IsGroupHidden( _rGroup ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir sal_Bool SvtOptionsDialogOptions::IsPageHidden( const String& _rPage, const String& _rGroup ) const 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir return m_pImp->IsPageHidden( _rPage, _rGroup ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir sal_Bool SvtOptionsDialogOptions::IsOptionHidden( 286*cdf0e10cSrcweir const String& _rOption, const String& _rPage, const String& _rGroup ) const 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir return m_pImp->IsOptionHidden( _rOption, _rPage, _rGroup ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291