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 //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <unotools/cmdoptions.hxx> 36*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 37*cdf0e10cSrcweir #include <unotools/configitem.hxx> 38*cdf0e10cSrcweir #include <tools/debug.hxx> 39*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 40*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 42*cdf0e10cSrcweir #include <tools/urlobj.hxx> 43*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <itemholder1.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <algorithm> 48*cdf0e10cSrcweir #include <hash_map> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // namespaces 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::std ; 55*cdf0e10cSrcweir using namespace ::utl ; 56*cdf0e10cSrcweir using namespace ::rtl ; 57*cdf0e10cSrcweir using namespace ::osl ; 58*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 59*cdf0e10cSrcweir using namespace ::com::sun::star::beans ; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62*cdf0e10cSrcweir // const 63*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #define ROOTNODE_CMDOPTIONS OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Commands/Execute" )) 66*cdf0e10cSrcweir #define PATHDELIMITER OUString(RTL_CONSTASCII_USTRINGPARAM("/" )) 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #define SETNODE_DISABLED OUString(RTL_CONSTASCII_USTRINGPARAM("Disabled" )) 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir #define PROPERTYNAME_CMD OUString(RTL_CONSTASCII_USTRINGPARAM("Command" )) 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #define PROPERTYCOUNT 1 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #define OFFSET_CMD 0 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 77*cdf0e10cSrcweir // private declarations! 78*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // Method to retrieve a hash code from a string. May be we have to change it to decrease collisions in the hash map 81*cdf0e10cSrcweir struct OUStringHashCode 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir size_t operator()( const ::rtl::OUString& sString ) const 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir return sString.hashCode(); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir }; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /*-**************************************************************************************************************** 90*cdf0e10cSrcweir @descr support simple command option structures and operations on it 91*cdf0e10cSrcweir ****************************************************************************************************************-*/ 92*cdf0e10cSrcweir class SvtCmdOptions 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir public: 95*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 96*cdf0e10cSrcweir // the only way to free memory! 97*cdf0e10cSrcweir void Clear() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir m_aCommandHashMap.clear(); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir sal_Bool HasEntries() const 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir return ( m_aCommandHashMap.size() > 0 ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SetContainerSize( sal_Int32 nSize ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir m_aCommandHashMap.resize( nSize ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir sal_Bool Lookup( const OUString& aCmd ) const 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir CommandHashMap::const_iterator pEntry = m_aCommandHashMap.find( aCmd ); 115*cdf0e10cSrcweir return ( pEntry != m_aCommandHashMap.end() ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir void AddCommand( const OUString& aCmd ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir m_aCommandHashMap.insert( CommandHashMap::value_type( aCmd, 0 ) ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 124*cdf0e10cSrcweir // convert internal list to external format 125*cdf0e10cSrcweir // for using it on right menus realy 126*cdf0e10cSrcweir // Notice: We build a property list with 4 entries and set it on result list then. 127*cdf0e10cSrcweir // The while-loop starts with pointer on internal member list lSetupEntries, change to 128*cdf0e10cSrcweir // lUserEntries then and stop after that with NULL! 129*cdf0e10cSrcweir // Separator entries will be packed in another way then normal entries! We define 130*cdf0e10cSrcweir // special strings "sEmpty" and "sSeperator" to perform too ... 131*cdf0e10cSrcweir Sequence< OUString > GetList() const 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir sal_Int32 nCount = (sal_Int32)m_aCommandHashMap.size(); 134*cdf0e10cSrcweir sal_Int32 nIndex = 0; 135*cdf0e10cSrcweir Sequence< OUString > aList( nCount ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir CommandHashMap::const_iterator pEntry = m_aCommandHashMap.begin(); 138*cdf0e10cSrcweir while ( pEntry != m_aCommandHashMap.end() ) 139*cdf0e10cSrcweir aList[nIndex++] = pEntry->first; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir return aList; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir private: 145*cdf0e10cSrcweir class CommandHashMap : public ::std::hash_map< ::rtl::OUString , 146*cdf0e10cSrcweir sal_Int32 , 147*cdf0e10cSrcweir OUStringHashCode , 148*cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir public: 151*cdf0e10cSrcweir inline void free() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir CommandHashMap().swap( *this ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir }; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir CommandHashMap m_aCommandHashMap; 158*cdf0e10cSrcweir }; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir typedef ::std::vector< ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > > SvtFrameVector; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir class SvtCommandOptions_Impl : public ConfigItem 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 165*cdf0e10cSrcweir // public methods 166*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir public: 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 171*cdf0e10cSrcweir // constructor / destructor 172*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir SvtCommandOptions_Impl(); 175*cdf0e10cSrcweir ~SvtCommandOptions_Impl(); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 178*cdf0e10cSrcweir // overloaded methods of baseclass 179*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir /*-****************************************************************************************************//** 182*cdf0e10cSrcweir @short called for notify of configmanager 183*cdf0e10cSrcweir @descr These method is called from the ConfigManager before application ends or from the 184*cdf0e10cSrcweir PropertyChangeListener if the sub tree broadcasts changes. You must update your 185*cdf0e10cSrcweir internal values. 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir @seealso baseclass ConfigItem 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir @param "lPropertyNames" is the list of properties which should be updated. 190*cdf0e10cSrcweir @return - 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir @onerror - 193*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir virtual void Notify( const Sequence< OUString >& lPropertyNames ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir /*-****************************************************************************************************//** 198*cdf0e10cSrcweir @short write changes to configuration 199*cdf0e10cSrcweir @descr These method writes the changed values into the sub tree 200*cdf0e10cSrcweir and should always called in our destructor to guarantee consistency of config data. 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir @seealso baseclass ConfigItem 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir @param - 205*cdf0e10cSrcweir @return - 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir @onerror - 208*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir virtual void Commit(); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 213*cdf0e10cSrcweir // public interface 214*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir /*-****************************************************************************************************//** 217*cdf0e10cSrcweir @short base implementation of public interface for "SvtDynamicMenuOptions"! 218*cdf0e10cSrcweir @descr These class is used as static member of "SvtDynamicMenuOptions" ... 219*cdf0e10cSrcweir => The code exist only for one time and isn't duplicated for every instance! 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir @seealso - 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir @param - 224*cdf0e10cSrcweir @return - 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir @onerror - 227*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir void Clear ( SvtCommandOptions::CmdOption eCmdOption ); 230*cdf0e10cSrcweir sal_Bool HasEntries ( SvtCommandOptions::CmdOption eOption ) const; 231*cdf0e10cSrcweir sal_Bool Lookup ( SvtCommandOptions::CmdOption eCmdOption, const OUString& ) const; 232*cdf0e10cSrcweir Sequence< OUString > GetList ( SvtCommandOptions::CmdOption eCmdOption ) const ; 233*cdf0e10cSrcweir void AddCommand ( SvtCommandOptions::CmdOption eCmdOption, 234*cdf0e10cSrcweir const OUString& sURL ); 235*cdf0e10cSrcweir void EstablisFrameCallback(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 238*cdf0e10cSrcweir // private methods 239*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir private: 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /*-****************************************************************************************************//** 244*cdf0e10cSrcweir @short return list of key names of our configuration management which represent oue module tree 245*cdf0e10cSrcweir @descr These methods return the current list of key names! We need it to get needed values from our 246*cdf0e10cSrcweir configuration management and support dynamical menu item lists! 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir @seealso - 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir @param "nDisabledCount" , returns count of menu entries for "new" 251*cdf0e10cSrcweir @return A list of configuration key names is returned. 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir @onerror - 254*cdf0e10cSrcweir *//*-*****************************************************************************************************/ 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir Sequence< OUString > impl_GetPropertyNames(); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 259*cdf0e10cSrcweir // private member 260*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------- 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir private: 263*cdf0e10cSrcweir SvtCmdOptions m_aDisabledCommands; 264*cdf0e10cSrcweir SvtFrameVector m_lFrames; 265*cdf0e10cSrcweir }; 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 268*cdf0e10cSrcweir // definitions 269*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir //***************************************************************************************************************** 272*cdf0e10cSrcweir // constructor 273*cdf0e10cSrcweir //***************************************************************************************************************** 274*cdf0e10cSrcweir SvtCommandOptions_Impl::SvtCommandOptions_Impl() 275*cdf0e10cSrcweir // Init baseclasses first 276*cdf0e10cSrcweir : ConfigItem( ROOTNODE_CMDOPTIONS ) 277*cdf0e10cSrcweir // Init member then... 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir // Get names and values of all accessable menu entries and fill internal structures. 280*cdf0e10cSrcweir // See impl_GetPropertyNames() for further informations. 281*cdf0e10cSrcweir Sequence< OUString > lNames = impl_GetPropertyNames (); 282*cdf0e10cSrcweir Sequence< Any > lValues = GetProperties ( lNames ); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir // Safe impossible cases. 285*cdf0e10cSrcweir // We need values from ALL configuration keys. 286*cdf0e10cSrcweir // Follow assignment use order of values in relation to our list of key names! 287*cdf0e10cSrcweir DBG_ASSERT( !(lNames.getLength()!=lValues.getLength()), "SvtCommandOptions_Impl::SvtCommandOptions_Impl()\nI miss some values of configuration keys!\n" ); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir // Copy values from list in right order to ouer internal member. 290*cdf0e10cSrcweir // Attention: List for names and values have an internal construction pattern! 291*cdf0e10cSrcweir sal_Int32 nItem = 0 ; 292*cdf0e10cSrcweir OUString sCmd ; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir // Set size of hash_map reach a used size of approx. 60% 295*cdf0e10cSrcweir m_aDisabledCommands.SetContainerSize( lNames.getLength() * 10 / 6 ); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // Get names/values for disabled commands. 298*cdf0e10cSrcweir for( nItem=0; nItem < lNames.getLength(); ++nItem ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir // Currently only one value 301*cdf0e10cSrcweir lValues[nItem] >>= sCmd; 302*cdf0e10cSrcweir m_aDisabledCommands.AddCommand( sCmd ); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir /*TODO: Not used in the moment! see Notify() ... 306*cdf0e10cSrcweir // Enable notification mechanism of ouer baseclass. 307*cdf0e10cSrcweir // We need it to get information about changes outside these class on ouer used configuration keys! */ 308*cdf0e10cSrcweir Sequence< OUString > aNotifySeq( 1 ); 309*cdf0e10cSrcweir aNotifySeq[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Disabled" )); 310*cdf0e10cSrcweir EnableNotification( aNotifySeq, sal_True ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir //***************************************************************************************************************** 314*cdf0e10cSrcweir // destructor 315*cdf0e10cSrcweir //***************************************************************************************************************** 316*cdf0e10cSrcweir SvtCommandOptions_Impl::~SvtCommandOptions_Impl() 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir // We must save our current values .. if user forget it! 319*cdf0e10cSrcweir if( IsModified() == sal_True ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir Commit(); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir //***************************************************************************************************************** 326*cdf0e10cSrcweir // public method 327*cdf0e10cSrcweir //***************************************************************************************************************** 328*cdf0e10cSrcweir void SvtCommandOptions_Impl::Notify( const Sequence< OUString >& ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir MutexGuard aGuard( SvtCommandOptions::GetOwnStaticMutex() ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir Sequence< OUString > lNames = impl_GetPropertyNames (); 333*cdf0e10cSrcweir Sequence< Any > lValues = GetProperties ( lNames ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir // Safe impossible cases. 336*cdf0e10cSrcweir // We need values from ALL configuration keys. 337*cdf0e10cSrcweir // Follow assignment use order of values in relation to our list of key names! 338*cdf0e10cSrcweir DBG_ASSERT( !(lNames.getLength()!=lValues.getLength()), "SvtCommandOptions_Impl::SvtCommandOptions_Impl()\nI miss some values of configuration keys!\n" ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // Copy values from list in right order to ouer internal member. 341*cdf0e10cSrcweir // Attention: List for names and values have an internal construction pattern! 342*cdf0e10cSrcweir sal_Int32 nItem = 0 ; 343*cdf0e10cSrcweir OUString sCmd ; 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir // Set size of hash_map reach a used size of approx. 60% 346*cdf0e10cSrcweir m_aDisabledCommands.Clear(); 347*cdf0e10cSrcweir m_aDisabledCommands.SetContainerSize( lNames.getLength() * 10 / 6 ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir // Get names/values for disabled commands. 350*cdf0e10cSrcweir for( nItem=0; nItem < lNames.getLength(); ++nItem ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir // Currently only one value 353*cdf0e10cSrcweir lValues[nItem] >>= sCmd; 354*cdf0e10cSrcweir m_aDisabledCommands.AddCommand( sCmd ); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir // dont forget to update all existing frames and her might cached dispatch objects! 358*cdf0e10cSrcweir // But look for already killed frames. We hold weak references instead of hard ones ... 359*cdf0e10cSrcweir for (SvtFrameVector::const_iterator pIt = m_lFrames.begin(); 360*cdf0e10cSrcweir pIt != m_lFrames.end() ; 361*cdf0e10cSrcweir ++pIt ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame(pIt->get(), ::com::sun::star::uno::UNO_QUERY); 364*cdf0e10cSrcweir if (xFrame.is()) 365*cdf0e10cSrcweir xFrame->contextChanged(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir //***************************************************************************************************************** 370*cdf0e10cSrcweir // public method 371*cdf0e10cSrcweir //***************************************************************************************************************** 372*cdf0e10cSrcweir void SvtCommandOptions_Impl::Commit() 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir DBG_ERROR( "SvtCommandOptions_Impl::Commit()\nNot implemented yet!\n" ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir //***************************************************************************************************************** 378*cdf0e10cSrcweir // public method 379*cdf0e10cSrcweir //***************************************************************************************************************** 380*cdf0e10cSrcweir void SvtCommandOptions_Impl::Clear( SvtCommandOptions::CmdOption eCmdOption ) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir switch( eCmdOption ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir case SvtCommandOptions::CMDOPTION_DISABLED: 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir m_aDisabledCommands.Clear(); 387*cdf0e10cSrcweir SetModified(); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir break; 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir default: 392*cdf0e10cSrcweir DBG_ASSERT( sal_False, "SvtCommandOptions_Impl::Clear()\nUnknown option type given!\n" ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir //***************************************************************************************************************** 397*cdf0e10cSrcweir // public method 398*cdf0e10cSrcweir //***************************************************************************************************************** 399*cdf0e10cSrcweir sal_Bool SvtCommandOptions_Impl::HasEntries( SvtCommandOptions::CmdOption eOption ) const 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir if ( eOption == SvtCommandOptions::CMDOPTION_DISABLED ) 402*cdf0e10cSrcweir return ( m_aDisabledCommands.HasEntries() > 0 ); 403*cdf0e10cSrcweir else 404*cdf0e10cSrcweir return sal_False; 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir //***************************************************************************************************************** 408*cdf0e10cSrcweir // public method 409*cdf0e10cSrcweir //***************************************************************************************************************** 410*cdf0e10cSrcweir Sequence< OUString > SvtCommandOptions_Impl::GetList( SvtCommandOptions::CmdOption eCmdOption ) const 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir Sequence< OUString > lReturn; 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir switch( eCmdOption ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir case SvtCommandOptions::CMDOPTION_DISABLED: 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir lReturn = m_aDisabledCommands.GetList(); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir break; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir default: 423*cdf0e10cSrcweir DBG_ASSERT( sal_False, "SvtCommandOptions_Impl::GetList()\nUnknown option type given!\n" ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir return lReturn; 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir //***************************************************************************************************************** 430*cdf0e10cSrcweir // public method 431*cdf0e10cSrcweir //***************************************************************************************************************** 432*cdf0e10cSrcweir sal_Bool SvtCommandOptions_Impl::Lookup( SvtCommandOptions::CmdOption eCmdOption, const OUString& aCommand ) const 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir switch( eCmdOption ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir case SvtCommandOptions::CMDOPTION_DISABLED: 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir return m_aDisabledCommands.Lookup( aCommand ); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir default: 441*cdf0e10cSrcweir DBG_ASSERT( sal_False, "SvtCommandOptions_Impl::GetList()\nUnknown option type given!\n" ); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir return sal_False; 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir //***************************************************************************************************************** 448*cdf0e10cSrcweir // public method 449*cdf0e10cSrcweir //***************************************************************************************************************** 450*cdf0e10cSrcweir void SvtCommandOptions_Impl::AddCommand( SvtCommandOptions::CmdOption eCmdOption, const OUString& sCmd ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir switch( eCmdOption ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir case SvtCommandOptions::CMDOPTION_DISABLED: 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir m_aDisabledCommands.AddCommand( sCmd ); 457*cdf0e10cSrcweir SetModified(); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir break; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir default: 462*cdf0e10cSrcweir DBG_ASSERT( sal_False, "SvtCommandOptions_Impl::GetList()\nUnknown option type given!\n" ); 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir //***************************************************************************************************************** 467*cdf0e10cSrcweir // public method 468*cdf0e10cSrcweir //***************************************************************************************************************** 469*cdf0e10cSrcweir void SvtCommandOptions_Impl::EstablisFrameCallback(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir // check if frame already exists inside list 472*cdf0e10cSrcweir // ignore double registrations 473*cdf0e10cSrcweir // every frame must be notified one times only! 474*cdf0e10cSrcweir ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xWeak(xFrame); 475*cdf0e10cSrcweir SvtFrameVector::const_iterator pIt = ::std::find(m_lFrames.begin(), m_lFrames.end(), xWeak); 476*cdf0e10cSrcweir if (pIt == m_lFrames.end()) 477*cdf0e10cSrcweir m_lFrames.push_back(xWeak); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir //***************************************************************************************************************** 481*cdf0e10cSrcweir // private method 482*cdf0e10cSrcweir //***************************************************************************************************************** 483*cdf0e10cSrcweir Sequence< OUString > SvtCommandOptions_Impl::impl_GetPropertyNames() 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir // First get ALL names of current existing list items in configuration! 486*cdf0e10cSrcweir Sequence< OUString > lDisabledItems = GetNodeNames( SETNODE_DISABLED, utl::CONFIG_NAME_LOCAL_PATH ); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir OUString aSetNode( SETNODE_DISABLED ); 489*cdf0e10cSrcweir aSetNode += PATHDELIMITER; 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir OUString aCommandKey( PATHDELIMITER ); 492*cdf0e10cSrcweir aCommandKey += PROPERTYNAME_CMD; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir // Expand all keys 495*cdf0e10cSrcweir for (sal_Int32 i=0; i<lDisabledItems.getLength(); ++i ) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir OUStringBuffer aBuffer( 32 ); 498*cdf0e10cSrcweir aBuffer.append( aSetNode ); 499*cdf0e10cSrcweir aBuffer.append( lDisabledItems[i] ); 500*cdf0e10cSrcweir aBuffer.append( aCommandKey ); 501*cdf0e10cSrcweir lDisabledItems[i] = aBuffer.makeStringAndClear(); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir // Return result. 505*cdf0e10cSrcweir return lDisabledItems; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir //***************************************************************************************************************** 509*cdf0e10cSrcweir // initialize static member 510*cdf0e10cSrcweir // DON'T DO IT IN YOUR HEADER! 511*cdf0e10cSrcweir // see definition for further informations 512*cdf0e10cSrcweir //***************************************************************************************************************** 513*cdf0e10cSrcweir SvtCommandOptions_Impl* SvtCommandOptions::m_pDataContainer = NULL ; 514*cdf0e10cSrcweir sal_Int32 SvtCommandOptions::m_nRefCount = 0 ; 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir //***************************************************************************************************************** 517*cdf0e10cSrcweir // constructor 518*cdf0e10cSrcweir //***************************************************************************************************************** 519*cdf0e10cSrcweir SvtCommandOptions::SvtCommandOptions() 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir // Global access, must be guarded (multithreading!). 522*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 523*cdf0e10cSrcweir // Increase ouer refcount ... 524*cdf0e10cSrcweir ++m_nRefCount; 525*cdf0e10cSrcweir // ... and initialize ouer data container only if it not already exist! 526*cdf0e10cSrcweir if( m_pDataContainer == NULL ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir m_pDataContainer = new SvtCommandOptions_Impl; 529*cdf0e10cSrcweir ItemHolder1::holdConfigItem(E_CMDOPTIONS); 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir //***************************************************************************************************************** 534*cdf0e10cSrcweir // destructor 535*cdf0e10cSrcweir //***************************************************************************************************************** 536*cdf0e10cSrcweir SvtCommandOptions::~SvtCommandOptions() 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir // Global access, must be guarded (multithreading!) 539*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 540*cdf0e10cSrcweir // Decrease ouer refcount. 541*cdf0e10cSrcweir --m_nRefCount; 542*cdf0e10cSrcweir // If last instance was deleted ... 543*cdf0e10cSrcweir // we must destroy ouer static data container! 544*cdf0e10cSrcweir if( m_nRefCount <= 0 ) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir delete m_pDataContainer; 547*cdf0e10cSrcweir m_pDataContainer = NULL; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir //***************************************************************************************************************** 552*cdf0e10cSrcweir // public method 553*cdf0e10cSrcweir //***************************************************************************************************************** 554*cdf0e10cSrcweir void SvtCommandOptions::Clear( CmdOption eCmdOption ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 557*cdf0e10cSrcweir m_pDataContainer->Clear( eCmdOption ); 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir //***************************************************************************************************************** 561*cdf0e10cSrcweir // public method 562*cdf0e10cSrcweir //***************************************************************************************************************** 563*cdf0e10cSrcweir sal_Bool SvtCommandOptions::HasEntries( CmdOption eOption ) const 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 566*cdf0e10cSrcweir return m_pDataContainer->HasEntries( eOption ); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir //***************************************************************************************************************** 570*cdf0e10cSrcweir // public method 571*cdf0e10cSrcweir //***************************************************************************************************************** 572*cdf0e10cSrcweir sal_Bool SvtCommandOptions::Lookup( CmdOption eCmdOption, const OUString& aCommandURL ) const 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 575*cdf0e10cSrcweir return m_pDataContainer->Lookup( eCmdOption, aCommandURL ); 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir //***************************************************************************************************************** 579*cdf0e10cSrcweir // public method 580*cdf0e10cSrcweir //***************************************************************************************************************** 581*cdf0e10cSrcweir Sequence< OUString > SvtCommandOptions::GetList( CmdOption eCmdOption ) const 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 584*cdf0e10cSrcweir return m_pDataContainer->GetList( eCmdOption ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir //***************************************************************************************************************** 588*cdf0e10cSrcweir // public method 589*cdf0e10cSrcweir //***************************************************************************************************************** 590*cdf0e10cSrcweir void SvtCommandOptions::AddCommand( CmdOption eCmdOption, const OUString& sURL ) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 593*cdf0e10cSrcweir m_pDataContainer->AddCommand( eCmdOption, sURL ); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir //***************************************************************************************************************** 597*cdf0e10cSrcweir // public method 598*cdf0e10cSrcweir //***************************************************************************************************************** 599*cdf0e10cSrcweir void SvtCommandOptions::EstablisFrameCallback(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 602*cdf0e10cSrcweir m_pDataContainer->EstablisFrameCallback(xFrame); 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir //***************************************************************************************************************** 606*cdf0e10cSrcweir // private method 607*cdf0e10cSrcweir //***************************************************************************************************************** 608*cdf0e10cSrcweir Mutex& SvtCommandOptions::GetOwnStaticMutex() 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir // Initialize static mutex only for one time! 611*cdf0e10cSrcweir static Mutex* pMutex = NULL; 612*cdf0e10cSrcweir // If these method first called (Mutex not already exist!) ... 613*cdf0e10cSrcweir if( pMutex == NULL ) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir // ... we must create a new one. Protect follow code with the global mutex - 616*cdf0e10cSrcweir // It must be - we create a static variable! 617*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 618*cdf0e10cSrcweir // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these! 619*cdf0e10cSrcweir if( pMutex == NULL ) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir // Create the new mutex and set it for return on static variable. 622*cdf0e10cSrcweir static Mutex aMutex; 623*cdf0e10cSrcweir pMutex = &aMutex; 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir // Return new created or already existing mutex object. 627*cdf0e10cSrcweir return *pMutex; 628*cdf0e10cSrcweir } 629