1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //	my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir #include "uielement/uicommanddescription.hxx"
31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32cdf0e10cSrcweir #include "services.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "properties.h"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir //	interface includes
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46cdf0e10cSrcweir //	includes of other projects
47cdf0e10cSrcweir //_________________________________________________________________________________________________________________
48cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
49cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
50cdf0e10cSrcweir #include <unotools/configmgr.hxx>
51cdf0e10cSrcweir #include <tools/string.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #ifndef _VCL_MNEMONIC_HXX_
54cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #include <comphelper/sequence.hxx>
57cdf0e10cSrcweir #include <rtl/logfile.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60cdf0e10cSrcweir //	Defines
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir //
63cdf0e10cSrcweir 
64cdf0e10cSrcweir using namespace com::sun::star::uno;
65cdf0e10cSrcweir using namespace com::sun::star::lang;
66cdf0e10cSrcweir using namespace com::sun::star::beans;
67cdf0e10cSrcweir using namespace com::sun::star::container;
68cdf0e10cSrcweir using namespace ::com::sun::star::frame;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //_________________________________________________________________________________________________________________
71cdf0e10cSrcweir //	Namespace
72cdf0e10cSrcweir //_________________________________________________________________________________________________________________
73cdf0e10cSrcweir //
74cdf0e10cSrcweir 
75cdf0e10cSrcweir struct ModuleToCommands
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     const char* pModuleId;
78cdf0e10cSrcweir     const char* pCommands;
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir static const char GENERIC_UICOMMANDS[]                  = "generic";
82cdf0e10cSrcweir static const char COMMANDS[]                            = "Commands";
83cdf0e10cSrcweir static const char CONFIGURATION_ROOT_ACCESS[]           = "/org.openoffice.Office.UI.";
84cdf0e10cSrcweir static const char CONFIGURATION_CMD_ELEMENT_ACCESS[]    = "/UserInterface/Commands";
85cdf0e10cSrcweir static const char CONFIGURATION_POP_ELEMENT_ACCESS[]    = "/UserInterface/Popups";
86cdf0e10cSrcweir static const char CONFIGURATION_PROPERTY_LABEL[]        = "Label";
87cdf0e10cSrcweir static const char CONFIGURATION_PROPERTY_CONTEXT_LABEL[] = "ContextLabel";
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // Property names of the resulting Property Set
90cdf0e10cSrcweir static const char PROPSET_LABEL[]                       = "Label";
91cdf0e10cSrcweir static const char PROPSET_NAME[]                        = "Name";
92cdf0e10cSrcweir static const char PROPSET_POPUP[]                       = "Popup";
93cdf0e10cSrcweir static const char PROPSET_PROPERTIES[]                  = "Properties";
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // Special resource URLs to retrieve additional information
96cdf0e10cSrcweir static const char PRIVATE_RESOURCE_URL[]                = "private:";
97cdf0e10cSrcweir 
98cdf0e10cSrcweir const sal_Int32   COMMAND_PROPERTY_IMAGE                = 1;
99cdf0e10cSrcweir const sal_Int32   COMMAND_PROPERTY_ROTATE               = 2;
100cdf0e10cSrcweir const sal_Int32   COMMAND_PROPERTY_MIRROR               = 4;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir namespace framework
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //*****************************************************************************************************************
106cdf0e10cSrcweir //	Configuration access class for PopupMenuControllerFactory implementation
107cdf0e10cSrcweir //*****************************************************************************************************************
108cdf0e10cSrcweir 
109cdf0e10cSrcweir class ConfigurationAccess_UICommand : // Order is neccessary for right initialization!
110cdf0e10cSrcweir                                         private ThreadHelpBase                           ,
111cdf0e10cSrcweir                                         public  ::cppu::WeakImplHelper2<XNameAccess,XContainerListener>
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     public:
114cdf0e10cSrcweir                                   ConfigurationAccess_UICommand( const ::rtl::OUString& aModuleName, const Reference< XNameAccess >& xGenericUICommands, const Reference< XMultiServiceFactory >& rServiceManager );
115cdf0e10cSrcweir         virtual                   ~ConfigurationAccess_UICommand();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         // XNameAccess
118cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
119cdf0e10cSrcweir             throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
122cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
125cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         // XElementAccess
128cdf0e10cSrcweir         virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
129cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         virtual sal_Bool SAL_CALL hasElements()
132cdf0e10cSrcweir             throw (::com::sun::star::uno::RuntimeException);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // container.XContainerListener
135cdf0e10cSrcweir         virtual void SAL_CALL     elementInserted( const ContainerEvent& aEvent ) throw(RuntimeException);
136cdf0e10cSrcweir         virtual void SAL_CALL     elementRemoved ( const ContainerEvent& aEvent ) throw(RuntimeException);
137cdf0e10cSrcweir         virtual void SAL_CALL     elementReplaced( const ContainerEvent& aEvent ) throw(RuntimeException);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         // lang.XEventListener
140cdf0e10cSrcweir         virtual void SAL_CALL disposing( const EventObject& aEvent ) throw(RuntimeException);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     protected:
143cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any SAL_CALL getByNameImpl( const ::rtl::OUString& aName );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         struct CmdToInfoMap
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             CmdToInfoMap() : bPopup( false ),
148cdf0e10cSrcweir                              bCommandNameCreated( false ),
149cdf0e10cSrcweir                              nProperties( 0 ) {}
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             rtl::OUString       aLabel;
152cdf0e10cSrcweir             rtl::OUString       aContextLabel;
153cdf0e10cSrcweir             rtl::OUString       aCommandName;
154cdf0e10cSrcweir             bool                bPopup : 1,
155cdf0e10cSrcweir                                 bCommandNameCreated : 1;
156cdf0e10cSrcweir             sal_Int32           nProperties;
157cdf0e10cSrcweir         };
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         Any                       getSequenceFromCache( const rtl::OUString& aCommandURL );
160cdf0e10cSrcweir         Any                       getInfoFromCommand( const rtl::OUString& rCommandURL );
161cdf0e10cSrcweir         void                      fillInfoFromResult( CmdToInfoMap& rCmdInfo, const rtl::OUString& aLabel );
162cdf0e10cSrcweir         Any                       getUILabelFromCommand( const rtl::OUString& rCommandURL );
163cdf0e10cSrcweir         Sequence< rtl::OUString > getAllCommands();
164cdf0e10cSrcweir         sal_Bool                  fillCache();
165cdf0e10cSrcweir         sal_Bool                  addGenericInfoToCache();
166cdf0e10cSrcweir         void                      impl_fill(const Reference< XNameAccess >& _xConfigAccess,sal_Bool _bPopup,
167cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageCommandVector,
168cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageRotateVector,
169cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageMirrorVector);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     private:
172cdf0e10cSrcweir         typedef ::std::hash_map< ::rtl::OUString,
173cdf0e10cSrcweir                                  CmdToInfoMap,
174cdf0e10cSrcweir                                  OUStringHashCode,
175cdf0e10cSrcweir                                  ::std::equal_to< ::rtl::OUString > > CommandToInfoCache;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         sal_Bool initializeConfigAccess();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         rtl::OUString                     m_aConfigCmdAccess;
180cdf0e10cSrcweir         rtl::OUString                     m_aConfigPopupAccess;
181cdf0e10cSrcweir         rtl::OUString                     m_aPropUILabel;
182cdf0e10cSrcweir         rtl::OUString                     m_aPropUIContextLabel;
183cdf0e10cSrcweir         rtl::OUString                     m_aPropLabel;
184cdf0e10cSrcweir         rtl::OUString                     m_aPropName;
185cdf0e10cSrcweir         rtl::OUString                     m_aPropPopup;
186cdf0e10cSrcweir         rtl::OUString                     m_aPropProperties;
187cdf0e10cSrcweir         rtl::OUString                     m_aBrandName;
188cdf0e10cSrcweir         rtl::OUString                     m_aXMLFileFormatVersion;
189cdf0e10cSrcweir         rtl::OUString                     m_aVersion;
190cdf0e10cSrcweir         rtl::OUString                     m_aExtension;
191cdf0e10cSrcweir         rtl::OUString                     m_aPrivateResourceURL;
192cdf0e10cSrcweir         Reference< XNameAccess >          m_xGenericUICommands;
193cdf0e10cSrcweir         Reference< XMultiServiceFactory > m_xServiceManager;
194cdf0e10cSrcweir         Reference< XMultiServiceFactory > m_xConfigProvider;
195cdf0e10cSrcweir         //Reference< XMultiServiceFactory > m_xConfigProviderPopups;
196cdf0e10cSrcweir         Reference< XNameAccess >          m_xConfigAccess;
197cdf0e10cSrcweir         Reference< XNameAccess >          m_xConfigAccessPopups;
198cdf0e10cSrcweir         Sequence< rtl::OUString >         m_aCommandImageList;
199cdf0e10cSrcweir         Sequence< rtl::OUString >         m_aCommandRotateImageList;
200cdf0e10cSrcweir         Sequence< rtl::OUString >         m_aCommandMirrorImageList;
201cdf0e10cSrcweir         CommandToInfoCache                m_aCmdInfoCache;
202cdf0e10cSrcweir         sal_Bool                          m_bConfigAccessInitialized;
203cdf0e10cSrcweir         sal_Bool                          m_bCacheFilled;
204cdf0e10cSrcweir         sal_Bool                          m_bGenericDataRetrieved;
205cdf0e10cSrcweir };
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //*****************************************************************************************************************
208cdf0e10cSrcweir //	XInterface, XTypeProvider
209cdf0e10cSrcweir //*****************************************************************************************************************
210cdf0e10cSrcweir ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const rtl::OUString& aModuleName, const Reference< XNameAccess >& rGenericUICommands, const Reference< XMultiServiceFactory >& rServiceManager ) :
211cdf0e10cSrcweir     ThreadHelpBase(),
212cdf0e10cSrcweir     m_aConfigCmdAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
213cdf0e10cSrcweir     m_aConfigPopupAccess( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_ROOT_ACCESS )),
214cdf0e10cSrcweir     m_aPropUILabel( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_PROPERTY_LABEL )),
215cdf0e10cSrcweir     m_aPropUIContextLabel( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_PROPERTY_CONTEXT_LABEL )),
216cdf0e10cSrcweir     m_aPropLabel( RTL_CONSTASCII_USTRINGPARAM( PROPSET_LABEL )),
217cdf0e10cSrcweir     m_aPropName( RTL_CONSTASCII_USTRINGPARAM( PROPSET_NAME )),
218cdf0e10cSrcweir     m_aPropPopup( RTL_CONSTASCII_USTRINGPARAM( PROPSET_POPUP )),
219cdf0e10cSrcweir     m_aPropProperties( RTL_CONSTASCII_USTRINGPARAM( PROPSET_PROPERTIES )),
220cdf0e10cSrcweir     m_aPrivateResourceURL( RTL_CONSTASCII_USTRINGPARAM( PRIVATE_RESOURCE_URL )),
221cdf0e10cSrcweir     m_xGenericUICommands( rGenericUICommands ),
222cdf0e10cSrcweir     m_xServiceManager( rServiceManager ),
223cdf0e10cSrcweir     m_bConfigAccessInitialized( sal_False ),
224cdf0e10cSrcweir     m_bCacheFilled( sal_False ),
225cdf0e10cSrcweir     m_bGenericDataRetrieved( sal_False )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     // Create configuration hierachical access name
228cdf0e10cSrcweir     m_aConfigCmdAccess += aModuleName;
229cdf0e10cSrcweir     m_aConfigCmdAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_CMD_ELEMENT_ACCESS ));
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     m_xConfigProvider = Reference< XMultiServiceFactory >( rServiceManager->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     m_aConfigPopupAccess += aModuleName;
234cdf0e10cSrcweir     m_aConfigPopupAccess += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIGURATION_POP_ELEMENT_ACCESS ));
235cdf0e10cSrcweir     //m_xConfigProviderPopups = Reference< XMultiServiceFactory >( rServiceManager->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     rtl::OUString aTmp;
238cdf0e10cSrcweir     ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ) >>= aTmp;
239cdf0e10cSrcweir     m_aBrandName = aTmp;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir ConfigurationAccess_UICommand::~ConfigurationAccess_UICommand()
243cdf0e10cSrcweir {
244cdf0e10cSrcweir     // SAFE
245cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
246cdf0e10cSrcweir     Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
247cdf0e10cSrcweir     if ( xContainer.is() )
248cdf0e10cSrcweir         xContainer->removeContainerListener( this );
249cdf0e10cSrcweir     xContainer = Reference< XContainer >( m_xConfigAccessPopups, UNO_QUERY );
250cdf0e10cSrcweir     if ( xContainer.is() )
251cdf0e10cSrcweir         xContainer->removeContainerListener( this );
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255cdf0e10cSrcweir // XNameAccess
256cdf0e10cSrcweir Any SAL_CALL ConfigurationAccess_UICommand::getByNameImpl( const ::rtl::OUString& rCommandURL )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     static sal_Int32 nRequests  = 0;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
261cdf0e10cSrcweir     if ( !m_bConfigAccessInitialized )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         initializeConfigAccess();
264cdf0e10cSrcweir         m_bConfigAccessInitialized = sal_True;
265cdf0e10cSrcweir         fillCache();
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     if ( rCommandURL.indexOf( m_aPrivateResourceURL ) == 0 )
269cdf0e10cSrcweir     {
270cdf0e10cSrcweir         // special keys to retrieve information about a set of commands
271cdf0e10cSrcweir         // SAFE
272cdf0e10cSrcweir         addGenericInfoToCache();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST ))
275cdf0e10cSrcweir             return makeAny( m_aCommandImageList );
276cdf0e10cSrcweir         else if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))
277cdf0e10cSrcweir             return makeAny( m_aCommandRotateImageList );
278cdf0e10cSrcweir         else if ( rCommandURL.equalsIgnoreAsciiCaseAscii( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))
279cdf0e10cSrcweir             return makeAny( m_aCommandMirrorImageList );
280cdf0e10cSrcweir         else
281cdf0e10cSrcweir             return Any();
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir     else
284cdf0e10cSrcweir     {
285cdf0e10cSrcweir         // SAFE
286cdf0e10cSrcweir         ++nRequests;
287cdf0e10cSrcweir         return getInfoFromCommand( rCommandURL );
288cdf0e10cSrcweir     }
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir Any SAL_CALL ConfigurationAccess_UICommand::getByName( const ::rtl::OUString& rCommandURL )
292cdf0e10cSrcweir throw ( NoSuchElementException, WrappedTargetException, RuntimeException)
293cdf0e10cSrcweir {
294cdf0e10cSrcweir 	Any aRet( getByNameImpl( rCommandURL ) );
295cdf0e10cSrcweir 	if( !aRet.hasValue() )
296cdf0e10cSrcweir 		throw NoSuchElementException();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	return aRet;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ConfigurationAccess_UICommand::getElementNames()
302cdf0e10cSrcweir throw ( RuntimeException )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     return getAllCommands();
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasByName( const ::rtl::OUString& rCommandURL )
308cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     return getByNameImpl( rCommandURL ).hasValue();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir // XElementAccess
314cdf0e10cSrcweir Type SAL_CALL ConfigurationAccess_UICommand::getElementType()
315cdf0e10cSrcweir throw ( RuntimeException )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     return( ::getCppuType( (const Sequence< PropertyValue >*)NULL ) );
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasElements()
321cdf0e10cSrcweir throw ( RuntimeException )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     // There must are global commands!
324cdf0e10cSrcweir     return sal_True;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir void ConfigurationAccess_UICommand::fillInfoFromResult( CmdToInfoMap& rCmdInfo, const rtl::OUString& aLabel )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     String rStr( aLabel );
330cdf0e10cSrcweir     if ( rStr.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND )
331cdf0e10cSrcweir         rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", m_aBrandName );
332cdf0e10cSrcweir     rCmdInfo.aLabel       = ::rtl::OUString( rStr );
333cdf0e10cSrcweir     rStr.EraseTrailingChars( '.' ); // Remove "..." from string
334cdf0e10cSrcweir     rCmdInfo.aCommandName = ::rtl::OUString( MnemonicGenerator::EraseAllMnemonicChars( rStr ));
335cdf0e10cSrcweir     rCmdInfo.bCommandNameCreated = sal_True;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir Any ConfigurationAccess_UICommand::getSequenceFromCache( const ::rtl::OUString& aCommandURL )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir     CommandToInfoCache::iterator pIter = m_aCmdInfoCache.find( aCommandURL );
341cdf0e10cSrcweir     if ( pIter != m_aCmdInfoCache.end() )
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         if ( !pIter->second.bCommandNameCreated )
344cdf0e10cSrcweir             fillInfoFromResult( pIter->second, pIter->second.aLabel );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir         Sequence< PropertyValue > aPropSeq( 4 );
347cdf0e10cSrcweir         aPropSeq[0].Name  = m_aPropLabel;
348cdf0e10cSrcweir         aPropSeq[0].Value = pIter->second.aContextLabel.getLength() ?
349cdf0e10cSrcweir                 makeAny( pIter->second.aContextLabel ): makeAny( pIter->second.aLabel );
350cdf0e10cSrcweir         aPropSeq[1].Name  = m_aPropName;
351cdf0e10cSrcweir         aPropSeq[1].Value <<= pIter->second.aCommandName;
352cdf0e10cSrcweir         aPropSeq[2].Name  = m_aPropPopup;
353cdf0e10cSrcweir         aPropSeq[2].Value <<= pIter->second.bPopup;
354cdf0e10cSrcweir         aPropSeq[3].Name  = m_aPropProperties;
355cdf0e10cSrcweir         aPropSeq[3].Value <<= pIter->second.nProperties;
356cdf0e10cSrcweir         return makeAny( aPropSeq );
357cdf0e10cSrcweir     }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     return Any();
360cdf0e10cSrcweir }
361cdf0e10cSrcweir void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _xConfigAccess,sal_Bool _bPopup,
362cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageCommandVector,
363cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageRotateVector,
364cdf0e10cSrcweir                                                 std::vector< ::rtl::OUString >& aImageMirrorVector)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     if ( _xConfigAccess.is() )
367cdf0e10cSrcweir     {
368cdf0e10cSrcweir         Sequence< ::rtl::OUString> aNameSeq = _xConfigAccess->getElementNames();
369cdf0e10cSrcweir         const sal_Int32 nCount = aNameSeq.getLength();
370cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < nCount; i++ )
371cdf0e10cSrcweir         {
372cdf0e10cSrcweir             try
373cdf0e10cSrcweir             {
374cdf0e10cSrcweir                 Reference< XNameAccess > xNameAccess(_xConfigAccess->getByName( aNameSeq[i] ),UNO_QUERY);
375cdf0e10cSrcweir                 if ( xNameAccess.is() )
376cdf0e10cSrcweir                 {
377cdf0e10cSrcweir                     CmdToInfoMap aCmdToInfo;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir                     aCmdToInfo.bPopup = _bPopup;
380cdf0e10cSrcweir                     xNameAccess->getByName( m_aPropUILabel )        >>= aCmdToInfo.aLabel;
381cdf0e10cSrcweir                     xNameAccess->getByName( m_aPropUIContextLabel ) >>= aCmdToInfo.aContextLabel;
382cdf0e10cSrcweir                     xNameAccess->getByName( m_aPropProperties )     >>= aCmdToInfo.nProperties;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir                     m_aCmdInfoCache.insert( CommandToInfoCache::value_type( aNameSeq[i], aCmdToInfo ));
385cdf0e10cSrcweir 
386cdf0e10cSrcweir                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_IMAGE )
387cdf0e10cSrcweir                         aImageCommandVector.push_back( aNameSeq[i] );
388cdf0e10cSrcweir                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_ROTATE )
389cdf0e10cSrcweir                         aImageRotateVector.push_back( aNameSeq[i] );
390cdf0e10cSrcweir                     if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_MIRROR )
391cdf0e10cSrcweir                         aImageMirrorVector.push_back( aNameSeq[i] );
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir             catch ( com::sun::star::lang::WrappedTargetException& )
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir             }
397cdf0e10cSrcweir             catch ( com::sun::star::container::NoSuchElementException& )
398cdf0e10cSrcweir             {
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir     } // if ( m_xConfigAccessPopups.is() )
402cdf0e10cSrcweir }
403cdf0e10cSrcweir sal_Bool ConfigurationAccess_UICommand::fillCache()
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::ConfigurationAccess_UICommand::fillCache" );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     if ( m_bCacheFilled )
408cdf0e10cSrcweir         return sal_True;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     std::vector< ::rtl::OUString > aImageCommandVector;
411cdf0e10cSrcweir     std::vector< ::rtl::OUString > aImageRotateVector;
412cdf0e10cSrcweir     std::vector< ::rtl::OUString > aImageMirrorVector;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     impl_fill(m_xConfigAccess,sal_False,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
415cdf0e10cSrcweir     impl_fill(m_xConfigAccessPopups,sal_True,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
416cdf0e10cSrcweir     // Create cached sequences for fast retrieving
417cdf0e10cSrcweir     m_aCommandImageList       = comphelper::containerToSequence( aImageCommandVector );
418cdf0e10cSrcweir     m_aCommandRotateImageList = comphelper::containerToSequence( aImageRotateVector );
419cdf0e10cSrcweir     m_aCommandMirrorImageList = comphelper::containerToSequence( aImageMirrorVector );
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     m_bCacheFilled = sal_True;
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     return sal_True;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir sal_Bool ConfigurationAccess_UICommand::addGenericInfoToCache()
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     if ( m_xGenericUICommands.is() && !m_bGenericDataRetrieved )
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         Sequence< rtl::OUString > aCommandNameSeq;
431cdf0e10cSrcweir         try
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir             if ( m_xGenericUICommands->getByName(
434cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST ))) >>= aCommandNameSeq )
435cdf0e10cSrcweir                 m_aCommandRotateImageList = comphelper::concatSequences< rtl::OUString >( m_aCommandRotateImageList, aCommandNameSeq );
436cdf0e10cSrcweir         }
437cdf0e10cSrcweir         catch ( RuntimeException& e )
438cdf0e10cSrcweir         {
439cdf0e10cSrcweir             throw e;
440cdf0e10cSrcweir         }
441cdf0e10cSrcweir         catch ( Exception& )
442cdf0e10cSrcweir         {
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir         try
446cdf0e10cSrcweir         {
447cdf0e10cSrcweir             if ( m_xGenericUICommands->getByName(
448cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST ))) >>= aCommandNameSeq )
449cdf0e10cSrcweir                 m_aCommandMirrorImageList = comphelper::concatSequences< rtl::OUString >( m_aCommandMirrorImageList, aCommandNameSeq );
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir         catch ( RuntimeException& e )
452cdf0e10cSrcweir         {
453cdf0e10cSrcweir             throw e;
454cdf0e10cSrcweir         }
455cdf0e10cSrcweir         catch ( Exception& )
456cdf0e10cSrcweir         {
457cdf0e10cSrcweir         }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         m_bGenericDataRetrieved = sal_True;
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     return sal_True;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir Any ConfigurationAccess_UICommand::getInfoFromCommand( const rtl::OUString& rCommandURL )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     Any a;
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     try
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         a = getSequenceFromCache( rCommandURL );
472cdf0e10cSrcweir         if ( !a.hasValue() )
473cdf0e10cSrcweir         {
474cdf0e10cSrcweir             // First try to ask our global commands configuration access. It also caches maybe
475cdf0e10cSrcweir             // we find the entry in its cache first.
476cdf0e10cSrcweir             if ( m_xGenericUICommands.is() && m_xGenericUICommands->hasByName( rCommandURL ) )
477cdf0e10cSrcweir             {
478cdf0e10cSrcweir                 try
479cdf0e10cSrcweir                 {
480cdf0e10cSrcweir                     return m_xGenericUICommands->getByName( rCommandURL );
481cdf0e10cSrcweir                 }
482cdf0e10cSrcweir                 catch ( com::sun::star::lang::WrappedTargetException& )
483cdf0e10cSrcweir                 {
484cdf0e10cSrcweir                 }
485cdf0e10cSrcweir                 catch ( com::sun::star::container::NoSuchElementException& )
486cdf0e10cSrcweir                 {
487cdf0e10cSrcweir                 }
488cdf0e10cSrcweir             }
489cdf0e10cSrcweir         }
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir     catch( com::sun::star::container::NoSuchElementException& )
492cdf0e10cSrcweir     {
493cdf0e10cSrcweir     }
494cdf0e10cSrcweir     catch ( com::sun::star::lang::WrappedTargetException& )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     return a;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir Sequence< rtl::OUString > ConfigurationAccess_UICommand::getAllCommands()
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     // SAFE
504cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     if ( !m_bConfigAccessInitialized )
507cdf0e10cSrcweir     {
508cdf0e10cSrcweir         initializeConfigAccess();
509cdf0e10cSrcweir         m_bConfigAccessInitialized = sal_True;
510cdf0e10cSrcweir         fillCache();
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     if ( m_xConfigAccess.is() )
514cdf0e10cSrcweir     {
515cdf0e10cSrcweir         Reference< XNameAccess > xNameAccess;
516cdf0e10cSrcweir 
517cdf0e10cSrcweir         try
518cdf0e10cSrcweir         {
519cdf0e10cSrcweir             Sequence< ::rtl::OUString > aNameSeq = m_xConfigAccess->getElementNames();
520cdf0e10cSrcweir 
521cdf0e10cSrcweir             if ( m_xGenericUICommands.is() )
522cdf0e10cSrcweir             {
523cdf0e10cSrcweir                 // Create concat list of supported user interface commands of the module
524cdf0e10cSrcweir                 Sequence< ::rtl::OUString > aGenericNameSeq = m_xGenericUICommands->getElementNames();
525cdf0e10cSrcweir                 sal_uInt32 nCount1 = aNameSeq.getLength();
526cdf0e10cSrcweir                 sal_uInt32 nCount2 = aGenericNameSeq.getLength();
527cdf0e10cSrcweir 
528cdf0e10cSrcweir                 aNameSeq.realloc( nCount1 + nCount2 );
529cdf0e10cSrcweir                 ::rtl::OUString* pNameSeq = aNameSeq.getArray();
530cdf0e10cSrcweir                 const ::rtl::OUString* pGenericSeq = aGenericNameSeq.getConstArray();
531cdf0e10cSrcweir                 for ( sal_uInt32 i = 0; i < nCount2; i++ )
532cdf0e10cSrcweir                     pNameSeq[nCount1+i] = pGenericSeq[i];
533cdf0e10cSrcweir             }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir             return aNameSeq;
536cdf0e10cSrcweir         }
537cdf0e10cSrcweir         catch( com::sun::star::container::NoSuchElementException& )
538cdf0e10cSrcweir         {
539cdf0e10cSrcweir         }
540cdf0e10cSrcweir         catch ( com::sun::star::lang::WrappedTargetException& )
541cdf0e10cSrcweir         {
542cdf0e10cSrcweir         }
543cdf0e10cSrcweir     }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     return Sequence< rtl::OUString >();
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir sal_Bool ConfigurationAccess_UICommand::initializeConfigAccess()
549cdf0e10cSrcweir {
550cdf0e10cSrcweir     Sequence< Any > aArgs( 1 );
551cdf0e10cSrcweir     PropertyValue   aPropValue;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     try
554cdf0e10cSrcweir     {
555cdf0e10cSrcweir         aPropValue.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
556cdf0e10cSrcweir         aPropValue.Value <<= m_aConfigCmdAccess;
557cdf0e10cSrcweir         aArgs[0] <<= aPropValue;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         m_xConfigAccess = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ),UNO_QUERY );
560cdf0e10cSrcweir         if ( m_xConfigAccess.is() )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir             // Add as container listener
563cdf0e10cSrcweir             Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY );
564cdf0e10cSrcweir             if ( xContainer.is() )
565cdf0e10cSrcweir                 xContainer->addContainerListener( this );
566cdf0e10cSrcweir         }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir         aPropValue.Value <<= m_aConfigPopupAccess;
569cdf0e10cSrcweir         aArgs[0] <<= aPropValue;
570cdf0e10cSrcweir         m_xConfigAccessPopups = Reference< XNameAccess >( m_xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,aArgs ),UNO_QUERY );
571cdf0e10cSrcweir         if ( m_xConfigAccessPopups.is() )
572cdf0e10cSrcweir         {
573cdf0e10cSrcweir             // Add as container listener
574cdf0e10cSrcweir             Reference< XContainer > xContainer( m_xConfigAccessPopups, UNO_QUERY );
575cdf0e10cSrcweir             if ( xContainer.is() )
576cdf0e10cSrcweir                 xContainer->addContainerListener( this );
577cdf0e10cSrcweir         }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir         return sal_True;
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir     catch ( WrappedTargetException& )
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir     }
584cdf0e10cSrcweir     catch ( Exception& )
585cdf0e10cSrcweir     {
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     return sal_False;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir // container.XContainerListener
592cdf0e10cSrcweir void SAL_CALL ConfigurationAccess_UICommand::elementInserted( const ContainerEvent& ) throw(RuntimeException)
593cdf0e10cSrcweir {
594cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
595cdf0e10cSrcweir     m_bCacheFilled = sal_False;
596cdf0e10cSrcweir     fillCache();
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir void SAL_CALL ConfigurationAccess_UICommand::elementRemoved( const ContainerEvent& ) throw(RuntimeException)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
602cdf0e10cSrcweir     m_bCacheFilled = sal_False;
603cdf0e10cSrcweir     fillCache();
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir void SAL_CALL ConfigurationAccess_UICommand::elementReplaced( const ContainerEvent& ) throw(RuntimeException)
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
609cdf0e10cSrcweir     m_bCacheFilled = sal_False;
610cdf0e10cSrcweir     fillCache();
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir // lang.XEventListener
614cdf0e10cSrcweir void SAL_CALL ConfigurationAccess_UICommand::disposing( const EventObject& aEvent ) throw(RuntimeException)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir     // SAFE
617cdf0e10cSrcweir     // remove our reference to the config access
618cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
619cdf0e10cSrcweir 
620cdf0e10cSrcweir     Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY );
621cdf0e10cSrcweir     Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY );
622cdf0e10cSrcweir     if ( xIfac1 == xIfac2 )
623cdf0e10cSrcweir         m_xConfigAccess.clear();
624cdf0e10cSrcweir     else
625cdf0e10cSrcweir     {
626cdf0e10cSrcweir         xIfac2 = Reference< XInterface >( m_xConfigAccessPopups, UNO_QUERY );
627cdf0e10cSrcweir         if ( xIfac1 == xIfac2 )
628cdf0e10cSrcweir             m_xConfigAccessPopups.clear();
629cdf0e10cSrcweir     }
630cdf0e10cSrcweir }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir //*****************************************************************************************************************
633cdf0e10cSrcweir //	XInterface, XTypeProvider, XServiceInfo
634cdf0e10cSrcweir //*****************************************************************************************************************
635cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   UICommandDescription				    ,
636cdf0e10cSrcweir                                             ::cppu::OWeakObject						,
637cdf0e10cSrcweir                                             SERVICENAME_UICOMMANDDESCRIPTION	    ,
638cdf0e10cSrcweir 											IMPLEMENTATIONNAME_UICOMMANDDESCRIPTION
639cdf0e10cSrcweir 										)
640cdf0e10cSrcweir 
641cdf0e10cSrcweir DEFINE_INIT_SERVICE                     (   UICommandDescription, {} )
642cdf0e10cSrcweir 
643cdf0e10cSrcweir UICommandDescription::UICommandDescription( const Reference< XMultiServiceFactory >& xServiceManager ) :
644cdf0e10cSrcweir     ThreadHelpBase(),
645cdf0e10cSrcweir     m_aPrivateResourceURL( RTL_CONSTASCII_USTRINGPARAM( PRIVATE_RESOURCE_URL )),
646cdf0e10cSrcweir     m_xServiceManager( xServiceManager )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::UICommandDescription" );
649cdf0e10cSrcweir     Reference< XNameAccess > xEmpty;
650cdf0e10cSrcweir     rtl::OUString aGenericUICommand( ::rtl::OUString::createFromAscii( "GenericCommands" ));
651cdf0e10cSrcweir     m_xGenericUICommands = new ConfigurationAccess_UICommand( aGenericUICommand, xEmpty, xServiceManager );
652cdf0e10cSrcweir 
653cdf0e10cSrcweir     impl_fillElements("ooSetupFactoryCommandConfigRef");
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     // insert generic commands
656cdf0e10cSrcweir     UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aGenericUICommand );
657cdf0e10cSrcweir     if ( pIter != m_aUICommandsHashMap.end() )
658cdf0e10cSrcweir         pIter->second = m_xGenericUICommands;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir UICommandDescription::UICommandDescription( const Reference< XMultiServiceFactory >& xServiceManager,bool ) :
661cdf0e10cSrcweir     ThreadHelpBase(),
662cdf0e10cSrcweir     m_xServiceManager( xServiceManager )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir }
665cdf0e10cSrcweir UICommandDescription::~UICommandDescription()
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
668cdf0e10cSrcweir     m_aModuleToCommandFileMap.clear();
669cdf0e10cSrcweir     m_aUICommandsHashMap.clear();
670cdf0e10cSrcweir     m_xGenericUICommands.clear();
671cdf0e10cSrcweir }
672cdf0e10cSrcweir void UICommandDescription::impl_fillElements(const sal_Char* _pName)
673cdf0e10cSrcweir {
674cdf0e10cSrcweir     m_xModuleManager.set( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ),UNO_QUERY );
675cdf0e10cSrcweir     Reference< XNameAccess > xNameAccess( m_xModuleManager, UNO_QUERY_THROW );
676cdf0e10cSrcweir     Sequence< rtl::OUString > aElementNames = xNameAccess->getElementNames();
677cdf0e10cSrcweir     Sequence< PropertyValue > aSeq;
678cdf0e10cSrcweir     ::rtl::OUString                  aModuleIdentifier;
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
681cdf0e10cSrcweir     {
682cdf0e10cSrcweir         aModuleIdentifier = aElementNames[i];
683cdf0e10cSrcweir         if ( xNameAccess->getByName( aModuleIdentifier ) >>= aSeq )
684cdf0e10cSrcweir         {
685cdf0e10cSrcweir             ::rtl::OUString aCommandStr;
686cdf0e10cSrcweir             for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
687cdf0e10cSrcweir             {
688cdf0e10cSrcweir                 if ( aSeq[y].Name.equalsAscii(_pName) )
689cdf0e10cSrcweir                 {
690cdf0e10cSrcweir                     aSeq[y].Value >>= aCommandStr;
691cdf0e10cSrcweir                     break;
692cdf0e10cSrcweir                 }
693cdf0e10cSrcweir             }
694cdf0e10cSrcweir 
695cdf0e10cSrcweir             // Create first mapping ModuleIdentifier ==> Command File
696cdf0e10cSrcweir             m_aModuleToCommandFileMap.insert( ModuleToCommandFileMap::value_type( aModuleIdentifier, aCommandStr ));
697cdf0e10cSrcweir 
698cdf0e10cSrcweir             // Create second mapping Command File ==> commands instance
699cdf0e10cSrcweir             UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandStr );
700cdf0e10cSrcweir             if ( pIter == m_aUICommandsHashMap.end() )
701cdf0e10cSrcweir                 m_aUICommandsHashMap.insert( UICommandsHashMap::value_type( aCommandStr, Reference< XNameAccess >() ));
702cdf0e10cSrcweir         }
703cdf0e10cSrcweir     } // for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
704cdf0e10cSrcweir }
705cdf0e10cSrcweir Reference< XNameAccess > UICommandDescription::impl_createConfigAccess(const ::rtl::OUString& _sName)
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     return new ConfigurationAccess_UICommand( _sName,m_xGenericUICommands,m_xServiceManager );
708cdf0e10cSrcweir }
709cdf0e10cSrcweir 
710cdf0e10cSrcweir Any SAL_CALL UICommandDescription::getByName( const ::rtl::OUString& aName )
711cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
712cdf0e10cSrcweir {
713cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getByName" );
714cdf0e10cSrcweir     Any a;
715cdf0e10cSrcweir 
716cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     ModuleToCommandFileMap::const_iterator pM2CIter = m_aModuleToCommandFileMap.find( aName );
719cdf0e10cSrcweir     if ( pM2CIter != m_aModuleToCommandFileMap.end() )
720cdf0e10cSrcweir     {
721cdf0e10cSrcweir         ::rtl::OUString aCommandFile( pM2CIter->second );
722cdf0e10cSrcweir         UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandFile );
723cdf0e10cSrcweir         if ( pIter != m_aUICommandsHashMap.end() )
724cdf0e10cSrcweir         {
725cdf0e10cSrcweir             if ( pIter->second.is() )
726cdf0e10cSrcweir                 a <<= pIter->second;
727cdf0e10cSrcweir             else
728cdf0e10cSrcweir             {
729cdf0e10cSrcweir                 Reference< XNameAccess > xUICommands;
730cdf0e10cSrcweir                 ConfigurationAccess_UICommand* pUICommands = new ConfigurationAccess_UICommand( aCommandFile,
731cdf0e10cSrcweir                                                                                                m_xGenericUICommands,
732cdf0e10cSrcweir                                                                                                m_xServiceManager );
733cdf0e10cSrcweir                 xUICommands = Reference< XNameAccess >( static_cast< cppu::OWeakObject* >( pUICommands ),UNO_QUERY );
734cdf0e10cSrcweir                 pIter->second = xUICommands;
735cdf0e10cSrcweir                 a <<= xUICommands;
736cdf0e10cSrcweir             }
737cdf0e10cSrcweir         }
738cdf0e10cSrcweir     }
739cdf0e10cSrcweir     else if ( m_aPrivateResourceURL.getLength() && aName.indexOf( m_aPrivateResourceURL ) == 0 )
740cdf0e10cSrcweir     {
741cdf0e10cSrcweir         // special keys to retrieve information about a set of commands
742cdf0e10cSrcweir         return m_xGenericUICommands->getByName( aName );
743cdf0e10cSrcweir     }
744cdf0e10cSrcweir     else
745cdf0e10cSrcweir     {
746cdf0e10cSrcweir         throw NoSuchElementException();
747cdf0e10cSrcweir     }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir     return a;
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL UICommandDescription::getElementNames()
753cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getElementNames" );
756cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
757cdf0e10cSrcweir 
758cdf0e10cSrcweir     Sequence< rtl::OUString > aSeq( m_aModuleToCommandFileMap.size() );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir     sal_Int32 n = 0;
761cdf0e10cSrcweir     ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.begin();
762cdf0e10cSrcweir     while ( pIter != m_aModuleToCommandFileMap.end() )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         aSeq[n] = pIter->first;
765cdf0e10cSrcweir         ++pIter;
766cdf0e10cSrcweir     }
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     return aSeq;
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir sal_Bool SAL_CALL UICommandDescription::hasByName( const ::rtl::OUString& aName )
772cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
773cdf0e10cSrcweir {
774cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::hasByName" );
775cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     ModuleToCommandFileMap::const_iterator pIter = m_aModuleToCommandFileMap.find( aName );
778cdf0e10cSrcweir     return ( pIter != m_aModuleToCommandFileMap.end() );
779cdf0e10cSrcweir }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir // XElementAccess
782cdf0e10cSrcweir Type SAL_CALL UICommandDescription::getElementType()
783cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
784cdf0e10cSrcweir {
785cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::getElementType" );
786cdf0e10cSrcweir     return( ::getCppuType( (const Reference< XNameAccess >*)NULL ) );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir sal_Bool SAL_CALL UICommandDescription::hasElements()
790cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "UICommandDescription::hasElements" );
793cdf0e10cSrcweir     // generic UI commands are always available!
794cdf0e10cSrcweir     return sal_True;
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir } // namespace framework
798cdf0e10cSrcweir 
799