1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "uielement/uicommanddescription.hxx"
22 #include "properties.h"
24 #include "helper/mischelper.hxx"
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/ModuleManager.hpp>
29 #include <com/sun/star/configuration/theDefaultProvider.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <com/sun/star/container/XContainer.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include <cppuhelper/implbase2.hxx>
36 #include <unotools/configmgr.hxx>
38 #include <vcl/mnemonic.hxx>
39 #include <comphelper/sequence.hxx>
40 #include <comphelper/string.hxx>
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::lang
;
44 using namespace com::sun::star::beans
;
45 using namespace com::sun::star::configuration
;
46 using namespace com::sun::star::container
;
47 using namespace ::com::sun::star::frame
;
51 struct ModuleToCommands
53 const char* pModuleId
;
54 const char* pCommands
;
57 static const char CONFIGURATION_ROOT_ACCESS
[] = "/org.openoffice.Office.UI.";
58 static const char CONFIGURATION_CMD_ELEMENT_ACCESS
[] = "/UserInterface/Commands";
59 static const char CONFIGURATION_POP_ELEMENT_ACCESS
[] = "/UserInterface/Popups";
60 static const char CONFIGURATION_PROPERTY_LABEL
[] = "Label";
61 static const char CONFIGURATION_PROPERTY_CONTEXT_LABEL
[] = "ContextLabel";
63 // Property names of the resulting Property Set
64 static const char PROPSET_LABEL
[] = "Label";
65 static const char PROPSET_NAME
[] = "Name";
66 static const char PROPSET_POPUP
[] = "Popup";
67 static const char PROPSET_PROPERTIES
[] = "Properties";
69 // Special resource URLs to retrieve additional information
70 static const char PRIVATE_RESOURCE_URL
[] = "private:";
72 const sal_Int32 COMMAND_PROPERTY_IMAGE
= 1;
73 const sal_Int32 COMMAND_PROPERTY_ROTATE
= 2;
74 const sal_Int32 COMMAND_PROPERTY_MIRROR
= 4;
79 // Configuration access class for PopupMenuControllerFactory implementation
81 class ConfigurationAccess_UICommand
: // Order is necessary for right initialization!
82 public ::cppu::WeakImplHelper2
<XNameAccess
,XContainerListener
>
86 ConfigurationAccess_UICommand( const OUString
& aModuleName
, const Reference
< XNameAccess
>& xGenericUICommands
, const Reference
< XComponentContext
>& rxContext
);
87 virtual ~ConfigurationAccess_UICommand();
90 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const OUString
& aName
)
91 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
93 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getElementNames()
94 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
96 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
)
97 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
101 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 virtual sal_Bool SAL_CALL
hasElements()
104 throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
106 // container.XContainerListener
107 virtual void SAL_CALL
elementInserted( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 virtual void SAL_CALL
elementRemoved ( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 virtual void SAL_CALL
elementReplaced( const ContainerEvent
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 // lang.XEventListener
112 virtual void SAL_CALL
disposing( const EventObject
& aEvent
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 ::com::sun::star::uno::Any SAL_CALL
getByNameImpl( const OUString
& aName
);
119 CmdToInfoMap() : bPopup( false ),
120 bCommandNameCreated( false ),
124 OUString aContextLabel
;
125 OUString aCommandName
;
127 bCommandNameCreated
: 1;
128 sal_Int32 nProperties
;
131 Any
getSequenceFromCache( const OUString
& aCommandURL
);
132 Any
getInfoFromCommand( const OUString
& rCommandURL
);
133 void fillInfoFromResult( CmdToInfoMap
& rCmdInfo
, const OUString
& aLabel
);
134 Sequence
< OUString
> getAllCommands();
136 bool addGenericInfoToCache();
137 void impl_fill(const Reference
< XNameAccess
>& _xConfigAccess
,bool _bPopup
,
138 std::vector
< OUString
>& aImageCommandVector
,
139 std::vector
< OUString
>& aImageRotateVector
,
140 std::vector
< OUString
>& aImageMirrorVector
);
143 typedef std::unordered_map
< OUString
,
146 std::equal_to
< OUString
> > CommandToInfoCache
;
148 bool initializeConfigAccess();
150 OUString m_aConfigCmdAccess
;
151 OUString m_aConfigPopupAccess
;
152 OUString m_aPropUILabel
;
153 OUString m_aPropUIContextLabel
;
154 OUString m_aPropLabel
;
155 OUString m_aPropName
;
156 OUString m_aPropPopup
;
157 OUString m_aPropProperties
;
158 OUString m_aPrivateResourceURL
;
159 Reference
< XNameAccess
> m_xGenericUICommands
;
160 Reference
< XMultiServiceFactory
> m_xConfigProvider
;
161 Reference
< XNameAccess
> m_xConfigAccess
;
162 Reference
< XContainerListener
> m_xConfigListener
;
163 Reference
< XNameAccess
> m_xConfigAccessPopups
;
164 Reference
< XContainerListener
> m_xConfigAccessListener
;
165 Sequence
< OUString
> m_aCommandImageList
;
166 Sequence
< OUString
> m_aCommandRotateImageList
;
167 Sequence
< OUString
> m_aCommandMirrorImageList
;
168 CommandToInfoCache m_aCmdInfoCache
;
169 bool m_bConfigAccessInitialized
;
171 bool m_bGenericDataRetrieved
;
174 // XInterface, XTypeProvider
176 ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const OUString
& aModuleName
, const Reference
< XNameAccess
>& rGenericUICommands
, const Reference
< XComponentContext
>& rxContext
) :
177 m_aConfigCmdAccess( CONFIGURATION_ROOT_ACCESS
),
178 m_aConfigPopupAccess( CONFIGURATION_ROOT_ACCESS
),
179 m_aPropUILabel( CONFIGURATION_PROPERTY_LABEL
),
180 m_aPropUIContextLabel( CONFIGURATION_PROPERTY_CONTEXT_LABEL
),
181 m_aPropLabel( PROPSET_LABEL
),
182 m_aPropName( PROPSET_NAME
),
183 m_aPropPopup( PROPSET_POPUP
),
184 m_aPropProperties( PROPSET_PROPERTIES
),
185 m_aPrivateResourceURL( PRIVATE_RESOURCE_URL
),
186 m_xGenericUICommands( rGenericUICommands
),
187 m_bConfigAccessInitialized( false ),
188 m_bCacheFilled( false ),
189 m_bGenericDataRetrieved( false )
191 // Create configuration hierarchical access name
192 m_aConfigCmdAccess
+= aModuleName
;
193 m_aConfigCmdAccess
+= CONFIGURATION_CMD_ELEMENT_ACCESS
;
195 m_xConfigProvider
= theDefaultProvider::get( rxContext
);
197 m_aConfigPopupAccess
+= aModuleName
;
198 m_aConfigPopupAccess
+= CONFIGURATION_POP_ELEMENT_ACCESS
;
201 ConfigurationAccess_UICommand::~ConfigurationAccess_UICommand()
204 osl::MutexGuard
g(m_aMutex
);
205 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
206 if ( xContainer
.is() )
207 xContainer
->removeContainerListener(m_xConfigListener
);
208 xContainer
= Reference
< XContainer
>( m_xConfigAccessPopups
, UNO_QUERY
);
209 if ( xContainer
.is() )
210 xContainer
->removeContainerListener(m_xConfigAccessListener
);
214 Any SAL_CALL
ConfigurationAccess_UICommand::getByNameImpl( const OUString
& rCommandURL
)
216 static sal_Int32 nRequests
= 0;
218 osl::MutexGuard
g(m_aMutex
);
219 if ( !m_bConfigAccessInitialized
)
221 initializeConfigAccess();
222 m_bConfigAccessInitialized
= true;
226 if ( rCommandURL
.startsWith( m_aPrivateResourceURL
) )
228 // special keys to retrieve information about a set of commands
230 addGenericInfoToCache();
232 if ( rCommandURL
.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST
))
233 return makeAny( m_aCommandImageList
);
234 else if ( rCommandURL
.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST
))
235 return makeAny( m_aCommandRotateImageList
);
236 else if ( rCommandURL
.equalsIgnoreAsciiCase( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST
))
237 return makeAny( m_aCommandMirrorImageList
);
245 return getInfoFromCommand( rCommandURL
);
249 Any SAL_CALL
ConfigurationAccess_UICommand::getByName( const OUString
& rCommandURL
)
250 throw ( NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
252 Any
aRet( getByNameImpl( rCommandURL
) );
253 if( !aRet
.hasValue() )
254 throw NoSuchElementException();
259 Sequence
< OUString
> SAL_CALL
ConfigurationAccess_UICommand::getElementNames()
260 throw ( RuntimeException
, std::exception
)
262 return getAllCommands();
265 sal_Bool SAL_CALL
ConfigurationAccess_UICommand::hasByName( const OUString
& rCommandURL
)
266 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
268 return getByNameImpl( rCommandURL
).hasValue();
272 Type SAL_CALL
ConfigurationAccess_UICommand::getElementType()
273 throw ( RuntimeException
, std::exception
)
275 return( cppu::UnoType
<Sequence
< PropertyValue
>>::get() );
278 sal_Bool SAL_CALL
ConfigurationAccess_UICommand::hasElements()
279 throw ( RuntimeException
, std::exception
)
281 // There must are global commands!
285 void ConfigurationAccess_UICommand::fillInfoFromResult( CmdToInfoMap
& rCmdInfo
, const OUString
& aLabel
)
287 OUString
aStr(aLabel
.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName()));
288 rCmdInfo
.aLabel
= aStr
;
289 aStr
= comphelper::string::stripEnd(aStr
, '.'); // Remove "..." from string
290 rCmdInfo
.aCommandName
= MnemonicGenerator::EraseAllMnemonicChars(aStr
);
291 rCmdInfo
.bCommandNameCreated
= true;
294 Any
ConfigurationAccess_UICommand::getSequenceFromCache( const OUString
& aCommandURL
)
296 CommandToInfoCache::iterator pIter
= m_aCmdInfoCache
.find( aCommandURL
);
297 if ( pIter
!= m_aCmdInfoCache
.end() )
299 if ( !pIter
->second
.bCommandNameCreated
)
300 fillInfoFromResult( pIter
->second
, pIter
->second
.aLabel
);
302 Sequence
< PropertyValue
> aPropSeq( 4 );
303 aPropSeq
[0].Name
= m_aPropLabel
;
304 aPropSeq
[0].Value
= !pIter
->second
.aContextLabel
.isEmpty() ?
305 makeAny( pIter
->second
.aContextLabel
): makeAny( pIter
->second
.aLabel
);
306 aPropSeq
[1].Name
= m_aPropName
;
307 aPropSeq
[1].Value
<<= pIter
->second
.aCommandName
;
308 aPropSeq
[2].Name
= m_aPropPopup
;
309 aPropSeq
[2].Value
<<= pIter
->second
.bPopup
;
310 aPropSeq
[3].Name
= m_aPropProperties
;
311 aPropSeq
[3].Value
<<= pIter
->second
.nProperties
;
312 return makeAny( aPropSeq
);
317 void ConfigurationAccess_UICommand::impl_fill(const Reference
< XNameAccess
>& _xConfigAccess
,bool _bPopup
,
318 std::vector
< OUString
>& aImageCommandVector
,
319 std::vector
< OUString
>& aImageRotateVector
,
320 std::vector
< OUString
>& aImageMirrorVector
)
322 if ( _xConfigAccess
.is() )
324 Sequence
< OUString
> aNameSeq
= _xConfigAccess
->getElementNames();
325 const sal_Int32 nCount
= aNameSeq
.getLength();
326 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
330 Reference
< XNameAccess
> xNameAccess(_xConfigAccess
->getByName( aNameSeq
[i
] ),UNO_QUERY
);
331 if ( xNameAccess
.is() )
333 CmdToInfoMap aCmdToInfo
;
335 aCmdToInfo
.bPopup
= _bPopup
;
336 xNameAccess
->getByName( m_aPropUILabel
) >>= aCmdToInfo
.aLabel
;
337 xNameAccess
->getByName( m_aPropUIContextLabel
) >>= aCmdToInfo
.aContextLabel
;
338 xNameAccess
->getByName( m_aPropProperties
) >>= aCmdToInfo
.nProperties
;
340 m_aCmdInfoCache
.insert( CommandToInfoCache::value_type( aNameSeq
[i
], aCmdToInfo
));
342 if ( aCmdToInfo
.nProperties
& COMMAND_PROPERTY_IMAGE
)
343 aImageCommandVector
.push_back( aNameSeq
[i
] );
344 if ( aCmdToInfo
.nProperties
& COMMAND_PROPERTY_ROTATE
)
345 aImageRotateVector
.push_back( aNameSeq
[i
] );
346 if ( aCmdToInfo
.nProperties
& COMMAND_PROPERTY_MIRROR
)
347 aImageMirrorVector
.push_back( aNameSeq
[i
] );
350 catch (const com::sun::star::lang::WrappedTargetException
&)
353 catch (const com::sun::star::container::NoSuchElementException
&)
359 bool ConfigurationAccess_UICommand::fillCache()
362 if ( m_bCacheFilled
)
365 std::vector
< OUString
> aImageCommandVector
;
366 std::vector
< OUString
> aImageRotateVector
;
367 std::vector
< OUString
> aImageMirrorVector
;
369 impl_fill(m_xConfigAccess
,false,aImageCommandVector
,aImageRotateVector
,aImageMirrorVector
);
370 impl_fill(m_xConfigAccessPopups
,true,aImageCommandVector
,aImageRotateVector
,aImageMirrorVector
);
371 // Create cached sequences for fast retrieving
372 m_aCommandImageList
= comphelper::containerToSequence( aImageCommandVector
);
373 m_aCommandRotateImageList
= comphelper::containerToSequence( aImageRotateVector
);
374 m_aCommandMirrorImageList
= comphelper::containerToSequence( aImageMirrorVector
);
376 m_bCacheFilled
= true;
381 bool ConfigurationAccess_UICommand::addGenericInfoToCache()
383 if ( m_xGenericUICommands
.is() && !m_bGenericDataRetrieved
)
385 Sequence
< OUString
> aCommandNameSeq
;
388 if ( m_xGenericUICommands
->getByName(
389 OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST
)) >>= aCommandNameSeq
)
390 m_aCommandRotateImageList
= comphelper::concatSequences
< OUString
>( m_aCommandRotateImageList
, aCommandNameSeq
);
392 catch (const RuntimeException
&)
396 catch (const Exception
&)
402 if ( m_xGenericUICommands
->getByName(
403 OUString( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST
)) >>= aCommandNameSeq
)
404 m_aCommandMirrorImageList
= comphelper::concatSequences
< OUString
>( m_aCommandMirrorImageList
, aCommandNameSeq
);
406 catch (const RuntimeException
&)
410 catch (const Exception
&)
414 m_bGenericDataRetrieved
= true;
420 Any
ConfigurationAccess_UICommand::getInfoFromCommand( const OUString
& rCommandURL
)
426 a
= getSequenceFromCache( rCommandURL
);
429 // First try to ask our global commands configuration access. It also caches maybe
430 // we find the entry in its cache first.
431 if ( m_xGenericUICommands
.is() && m_xGenericUICommands
->hasByName( rCommandURL
) )
435 return m_xGenericUICommands
->getByName( rCommandURL
);
437 catch (const com::sun::star::lang::WrappedTargetException
&)
440 catch (const com::sun::star::container::NoSuchElementException
&)
446 catch (const com::sun::star::container::NoSuchElementException
&)
449 catch (const com::sun::star::lang::WrappedTargetException
&)
456 Sequence
< OUString
> ConfigurationAccess_UICommand::getAllCommands()
459 osl::MutexGuard
g(m_aMutex
);
461 if ( !m_bConfigAccessInitialized
)
463 initializeConfigAccess();
464 m_bConfigAccessInitialized
= true;
468 if ( m_xConfigAccess
.is() )
470 Reference
< XNameAccess
> xNameAccess
;
474 Sequence
< OUString
> aNameSeq
= m_xConfigAccess
->getElementNames();
476 if ( m_xGenericUICommands
.is() )
478 // Create concat list of supported user interface commands of the module
479 Sequence
< OUString
> aGenericNameSeq
= m_xGenericUICommands
->getElementNames();
480 sal_uInt32 nCount1
= aNameSeq
.getLength();
481 sal_uInt32 nCount2
= aGenericNameSeq
.getLength();
483 aNameSeq
.realloc( nCount1
+ nCount2
);
484 OUString
* pNameSeq
= aNameSeq
.getArray();
485 const OUString
* pGenericSeq
= aGenericNameSeq
.getConstArray();
486 for ( sal_uInt32 i
= 0; i
< nCount2
; i
++ )
487 pNameSeq
[nCount1
+i
] = pGenericSeq
[i
];
492 catch (const com::sun::star::container::NoSuchElementException
&)
495 catch (const com::sun::star::lang::WrappedTargetException
&)
500 return Sequence
< OUString
>();
503 bool ConfigurationAccess_UICommand::initializeConfigAccess()
505 Sequence
< Any
> aArgs( 1 );
506 PropertyValue aPropValue
;
510 aPropValue
.Name
= "nodepath";
511 aPropValue
.Value
<<= m_aConfigCmdAccess
;
512 aArgs
[0] <<= aPropValue
;
514 m_xConfigAccess
= Reference
< XNameAccess
>( m_xConfigProvider
->createInstanceWithArguments(
515 "com.sun.star.configuration.ConfigurationAccess", aArgs
),UNO_QUERY
);
516 if ( m_xConfigAccess
.is() )
518 // Add as container listener
519 Reference
< XContainer
> xContainer( m_xConfigAccess
, UNO_QUERY
);
520 if ( xContainer
.is() )
522 m_xConfigListener
= new WeakContainerListener(this);
523 xContainer
->addContainerListener(m_xConfigListener
);
527 aPropValue
.Value
<<= m_aConfigPopupAccess
;
528 aArgs
[0] <<= aPropValue
;
529 m_xConfigAccessPopups
= Reference
< XNameAccess
>( m_xConfigProvider
->createInstanceWithArguments(
530 "com.sun.star.configuration.ConfigurationAccess", aArgs
),UNO_QUERY
);
531 if ( m_xConfigAccessPopups
.is() )
533 // Add as container listener
534 Reference
< XContainer
> xContainer( m_xConfigAccessPopups
, UNO_QUERY
);
535 if ( xContainer
.is() )
537 m_xConfigAccessListener
= new WeakContainerListener(this);
538 xContainer
->addContainerListener(m_xConfigAccessListener
);
544 catch (const WrappedTargetException
&)
547 catch (const Exception
&)
554 // container.XContainerListener
555 void SAL_CALL
ConfigurationAccess_UICommand::elementInserted( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
557 osl::MutexGuard
g(m_aMutex
);
558 m_bCacheFilled
= false;
562 void SAL_CALL
ConfigurationAccess_UICommand::elementRemoved( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
564 osl::MutexGuard
g(m_aMutex
);
565 m_bCacheFilled
= false;
569 void SAL_CALL
ConfigurationAccess_UICommand::elementReplaced( const ContainerEvent
& ) throw(RuntimeException
, std::exception
)
571 osl::MutexGuard
g(m_aMutex
);
572 m_bCacheFilled
= false;
576 // lang.XEventListener
577 void SAL_CALL
ConfigurationAccess_UICommand::disposing( const EventObject
& aEvent
) throw(RuntimeException
, std::exception
)
580 // remove our reference to the config access
581 osl::MutexGuard
g(m_aMutex
);
583 Reference
< XInterface
> xIfac1( aEvent
.Source
, UNO_QUERY
);
584 Reference
< XInterface
> xIfac2( m_xConfigAccess
, UNO_QUERY
);
585 if ( xIfac1
== xIfac2
)
586 m_xConfigAccess
.clear();
589 xIfac2
= Reference
< XInterface
>( m_xConfigAccessPopups
, UNO_QUERY
);
590 if ( xIfac1
== xIfac2
)
591 m_xConfigAccessPopups
.clear();
595 UICommandDescription::UICommandDescription(const Reference
< XComponentContext
>& rxContext
)
596 : UICommandDescription_BASE(m_aMutex
)
597 , m_bConfigRead(false)
598 , m_aPrivateResourceURL(PRIVATE_RESOURCE_URL
)
599 , m_xContext(rxContext
)
601 Reference
< XNameAccess
> xEmpty
;
602 OUString
aGenericUICommand( "GenericCommands" );
603 m_xGenericUICommands
= new ConfigurationAccess_UICommand( aGenericUICommand
, xEmpty
, m_xContext
);
605 impl_fillElements("ooSetupFactoryCommandConfigRef");
607 // insert generic commands
608 UICommandsHashMap::iterator pIter
= m_aUICommandsHashMap
.find( aGenericUICommand
);
609 if ( pIter
!= m_aUICommandsHashMap
.end() )
610 pIter
->second
= m_xGenericUICommands
;
613 UICommandDescription::UICommandDescription(const Reference
< XComponentContext
>& rxContext
, bool)
614 : UICommandDescription_BASE(m_aMutex
)
615 , m_bConfigRead(false)
616 , m_xContext(rxContext
)
620 UICommandDescription::~UICommandDescription()
622 osl::MutexGuard
g(rBHelper
.rMutex
);
623 m_aModuleToCommandFileMap
.clear();
624 m_aUICommandsHashMap
.clear();
625 m_xGenericUICommands
.clear();
627 void UICommandDescription::impl_fillElements(const sal_Char
* _pName
)
629 m_xModuleManager
.set( ModuleManager::create( m_xContext
) );
630 Sequence
< OUString
> aElementNames
= m_xModuleManager
->getElementNames();
631 Sequence
< PropertyValue
> aSeq
;
632 OUString aModuleIdentifier
;
634 for ( sal_Int32 i
= 0; i
< aElementNames
.getLength(); i
++ )
636 aModuleIdentifier
= aElementNames
[i
];
637 if ( m_xModuleManager
->getByName( aModuleIdentifier
) >>= aSeq
)
639 OUString aCommandStr
;
640 for ( sal_Int32 y
= 0; y
< aSeq
.getLength(); y
++ )
642 if ( aSeq
[y
].Name
.equalsAscii(_pName
) )
644 aSeq
[y
].Value
>>= aCommandStr
;
649 // Create first mapping ModuleIdentifier ==> Command File
650 m_aModuleToCommandFileMap
.insert( ModuleToCommandFileMap::value_type( aModuleIdentifier
, aCommandStr
));
652 // Create second mapping Command File ==> commands instance
653 UICommandsHashMap::iterator pIter
= m_aUICommandsHashMap
.find( aCommandStr
);
654 if ( pIter
== m_aUICommandsHashMap
.end() )
655 m_aUICommandsHashMap
.insert( UICommandsHashMap::value_type( aCommandStr
, Reference
< XNameAccess
>() ));
657 } // for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
659 Reference
< XNameAccess
> UICommandDescription::impl_createConfigAccess(const OUString
& _sName
)
661 return new ConfigurationAccess_UICommand( _sName
, m_xGenericUICommands
, m_xContext
);
664 Any SAL_CALL
UICommandDescription::getByName( const OUString
& aName
)
665 throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
669 osl::MutexGuard
g(rBHelper
.rMutex
);
671 ModuleToCommandFileMap::const_iterator pM2CIter
= m_aModuleToCommandFileMap
.find( aName
);
672 if ( pM2CIter
!= m_aModuleToCommandFileMap
.end() )
674 OUString
aCommandFile( pM2CIter
->second
);
675 UICommandsHashMap::iterator pIter
= m_aUICommandsHashMap
.find( aCommandFile
);
676 if ( pIter
!= m_aUICommandsHashMap
.end() )
678 if ( pIter
->second
.is() )
682 Reference
< XNameAccess
> xUICommands
;
683 ConfigurationAccess_UICommand
* pUICommands
= new ConfigurationAccess_UICommand( aCommandFile
,
684 m_xGenericUICommands
,
686 xUICommands
= Reference
< XNameAccess
>( static_cast< cppu::OWeakObject
* >( pUICommands
),UNO_QUERY
);
687 pIter
->second
= xUICommands
;
692 else if ( !m_aPrivateResourceURL
.isEmpty() && aName
.startsWith( m_aPrivateResourceURL
) )
694 // special keys to retrieve information about a set of commands
695 return m_xGenericUICommands
->getByName( aName
);
699 throw NoSuchElementException();
705 Sequence
< OUString
> SAL_CALL
UICommandDescription::getElementNames()
706 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
708 osl::MutexGuard
g(rBHelper
.rMutex
);
710 Sequence
< OUString
> aSeq( m_aModuleToCommandFileMap
.size() );
713 ModuleToCommandFileMap::const_iterator pIter
= m_aModuleToCommandFileMap
.begin();
714 while ( pIter
!= m_aModuleToCommandFileMap
.end() )
716 aSeq
[n
++] = pIter
->first
;
723 sal_Bool SAL_CALL
UICommandDescription::hasByName( const OUString
& aName
)
724 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
726 osl::MutexGuard
g(rBHelper
.rMutex
);
728 ModuleToCommandFileMap::const_iterator pIter
= m_aModuleToCommandFileMap
.find( aName
);
729 return ( pIter
!= m_aModuleToCommandFileMap
.end() );
733 Type SAL_CALL
UICommandDescription::getElementType()
734 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
736 return( cppu::UnoType
<XNameAccess
>::get());
739 sal_Bool SAL_CALL
UICommandDescription::hasElements()
740 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
742 // generic UI commands are always available!
746 } // namespace framework
752 css::uno::Reference
<css::uno::XComponentContext
> const & context
):
753 instance(static_cast<cppu::OWeakObject
*>(
754 new framework::UICommandDescription(context
)))
758 css::uno::Reference
<css::uno::XInterface
> instance
;
762 public rtl::StaticWithArg
<
763 Instance
, css::uno::Reference
<css::uno::XComponentContext
>, Singleton
>
768 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
769 com_sun_star_comp_framework_UICommandDescription_get_implementation(
770 css::uno::XComponentContext
*context
,
771 css::uno::Sequence
<css::uno::Any
> const &)
773 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
774 Singleton::get(context
).instance
.get()));
777 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */