merge the formfield patch from ooo-build
[ooovba.git] / framework / source / uielement / uicommanddescription.cxx
blobe13ed0e97475a5e48cd68a192f003173c962b961
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uicommanddescription.cxx,v $
10 * $Revision: 1.17.34.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include "uielement/uicommanddescription.hxx"
38 #include <threadhelp/resetableguard.hxx>
39 #include "services.h"
41 #include "properties.h"
43 //_________________________________________________________________________________________________________________
44 // interface includes
45 //_________________________________________________________________________________________________________________
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #include <com/sun/star/container/XNameContainer.hpp>
50 #include <com/sun/star/container/XContainer.hpp>
52 //_________________________________________________________________________________________________________________
53 // includes of other projects
54 //_________________________________________________________________________________________________________________
55 #include <rtl/ustrbuf.hxx>
56 #include <cppuhelper/implbase2.hxx>
57 #include <unotools/configmgr.hxx>
58 #include <tools/string.hxx>
60 #ifndef _VCL_MNEMONIC_HXX_
61 #include <vcl/mnemonic.hxx>
62 #endif
63 #include <comphelper/sequence.hxx>
64 #include <rtl/logfile.hxx>
66 //_________________________________________________________________________________________________________________
67 // Defines
68 //_________________________________________________________________________________________________________________
71 using namespace com::sun::star::uno;
72 using namespace com::sun::star::lang;
73 using namespace com::sun::star::beans;
74 using namespace com::sun::star::container;
75 using namespace ::com::sun::star::frame;
77 //_________________________________________________________________________________________________________________
78 // Namespace
79 //_________________________________________________________________________________________________________________
82 struct ModuleToCommands
84 const char* pModuleId;
85 const char* pCommands;
88 static const char GENERIC_UICOMMANDS[] = "generic";
89 static const char COMMANDS[] = "Commands";
90 static const char CONFIGURATION_ROOT_ACCESS[] = "/org.openoffice.Office.UI.";
91 static const char CONFIGURATION_CMD_ELEMENT_ACCESS[] = "/UserInterface/Commands";
92 static const char CONFIGURATION_POP_ELEMENT_ACCESS[] = "/UserInterface/Popups";
93 static const char CONFIGURATION_PROPERTY_LABEL[] = "Label";
94 static const char CONFIGURATION_PROPERTY_CONTEXT_LABEL[] = "ContextLabel";
96 // Property names of the resulting Property Set
97 static const char PROPSET_LABEL[] = "Label";
98 static const char PROPSET_NAME[] = "Name";
99 static const char PROPSET_POPUP[] = "Popup";
100 static const char PROPSET_PROPERTIES[] = "Properties";
102 // Special resource URLs to retrieve additional information
103 static const char PRIVATE_RESOURCE_URL[] = "private:";
105 const sal_Int32 COMMAND_PROPERTY_IMAGE = 1;
106 const sal_Int32 COMMAND_PROPERTY_ROTATE = 2;
107 const sal_Int32 COMMAND_PROPERTY_MIRROR = 4;
109 namespace framework
112 //*****************************************************************************************************************
113 // Configuration access class for PopupMenuControllerFactory implementation
114 //*****************************************************************************************************************
116 class ConfigurationAccess_UICommand : // Order is neccessary for right initialization!
117 private ThreadHelpBase ,
118 public ::cppu::WeakImplHelper2<XNameAccess,XContainerListener>
120 public:
121 ConfigurationAccess_UICommand( const ::rtl::OUString& aModuleName, const Reference< XNameAccess >& xGenericUICommands, const Reference< XMultiServiceFactory >& rServiceManager );
122 virtual ~ConfigurationAccess_UICommand();
124 // XNameAccess
125 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
126 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
128 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
129 throw (::com::sun::star::uno::RuntimeException);
131 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
132 throw (::com::sun::star::uno::RuntimeException);
134 // XElementAccess
135 virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
136 throw (::com::sun::star::uno::RuntimeException);
138 virtual sal_Bool SAL_CALL hasElements()
139 throw (::com::sun::star::uno::RuntimeException);
141 // container.XContainerListener
142 virtual void SAL_CALL elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException);
143 virtual void SAL_CALL elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException);
144 virtual void SAL_CALL elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException);
146 // lang.XEventListener
147 virtual void SAL_CALL disposing( const EventObject& aEvent ) throw(RuntimeException);
149 protected:
150 struct CmdToInfoMap
152 CmdToInfoMap() : bPopup( false ),
153 bCommandNameCreated( false ),
154 nProperties( 0 ) {}
156 rtl::OUString aLabel;
157 rtl::OUString aContextLabel;
158 rtl::OUString aCommandName;
159 bool bPopup : 1,
160 bCommandNameCreated : 1;
161 sal_Int32 nProperties;
164 Any getSequenceFromCache( const rtl::OUString& aCommandURL );
165 Any getInfoFromCommand( const rtl::OUString& rCommandURL );
166 void fillInfoFromResult( CmdToInfoMap& rCmdInfo, const rtl::OUString& aLabel );
167 Any getUILabelFromCommand( const rtl::OUString& rCommandURL );
168 Sequence< rtl::OUString > getAllCommands();
169 sal_Bool fillCache();
170 sal_Bool addGenericInfoToCache();
171 void impl_fill(const Reference< XNameAccess >& _xConfigAccess,sal_Bool _bPopup,
172 std::vector< ::rtl::OUString >& aImageCommandVector,
173 std::vector< ::rtl::OUString >& aImageRotateVector,
174 std::vector< ::rtl::OUString >& aImageMirrorVector);
176 private:
177 typedef ::std::hash_map< ::rtl::OUString,
178 CmdToInfoMap,
179 OUStringHashCode,
180 ::std::equal_to< ::rtl::OUString > > CommandToInfoCache;
182 sal_Bool initializeConfigAccess();
184 rtl::OUString m_aConfigCmdAccess;
185 rtl::OUString m_aConfigPopupAccess;
186 rtl::OUString m_aPropUILabel;
187 rtl::OUString m_aPropUIContextLabel;
188 rtl::OUString m_aPropLabel;
189 rtl::OUString m_aPropName;
190 rtl::OUString m_aPropPopup;
191 rtl::OUString m_aPropProperties;
192 rtl::OUString m_aBrandName;
193 rtl::OUString m_aXMLFileFormatVersion;
194 rtl::OUString m_aVersion;
195 rtl::OUString m_aExtension;
196 rtl::OUString m_aPrivateResourceURL;
197 Reference< XNameAccess > m_xGenericUICommands;
198 Reference< XMultiServiceFactory > m_xServiceManager;
199 Reference< XMultiServiceFactory > m_xConfigProvider;
200 //Reference< XMultiServiceFactory > m_xConfigProviderPopups;
201 Reference< XNameAccess > m_xConfigAccess;
202 Reference< XNameAccess > m_xConfigAccessPopups;
203 Sequence< rtl::OUString > m_aCommandImageList;
204 Sequence< rtl::OUString > m_aCommandRotateImageList;
205 Sequence< rtl::OUString > m_aCommandMirrorImageList;
206 CommandToInfoCache m_aCmdInfoCache;
207 sal_Bool m_bConfigAccessInitialized;
208 sal_Bool m_bCacheFilled;
209 sal_Bool m_bGenericDataRetrieved;
212 //*****************************************************************************************************************
213 // XInterface, XTypeProvider
214 //*****************************************************************************************************************
215 ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const rtl::OUString& aModuleName, const Reference< XNameAccess >& rGenericUICommands, const Reference< XMultiServiceFactory >& rServiceManager ) :
216 ThreadHelpBase(),
217 m_aConfigCmdAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
218 m_aConfigPopupAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
219 m_aPropUILabel( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_PROPERTY_LABEL )),
220 m_aPropUIContextLabel( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_PROPERTY_CONTEXT_LABEL )),
221 m_aPropLabel( RTL_CONSTASCII_USTRINGPARAM( PROPSET_LABEL )),
222 m_aPropName( RTL_CONSTASCII_USTRINGPARAM( PROPSET_NAME )),
223 m_aPropPopup( RTL_CONSTASCII_USTRINGPARAM( PROPSET_POPUP )),
224 m_aPropProperties( RTL_CONSTASCII_USTRINGPARAM( PROPSET_PROPERTIES )),
225 m_aPrivateResourceURL( RTL_CONSTASCII_USTRINGPARAM( PRIVATE_RESOURCE_URL )),
226 m_xGenericUICommands( rGenericUICommands ),
227 m_xServiceManager( rServiceManager ),
228 m_bConfigAccessInitialized( sal_False ),
229 m_bCacheFilled( sal_False ),
230 m_bGenericDataRetrieved( sal_False )
232 // Create configuration hierachical access name
233 m_aConfigCmdAccess += aModuleName;
234 m_aConfigCmdAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_CMD_ELEMENT_ACCESS ));
236 m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY );
238 m_aConfigPopupAccess += aModuleName;
239 m_aConfigPopupAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_POP_ELEMENT_ACCESS ));
240 //m_xConfigProviderPopups = Reference< XMultiServiceFactory >( rServiceManager->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY );
242 rtl::OUString aTmp;
243 ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ) >>= aTmp;
244 m_aBrandName = aTmp;
247 ConfigurationAccess_UICommand::~ConfigurationAccess_UICommand()
249 // SAFE
250 ResetableGuard aLock( m_aLock );
251 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
252 if ( xContainer.is() )
253 xContainer->removeContainerListener( this );
254 xContainer = Reference< XContainer >( m_xConfigAccessPopups, UNO_QUERY );
255 if ( xContainer.is() )
256 xContainer->removeContainerListener( this );
259 // XNameAccess
260 Any SAL_CALL ConfigurationAccess_UICommand::getByName( const ::rtl::OUString& rCommandURL )
261 throw ( NoSuchElementException, WrappedTargetException, RuntimeException)
263 static sal_Int32 nRequests = 0;
265 ResetableGuard aLock( m_aLock );
266 if ( !m_bConfigAccessInitialized )
268 initializeConfigAccess();
269 m_bConfigAccessInitialized = sal_True;
270 fillCache();
273 if ( rCommandURL.indexOf( m_aPrivateResourceURL ) == 0 )
275 // special keys to retrieve information about a set of commands
276 // SAFE
277 addGenericInfoToCache();
279 if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST ))
280 return makeAny( m_aCommandImageList );
281 else if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))
282 return makeAny( m_aCommandRotateImageList );
283 else if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))
284 return makeAny( m_aCommandMirrorImageList );
285 else
286 throw NoSuchElementException();
288 else
290 // SAFE
291 ++nRequests;
292 Any a = getInfoFromCommand( rCommandURL );
294 if ( !a.hasValue() )
295 throw NoSuchElementException();
297 return a;
301 Sequence< ::rtl::OUString > SAL_CALL ConfigurationAccess_UICommand::getElementNames()
302 throw ( RuntimeException )
304 return getAllCommands();
307 sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasByName( const ::rtl::OUString& rCommandURL )
308 throw (::com::sun::star::uno::RuntimeException)
310 return getByName( rCommandURL ).hasValue();
313 // XElementAccess
314 Type SAL_CALL ConfigurationAccess_UICommand::getElementType()
315 throw ( RuntimeException )
317 return( ::getCppuType( (const Sequence< PropertyValue >*)NULL ) );
320 sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasElements()
321 throw ( RuntimeException )
323 // There must are global commands!
324 return sal_True;
327 void ConfigurationAccess_UICommand::fillInfoFromResult( CmdToInfoMap& rCmdInfo, const rtl::OUString& aLabel )
329 String rStr( aLabel );
330 if ( rStr.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND )
331 rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", m_aBrandName );
332 rCmdInfo.aLabel = ::rtl::OUString( rStr );
333 rStr.EraseTrailingChars( '.' ); // Remove "..." from string
334 rCmdInfo.aCommandName = ::rtl::OUString( MnemonicGenerator::EraseAllMnemonicChars( rStr ));
335 rCmdInfo.bCommandNameCreated = sal_True;
338 Any ConfigurationAccess_UICommand::getSequenceFromCache( const ::rtl::OUString& aCommandURL )
340 CommandToInfoCache::iterator pIter = m_aCmdInfoCache.find( aCommandURL );
341 if ( pIter != m_aCmdInfoCache.end() )
343 if ( !pIter->second.bCommandNameCreated )
344 fillInfoFromResult( pIter->second, pIter->second.aLabel );
346 Sequence< PropertyValue > aPropSeq( 3 );
347 aPropSeq[0].Name = m_aPropLabel;
348 aPropSeq[0].Value = pIter->second.aContextLabel.getLength() ?
349 makeAny( pIter->second.aContextLabel ): makeAny( pIter->second.aLabel );
350 aPropSeq[1].Name = m_aPropName;
351 aPropSeq[1].Value <<= pIter->second.aCommandName;
352 aPropSeq[2].Name = m_aPropPopup;
353 aPropSeq[2].Value <<= pIter->second.bPopup;
354 return makeAny( aPropSeq );
357 return Any();
359 void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _xConfigAccess,sal_Bool _bPopup,
360 std::vector< ::rtl::OUString >& aImageCommandVector,
361 std::vector< ::rtl::OUString >& aImageRotateVector,
362 std::vector< ::rtl::OUString >& aImageMirrorVector)
364 if ( _xConfigAccess.is() )
366 Sequence< ::rtl::OUString> aNameSeq = _xConfigAccess->getElementNames();
367 const sal_Int32 nCount = aNameSeq.getLength();
368 for ( sal_Int32 i = 0; i < nCount; i++ )
372 Reference< XNameAccess > xNameAccess(_xConfigAccess->getByName( aNameSeq[i] ),UNO_QUERY);
373 if ( xNameAccess.is() )
375 CmdToInfoMap aCmdToInfo;
377 aCmdToInfo.bPopup = _bPopup;
378 xNameAccess->getByName( m_aPropUILabel ) >>= aCmdToInfo.aLabel;
379 xNameAccess->getByName( m_aPropUIContextLabel ) >>= aCmdToInfo.aContextLabel;
380 xNameAccess->getByName( m_aPropProperties ) >>= aCmdToInfo.nProperties;
382 m_aCmdInfoCache.insert( CommandToInfoCache::value_type( aNameSeq[i], aCmdToInfo ));
384 if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_IMAGE )
385 aImageCommandVector.push_back( aNameSeq[i] );
386 if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_ROTATE )
387 aImageRotateVector.push_back( aNameSeq[i] );
388 if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_MIRROR )
389 aImageMirrorVector.push_back( aNameSeq[i] );
392 catch ( com::sun::star::lang::WrappedTargetException& )
395 catch ( com::sun::star::container::NoSuchElementException& )
399 } // if ( m_xConfigAccessPopups.is() )
401 sal_Bool ConfigurationAccess_UICommand::fillCache()
403 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ConfigurationAccess_UICommand::fillCache" );
405 if ( m_bCacheFilled )
406 return sal_True;
408 std::vector< ::rtl::OUString > aImageCommandVector;
409 std::vector< ::rtl::OUString > aImageRotateVector;
410 std::vector< ::rtl::OUString > aImageMirrorVector;
412 impl_fill(m_xConfigAccess,sal_False,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
413 impl_fill(m_xConfigAccessPopups,sal_True,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
414 // Create cached sequences for fast retrieving
415 m_aCommandImageList = comphelper::containerToSequence( aImageCommandVector );
416 m_aCommandRotateImageList = comphelper::containerToSequence( aImageRotateVector );
417 m_aCommandMirrorImageList = comphelper::containerToSequence( aImageMirrorVector );
419 m_bCacheFilled = sal_True;
421 return sal_True;
424 sal_Bool ConfigurationAccess_UICommand::addGenericInfoToCache()
426 if ( m_xGenericUICommands.is() && !m_bGenericDataRetrieved )
428 Sequence< rtl::OUString > aCommandNameSeq;
431 if ( m_xGenericUICommands->getByName(
432 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))) >>= aCommandNameSeq )
433 m_aCommandRotateImageList = comphelper::concatSequences< rtl::OUString >( m_aCommandRotateImageList, aCommandNameSeq );
435 catch ( RuntimeException& e )
437 throw e;
439 catch ( Exception& )
445 if ( m_xGenericUICommands->getByName(
446 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))) >>= aCommandNameSeq )
447 m_aCommandMirrorImageList = comphelper::concatSequences< rtl::OUString >( m_aCommandMirrorImageList, aCommandNameSeq );
449 catch ( RuntimeException& e )
451 throw e;
453 catch ( Exception& )
457 m_bGenericDataRetrieved = sal_True;
460 return sal_True;
463 Any ConfigurationAccess_UICommand::getInfoFromCommand( const rtl::OUString& rCommandURL )
465 Any a;
469 a = getSequenceFromCache( rCommandURL );
470 if ( !a.hasValue() )
472 // First try to ask our global commands configuration access. It also caches maybe
473 // we find the entry in its cache first.
474 if ( m_xGenericUICommands.is() )
478 return m_xGenericUICommands->getByName( rCommandURL );
480 catch ( com::sun::star::lang::WrappedTargetException& )
483 catch ( com::sun::star::container::NoSuchElementException& )
489 catch( com::sun::star::container::NoSuchElementException& )
492 catch ( com::sun::star::lang::WrappedTargetException& )
496 return a;
499 Sequence< rtl::OUString > ConfigurationAccess_UICommand::getAllCommands()
501 // SAFE
502 ResetableGuard aLock( m_aLock );
504 if ( !m_bConfigAccessInitialized )
506 initializeConfigAccess();
507 m_bConfigAccessInitialized = sal_True;
508 fillCache();
511 if ( m_xConfigAccess.is() )
513 Reference< XNameAccess > xNameAccess;
517 Sequence< ::rtl::OUString > aNameSeq = m_xConfigAccess->getElementNames();
519 if ( m_xGenericUICommands.is() )
521 // Create concat list of supported user interface commands of the module
522 Sequence< ::rtl::OUString > aGenericNameSeq = m_xGenericUICommands->getElementNames();
523 sal_uInt32 nCount1 = aNameSeq.getLength();
524 sal_uInt32 nCount2 = aGenericNameSeq.getLength();
526 aNameSeq.realloc( nCount1 + nCount2 );
527 ::rtl::OUString* pNameSeq = aNameSeq.getArray();
528 const ::rtl::OUString* pGenericSeq = aGenericNameSeq.getConstArray();
529 for ( sal_uInt32 i = 0; i < nCount2; i++ )
530 pNameSeq[nCount1+i] = pGenericSeq[i];
533 return aNameSeq;
535 catch( com::sun::star::container::NoSuchElementException& )
538 catch ( com::sun::star::lang::WrappedTargetException& )
543 return Sequence< rtl::OUString >();
546 sal_Bool ConfigurationAccess_UICommand::initializeConfigAccess()
548 Sequence< Any > aArgs( 1 );
549 PropertyValue aPropValue;
553 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
554 aPropValue.Value <<= m_aConfigCmdAccess;
555 aArgs[0] <<= aPropValue;
557 m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ),UNO_QUERY );
558 if ( m_xConfigAccess.is() )
560 // Add as container listener
561 Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
562 if ( xContainer.is() )
563 xContainer->addContainerListener( this );
566 aPropValue.Value <<= m_aConfigPopupAccess;
567 aArgs[0] <<= aPropValue;
568 m_xConfigAccessPopups = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ),UNO_QUERY );
569 if ( m_xConfigAccessPopups.is() )
571 // Add as container listener
572 Reference< XContainer > xContainer( m_xConfigAccessPopups, UNO_QUERY );
573 if ( xContainer.is() )
574 xContainer->addContainerListener( this );
577 return sal_True;
579 catch ( WrappedTargetException& )
582 catch ( Exception& )
586 return sal_False;
589 // container.XContainerListener
590 void SAL_CALL ConfigurationAccess_UICommand::elementInserted( const ContainerEvent& ) throw(RuntimeException)
592 ResetableGuard aLock( m_aLock );
593 m_bCacheFilled = sal_False;
594 fillCache();
597 void SAL_CALL ConfigurationAccess_UICommand::elementRemoved( const ContainerEvent& ) throw(RuntimeException)
599 ResetableGuard aLock( m_aLock );
600 m_bCacheFilled = sal_False;
601 fillCache();
604 void SAL_CALL ConfigurationAccess_UICommand::elementReplaced( const ContainerEvent& ) throw(RuntimeException)
606 ResetableGuard aLock( m_aLock );
607 m_bCacheFilled = sal_False;
608 fillCache();
611 // lang.XEventListener
612 void SAL_CALL ConfigurationAccess_UICommand::disposing( const EventObject& aEvent ) throw(RuntimeException)
614 // SAFE
615 // remove our reference to the config access
616 ResetableGuard aLock( m_aLock );
618 Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
619 Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
620 if ( xIfac1 == xIfac2 )
621 m_xConfigAccess.clear();
622 else
624 xIfac2 = Reference< XInterface >( m_xConfigAccessPopups, UNO_QUERY );
625 if ( xIfac1 == xIfac2 )
626 m_xConfigAccessPopups.clear();
630 //*****************************************************************************************************************
631 // XInterface, XTypeProvider, XServiceInfo
632 //*****************************************************************************************************************
633 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( UICommandDescription ,
634 ::cppu::OWeakObject ,
635 SERVICENAME_UICOMMANDDESCRIPTION ,
636 IMPLEMENTATIONNAME_UICOMMANDDESCRIPTION
639 DEFINE_INIT_SERVICE ( UICommandDescription, {} )
641 UICommandDescription::UICommandDescription( const Reference< XMultiServiceFactory >& xServiceManager ) :
642 ThreadHelpBase(),
643 m_aPrivateResourceURL( RTL_CONSTASCII_USTRINGPARAM( PRIVATE_RESOURCE_URL )),
644 m_xServiceManager( xServiceManager )
646 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::UICommandDescription" );
647 Reference< XNameAccess > xEmpty;
648 rtl::OUString aGenericUICommand( ::rtl::OUString::createFromAscii( "GenericCommands" ));
649 m_xGenericUICommands = new ConfigurationAccess_UICommand( aGenericUICommand, xEmpty, xServiceManager );
651 impl_fillElements("ooSetupFactoryCommandConfigRef");
653 // insert generic commands
654 UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aGenericUICommand );
655 if ( pIter != m_aUICommandsHashMap.end() )
656 pIter->second = m_xGenericUICommands;
658 UICommandDescription::UICommandDescription( const Reference< XMultiServiceFactory >& xServiceManager,bool ) :
659 ThreadHelpBase(),
660 m_xServiceManager( xServiceManager )
663 UICommandDescription::~UICommandDescription()
665 ResetableGuard aLock( m_aLock );
666 m_aModuleToCommandFileMap.clear();
667 m_aUICommandsHashMap.clear();
668 m_xGenericUICommands.clear();
670 void UICommandDescription::impl_fillElements(const sal_Char* _pName)
672 m_xModuleManager.set( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ),UNO_QUERY );
673 Reference< XNameAccess > xNameAccess( m_xModuleManager, UNO_QUERY_THROW );
674 Sequence< rtl::OUString > aElementNames = xNameAccess->getElementNames();
675 Sequence< PropertyValue > aSeq;
676 ::rtl::OUString aModuleIdentifier;
678 for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
680 aModuleIdentifier = aElementNames[i];
681 if ( xNameAccess->getByName( aModuleIdentifier ) >>= aSeq )
683 ::rtl::OUString aCommandStr;
684 for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
686 if ( aSeq[y].Name.equalsAscii(_pName) )
688 aSeq[y].Value >>= aCommandStr;
689 break;
693 // Create first mapping ModuleIdentifier ==> Command File
694 m_aModuleToCommandFileMap.insert( ModuleToCommandFileMap::value_type( aModuleIdentifier, aCommandStr ));
696 // Create second mapping Command File ==> commands instance
697 UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandStr );
698 if ( pIter == m_aUICommandsHashMap.end() )
699 m_aUICommandsHashMap.insert( UICommandsHashMap::value_type( aCommandStr, Reference< XNameAccess >() ));
701 } // for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
703 Reference< XNameAccess > UICommandDescription::impl_createConfigAccess(const ::rtl::OUString& _sName)
705 return new ConfigurationAccess_UICommand( _sName,m_xGenericUICommands,m_xServiceManager );
708 Any SAL_CALL UICommandDescription::getByName( const ::rtl::OUString& aName )
709 throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
711 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getByName" );
712 Any a;
714 ResetableGuard aLock( m_aLock );
716 ModuleToCommandFileMap::const_iterator pM2CIter = m_aModuleToCommandFileMap.find( aName );
717 if ( pM2CIter != m_aModuleToCommandFileMap.end() )
719 ::rtl::OUString aCommandFile( pM2CIter->second );
720 UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandFile );
721 if ( pIter != m_aUICommandsHashMap.end() )
723 if ( pIter->second.is() )
724 a <<= pIter->second;
725 else
727 Reference< XNameAccess > xUICommands;
728 ConfigurationAccess_UICommand* pUICommands = new ConfigurationAccess_UICommand( aCommandFile,
729 m_xGenericUICommands,
730 m_xServiceManager );
731 xUICommands = Reference< XNameAccess >( static_cast< cppu::OWeakObject* >( pUICommands ),UNO_QUERY );
732 pIter->second = xUICommands;
733 a <<= xUICommands;
737 else if ( m_aPrivateResourceURL.getLength() && aName.indexOf( m_aPrivateResourceURL ) == 0 )
739 // special keys to retrieve information about a set of commands
740 return m_xGenericUICommands->getByName( aName );
742 else
744 throw NoSuchElementException();
747 return a;
750 Sequence< ::rtl::OUString > SAL_CALL UICommandDescription::getElementNames()
751 throw (::com::sun::star::uno::RuntimeException)
753 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getElementNames" );
754 ResetableGuard aLock( m_aLock );
756 Sequence< rtl::OUString > aSeq( m_aModuleToCommandFileMap.size() );
758 sal_Int32 n = 0;
759 ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.begin();
760 while ( pIter != m_aModuleToCommandFileMap.end() )
762 aSeq[n] = pIter->first;
763 ++pIter;
766 return aSeq;
769 sal_Bool SAL_CALL UICommandDescription::hasByName( const ::rtl::OUString& aName )
770 throw (::com::sun::star::uno::RuntimeException)
772 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::hasByName" );
773 ResetableGuard aLock( m_aLock );
775 ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.find( aName );
776 return ( pIter != m_aModuleToCommandFileMap.end() );
779 // XElementAccess
780 Type SAL_CALL UICommandDescription::getElementType()
781 throw (::com::sun::star::uno::RuntimeException)
783 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getElementType" );
784 return( ::getCppuType( (const Reference< XNameAccess >*)NULL ) );
787 sal_Bool SAL_CALL UICommandDescription::hasElements()
788 throw (::com::sun::star::uno::RuntimeException)
790 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::hasElements" );
791 // generic UI commands are always available!
792 return sal_True;
795 } // namespace framework