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