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