xref: /AOO41X/main/framework/source/uiconfiguration/uiconfigurationmanagerimpl.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 #include <uiconfigurationmanagerimpl.hxx>
31*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32*cdf0e10cSrcweir #include <services.h>
33*cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
34*cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
35*cdf0e10cSrcweir #include <uielement/uielementtypenames.hxx>
36*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
37*cdf0e10cSrcweir #include <framework/toolboxconfiguration.hxx>
38*cdf0e10cSrcweir #include <uiconfiguration/imagemanager.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_STATUSBARCONFIGURATION_HXX_
41*cdf0e10cSrcweir #include <framework/statusbarconfiguration.hxx>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45*cdf0e10cSrcweir //	interface includes
46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
47*cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/ui/ConfigurationEvent.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
56*cdf0e10cSrcweir //	other includes
57*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <vcl/svapp.hxx>
60*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
61*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
62*cdf0e10cSrcweir #include <boost/bind.hpp>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65*cdf0e10cSrcweir //	namespaces
66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir using rtl::OUString;
69*cdf0e10cSrcweir using namespace com::sun::star::uno;
70*cdf0e10cSrcweir using namespace com::sun::star::io;
71*cdf0e10cSrcweir using namespace com::sun::star::embed;
72*cdf0e10cSrcweir using namespace com::sun::star::lang;
73*cdf0e10cSrcweir using namespace com::sun::star::container;
74*cdf0e10cSrcweir using namespace com::sun::star::beans;
75*cdf0e10cSrcweir using namespace ::com::sun::star::ui;
76*cdf0e10cSrcweir using namespace ::cppu;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir namespace framework
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // important: The order and position of the elements must match the constant
83*cdf0e10cSrcweir // definition of "::com::sun::star::ui::UIElementType"
84*cdf0e10cSrcweir static const char* UIELEMENTTYPENAMES[] =
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     "",  // Dummy value for unknown!
87*cdf0e10cSrcweir     UIELEMENTTYPE_MENUBAR_NAME,
88*cdf0e10cSrcweir     UIELEMENTTYPE_POPUPMENU_NAME,
89*cdf0e10cSrcweir     UIELEMENTTYPE_TOOLBAR_NAME,
90*cdf0e10cSrcweir     UIELEMENTTYPE_STATUSBAR_NAME,
91*cdf0e10cSrcweir     UIELEMENTTYPE_FLOATINGWINDOW_NAME,
92*cdf0e10cSrcweir     UIELEMENTTYPE_PROGRESSBAR_NAME
93*cdf0e10cSrcweir };
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir static const char       RESOURCEURL_PREFIX[] = "private:resource/";
96*cdf0e10cSrcweir static const sal_Int32  RESOURCEURL_PREFIX_SIZE = 17;
97*cdf0e10cSrcweir static const char       RESOURCEURL_CUSTOM_ELEMENT[] = "custom_";
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir static sal_Int16 RetrieveTypeFromResourceURL( const rtl::OUString& aResourceURL )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     if (( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) &&
103*cdf0e10cSrcweir         ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
104*cdf0e10cSrcweir     {
105*cdf0e10cSrcweir         rtl::OUString    aTmpStr     = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE );
106*cdf0e10cSrcweir         sal_Int32   nIndex      = aTmpStr.indexOf( '/' );
107*cdf0e10cSrcweir         if (( nIndex > 0 ) &&  ( aTmpStr.getLength() > nIndex ))
108*cdf0e10cSrcweir         {
109*cdf0e10cSrcweir             rtl::OUString aTypeStr( aTmpStr.copy( 0, nIndex ));
110*cdf0e10cSrcweir             for ( int i = 0; i < UIElementType::COUNT; i++ )
111*cdf0e10cSrcweir             {
112*cdf0e10cSrcweir                 if ( aTypeStr.equalsAscii( UIELEMENTTYPENAMES[i] ))
113*cdf0e10cSrcweir                     return sal_Int16( i );
114*cdf0e10cSrcweir             }
115*cdf0e10cSrcweir         }
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     return UIElementType::UNKNOWN;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir static rtl::OUString RetrieveNameFromResourceURL( const rtl::OUString& aResourceURL )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     if (( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) &&
124*cdf0e10cSrcweir         ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' );
127*cdf0e10cSrcweir         if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength()))
128*cdf0e10cSrcweir             return aResourceURL.copy( nIndex+1 );
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     return rtl::OUString();
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     // preload list of element types on demand
137*cdf0e10cSrcweir     impl_preloadUIElementTypeList( LAYER_USERDEFINED, nElementType );
138*cdf0e10cSrcweir     if ( m_bUseDefault )
139*cdf0e10cSrcweir         impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     UIElementDataHashMap& rUserElements = m_aUIElements[LAYER_USERDEFINED][nElementType].aElementsHashMap;
142*cdf0e10cSrcweir     UIElementDataHashMap::const_iterator pUserIter = rUserElements.begin();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     rtl::OUString aCustomUrlPrefix( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_CUSTOM_ELEMENT ));
145*cdf0e10cSrcweir     while ( pUserIter != rUserElements.end() )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         sal_Int32 nIndex = pUserIter->second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
148*cdf0e10cSrcweir         if ( nIndex > RESOURCEURL_PREFIX_SIZE )
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             // Performance: Retrieve user interface name only for custom user interface elements.
151*cdf0e10cSrcweir             // It's only used by them!
152*cdf0e10cSrcweir             UIElementData* pDataSettings = impl_findUIElementData( pUserIter->second.aResourceURL, nElementType );
153*cdf0e10cSrcweir             if ( pDataSettings && ( m_bUseDefault || !pDataSettings->bDefault ))
154*cdf0e10cSrcweir             {
155*cdf0e10cSrcweir                 // Retrieve user interface name from XPropertySet interface
156*cdf0e10cSrcweir                 rtl::OUString aUIName;
157*cdf0e10cSrcweir                 Reference< XPropertySet > xPropSet( pDataSettings->xSettings, UNO_QUERY );
158*cdf0e10cSrcweir                 if ( xPropSet.is() )
159*cdf0e10cSrcweir                 {
160*cdf0e10cSrcweir                     xPropSet->getPropertyValue( m_aPropUIName ) >>= aUIName;
161*cdf0e10cSrcweir                 }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir                 UIElementInfo aInfo( pUserIter->second.aResourceURL, aUIName );
164*cdf0e10cSrcweir                 aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pUserIter->second.aResourceURL, aInfo ));
165*cdf0e10cSrcweir             }
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir         else
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             // The user interface name for standard user interface elements is stored in the WindowState.xcu file
170*cdf0e10cSrcweir             UIElementInfo aInfo( pUserIter->second.aResourceURL, rtl::OUString() );
171*cdf0e10cSrcweir             aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pUserIter->second.aResourceURL, aInfo ));
172*cdf0e10cSrcweir         }
173*cdf0e10cSrcweir         ++pUserIter;
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     if ( m_bUseDefault )
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         UIElementDataHashMap& rDefaultElements = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap;
179*cdf0e10cSrcweir         UIElementDataHashMap::const_iterator pDefIter = rDefaultElements.begin();
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         while ( pDefIter != rDefaultElements.end() )
182*cdf0e10cSrcweir         {
183*cdf0e10cSrcweir             UIElementInfoHashMap::const_iterator pIterInfo = aUIElementInfoCollection.find( pDefIter->second.aResourceURL );
184*cdf0e10cSrcweir             if ( pIterInfo == aUIElementInfoCollection.end() )
185*cdf0e10cSrcweir             {
186*cdf0e10cSrcweir                 sal_Int32 nIndex = pDefIter->second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
187*cdf0e10cSrcweir                 if ( nIndex > RESOURCEURL_PREFIX_SIZE )
188*cdf0e10cSrcweir                 {
189*cdf0e10cSrcweir                     // Performance: Retrieve user interface name only for custom user interface elements.
190*cdf0e10cSrcweir                     // It's only used by them!
191*cdf0e10cSrcweir                     UIElementData* pDataSettings = impl_findUIElementData( pDefIter->second.aResourceURL, nElementType );
192*cdf0e10cSrcweir                     if ( pDataSettings )
193*cdf0e10cSrcweir                     {
194*cdf0e10cSrcweir                         // Retrieve user interface name from XPropertySet interface
195*cdf0e10cSrcweir                         rtl::OUString aUIName;
196*cdf0e10cSrcweir                         Reference< XPropertySet > xPropSet( pDataSettings->xSettings, UNO_QUERY );
197*cdf0e10cSrcweir                         if ( xPropSet.is() )
198*cdf0e10cSrcweir                         {
199*cdf0e10cSrcweir                             xPropSet->getPropertyValue( m_aPropUIName ) >>= aUIName;
200*cdf0e10cSrcweir                         }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir                         UIElementInfo aInfo( pDefIter->second.aResourceURL, aUIName );
203*cdf0e10cSrcweir                         aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pDefIter->second.aResourceURL, aInfo ));
204*cdf0e10cSrcweir                     }
205*cdf0e10cSrcweir                 }
206*cdf0e10cSrcweir                 else
207*cdf0e10cSrcweir                 {
208*cdf0e10cSrcweir                     // The user interface name for standard user interface elements is stored in the WindowState.xcu file
209*cdf0e10cSrcweir                     UIElementInfo aInfo( pDefIter->second.aResourceURL, rtl::OUString() );
210*cdf0e10cSrcweir                     aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pDefIter->second.aResourceURL, aInfo ));
211*cdf0e10cSrcweir                 }
212*cdf0e10cSrcweir             }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir             ++pDefIter;
215*cdf0e10cSrcweir         } // while ( pDefIter != rDefaultElements.end() )
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_preloadUIElementTypeList( Layer eLayer, sal_Int16 nElementType )
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir     UIElementType& rElementTypeData = m_aUIElements[eLayer][nElementType];
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir     if ( !rElementTypeData.bLoaded )
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir         Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage;
226*cdf0e10cSrcweir         if ( xElementTypeStorage.is() )
227*cdf0e10cSrcweir         {
228*cdf0e10cSrcweir             rtl::OUStringBuffer aBuf( RESOURCEURL_PREFIX_SIZE );
229*cdf0e10cSrcweir             aBuf.appendAscii( RESOURCEURL_PREFIX );
230*cdf0e10cSrcweir             aBuf.appendAscii( UIELEMENTTYPENAMES[ nElementType ] );
231*cdf0e10cSrcweir             aBuf.appendAscii( "/" );
232*cdf0e10cSrcweir             rtl::OUString aResURLPrefix( aBuf.makeStringAndClear() );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir             UIElementDataHashMap& rHashMap = rElementTypeData.aElementsHashMap;
235*cdf0e10cSrcweir             Reference< XNameAccess > xNameAccess( xElementTypeStorage, UNO_QUERY );
236*cdf0e10cSrcweir             Sequence< rtl::OUString > aUIElementNames = xNameAccess->getElementNames();
237*cdf0e10cSrcweir             for ( sal_Int32 n = 0; n < aUIElementNames.getLength(); n++ )
238*cdf0e10cSrcweir             {
239*cdf0e10cSrcweir                 UIElementData aUIElementData;
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir                 // Resource name must be without ".xml"
242*cdf0e10cSrcweir                 sal_Int32 nIndex = aUIElementNames[n].lastIndexOf( '.' );
243*cdf0e10cSrcweir                 if (( nIndex > 0 ) && ( nIndex < aUIElementNames[n].getLength() ))
244*cdf0e10cSrcweir                 {
245*cdf0e10cSrcweir                     rtl::OUString aExtension( aUIElementNames[n].copy( nIndex+1 ));
246*cdf0e10cSrcweir                     rtl::OUString aUIElementName( aUIElementNames[n].copy( 0, nIndex ));
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir                     if (( aUIElementName.getLength() > 0 ) &&
249*cdf0e10cSrcweir                         ( aExtension.equalsIgnoreAsciiCaseAsciiL( "xml", 3 )))
250*cdf0e10cSrcweir                     {
251*cdf0e10cSrcweir                         aUIElementData.aResourceURL = aResURLPrefix + aUIElementName;
252*cdf0e10cSrcweir                         aUIElementData.aName        = aUIElementNames[n];
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir                         if ( eLayer == LAYER_USERDEFINED )
255*cdf0e10cSrcweir                         {
256*cdf0e10cSrcweir                             aUIElementData.bModified    = false;
257*cdf0e10cSrcweir                             aUIElementData.bDefault     = false;
258*cdf0e10cSrcweir                             aUIElementData.bDefaultNode = false;
259*cdf0e10cSrcweir                         }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir                         // Create hash_map entries for all user interface elements inside the storage. We don't load the
262*cdf0e10cSrcweir                         // settings to speed up the process.
263*cdf0e10cSrcweir                         rHashMap.insert( UIElementDataHashMap::value_type( aUIElementData.aResourceURL, aUIElementData ));
264*cdf0e10cSrcweir                     }
265*cdf0e10cSrcweir                 }
266*cdf0e10cSrcweir             }
267*cdf0e10cSrcweir         }
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     rElementTypeData.bLoaded = true;
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_requestUIElementData( sal_Int16 nElementType, Layer eLayer, UIElementData& aUIElementData )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     UIElementType& rElementTypeData = m_aUIElements[eLayer][nElementType];
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage;
278*cdf0e10cSrcweir     if ( xElementTypeStorage.is() && aUIElementData.aName.getLength() )
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         try
281*cdf0e10cSrcweir         {
282*cdf0e10cSrcweir             Reference< XStream > xStream = xElementTypeStorage->openStreamElement( aUIElementData.aName, ElementModes::READ );
283*cdf0e10cSrcweir             Reference< XInputStream > xInputStream = xStream->getInputStream();
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir             if ( xInputStream.is() )
286*cdf0e10cSrcweir             {
287*cdf0e10cSrcweir                 switch ( nElementType )
288*cdf0e10cSrcweir                 {
289*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::UNKNOWN:
290*cdf0e10cSrcweir                     break;
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::MENUBAR:
293*cdf0e10cSrcweir                     {
294*cdf0e10cSrcweir                         try
295*cdf0e10cSrcweir                         {
296*cdf0e10cSrcweir                             MenuConfiguration aMenuCfg( m_xServiceManager );
297*cdf0e10cSrcweir                             Reference< XIndexAccess > xContainer( aMenuCfg.CreateMenuBarConfigurationFromXML( xInputStream ));
298*cdf0e10cSrcweir                             RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xContainer );
299*cdf0e10cSrcweir                             if ( pRootItemContainer )
300*cdf0e10cSrcweir                                 aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY );
301*cdf0e10cSrcweir                             else
302*cdf0e10cSrcweir                                 aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( xContainer, sal_True ) ), UNO_QUERY );
303*cdf0e10cSrcweir                             return;
304*cdf0e10cSrcweir                         }
305*cdf0e10cSrcweir                         catch ( ::com::sun::star::lang::WrappedTargetException& )
306*cdf0e10cSrcweir                         {
307*cdf0e10cSrcweir                         }
308*cdf0e10cSrcweir                     }
309*cdf0e10cSrcweir                     break;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::POPUPMENU:
312*cdf0e10cSrcweir                     {
313*cdf0e10cSrcweir                         break;
314*cdf0e10cSrcweir                     }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::TOOLBAR:
317*cdf0e10cSrcweir                     {
318*cdf0e10cSrcweir                         try
319*cdf0e10cSrcweir                         {
320*cdf0e10cSrcweir                             Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY );
321*cdf0e10cSrcweir                             ToolBoxConfiguration::LoadToolBox( m_xServiceManager, xInputStream, xIndexContainer );
322*cdf0e10cSrcweir                             RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer );
323*cdf0e10cSrcweir                             aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY );
324*cdf0e10cSrcweir                             return;
325*cdf0e10cSrcweir                         }
326*cdf0e10cSrcweir                         catch ( ::com::sun::star::lang::WrappedTargetException& )
327*cdf0e10cSrcweir                         {
328*cdf0e10cSrcweir                         }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir                         break;
331*cdf0e10cSrcweir                     }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::STATUSBAR:
334*cdf0e10cSrcweir                     {
335*cdf0e10cSrcweir                         try
336*cdf0e10cSrcweir                         {
337*cdf0e10cSrcweir                             Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY );
338*cdf0e10cSrcweir                             StatusBarConfiguration::LoadStatusBar( m_xServiceManager, xInputStream, xIndexContainer );
339*cdf0e10cSrcweir                             RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer );
340*cdf0e10cSrcweir                             aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY );
341*cdf0e10cSrcweir                             return;
342*cdf0e10cSrcweir                         }
343*cdf0e10cSrcweir                         catch ( ::com::sun::star::lang::WrappedTargetException& )
344*cdf0e10cSrcweir                         {
345*cdf0e10cSrcweir                         }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir                         break;
348*cdf0e10cSrcweir                     }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir                     case ::com::sun::star::ui::UIElementType::FLOATINGWINDOW:
351*cdf0e10cSrcweir                     {
352*cdf0e10cSrcweir                         break;
353*cdf0e10cSrcweir                     }
354*cdf0e10cSrcweir                 }
355*cdf0e10cSrcweir             }
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir         catch ( ::com::sun::star::embed::InvalidStorageException& )
358*cdf0e10cSrcweir         {
359*cdf0e10cSrcweir         }
360*cdf0e10cSrcweir 		catch (	::com::sun::star::lang::IllegalArgumentException& )
361*cdf0e10cSrcweir         {
362*cdf0e10cSrcweir         }
363*cdf0e10cSrcweir         catch ( ::com::sun::star::io::IOException& )
364*cdf0e10cSrcweir         {
365*cdf0e10cSrcweir         }
366*cdf0e10cSrcweir         catch ( ::com::sun::star::embed::StorageWrappedTargetException& )
367*cdf0e10cSrcweir         {
368*cdf0e10cSrcweir         }
369*cdf0e10cSrcweir     }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir     // At least we provide an empty settings container!
372*cdf0e10cSrcweir     aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer() ), UNO_QUERY );
373*cdf0e10cSrcweir }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir UIConfigurationManagerImpl::UIElementData*  UIConfigurationManagerImpl::impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad )
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir     // preload list of element types on demand
378*cdf0e10cSrcweir     impl_preloadUIElementTypeList( LAYER_USERDEFINED, nElementType );
379*cdf0e10cSrcweir     if ( m_bUseDefault )
380*cdf0e10cSrcweir         impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     // first try to look into our user-defined vector/hash_map combination
383*cdf0e10cSrcweir     UIElementDataHashMap& rUserHashMap = m_aUIElements[LAYER_USERDEFINED][nElementType].aElementsHashMap;
384*cdf0e10cSrcweir     UIElementDataHashMap::iterator pIter = rUserHashMap.find( aResourceURL );
385*cdf0e10cSrcweir     if ( pIter != rUserHashMap.end() )
386*cdf0e10cSrcweir     {
387*cdf0e10cSrcweir         // Default data settings data must be retrieved from the default layer!
388*cdf0e10cSrcweir         if ( !pIter->second.bDefault )
389*cdf0e10cSrcweir         {
390*cdf0e10cSrcweir             if ( !pIter->second.xSettings.is() && bLoad )
391*cdf0e10cSrcweir                 impl_requestUIElementData( nElementType, LAYER_USERDEFINED, pIter->second );
392*cdf0e10cSrcweir             return &(pIter->second);
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     if ( m_bUseDefault )
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir         // Not successfull, we have to look into our default vector/hash_map combination
399*cdf0e10cSrcweir         UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap;
400*cdf0e10cSrcweir         pIter = rDefaultHashMap.find( aResourceURL );
401*cdf0e10cSrcweir         if ( pIter != rDefaultHashMap.end() )
402*cdf0e10cSrcweir         {
403*cdf0e10cSrcweir             if ( !pIter->second.xSettings.is() && bLoad )
404*cdf0e10cSrcweir                 impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second );
405*cdf0e10cSrcweir             return &(pIter->second);
406*cdf0e10cSrcweir         } // if ( pIter != rDefaultHashMap.end() )
407*cdf0e10cSrcweir     }
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir     // Nothing has been found!
410*cdf0e10cSrcweir     return NULL;
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_storeElementTypeData( Reference< XStorage > xStorage, UIElementType& rElementType, bool bResetModifyState )
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     UIElementDataHashMap& rHashMap          = rElementType.aElementsHashMap;
416*cdf0e10cSrcweir     UIElementDataHashMap::iterator pIter    = rHashMap.begin();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     while ( pIter != rHashMap.end() )
419*cdf0e10cSrcweir     {
420*cdf0e10cSrcweir         UIElementData& rElement = pIter->second;
421*cdf0e10cSrcweir         if ( rElement.bModified )
422*cdf0e10cSrcweir         {
423*cdf0e10cSrcweir             if ( rElement.bDefault )
424*cdf0e10cSrcweir             {
425*cdf0e10cSrcweir                 xStorage->removeElement( rElement.aName );
426*cdf0e10cSrcweir                 rElement.bModified = sal_False; // mark as not modified
427*cdf0e10cSrcweir             }
428*cdf0e10cSrcweir             else
429*cdf0e10cSrcweir             {
430*cdf0e10cSrcweir                 Reference< XStream > xStream( xStorage->openStreamElement( rElement.aName, ElementModes::WRITE|ElementModes::TRUNCATE ), UNO_QUERY );
431*cdf0e10cSrcweir                 Reference< XOutputStream > xOutputStream( xStream->getOutputStream() );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir                 if ( xOutputStream.is() )
434*cdf0e10cSrcweir                 {
435*cdf0e10cSrcweir                     switch( rElementType.nElementType )
436*cdf0e10cSrcweir                     {
437*cdf0e10cSrcweir                         case ::com::sun::star::ui::UIElementType::MENUBAR:
438*cdf0e10cSrcweir                         {
439*cdf0e10cSrcweir                             try
440*cdf0e10cSrcweir                             {
441*cdf0e10cSrcweir                                 MenuConfiguration aMenuCfg( m_xServiceManager );
442*cdf0e10cSrcweir                                 aMenuCfg.StoreMenuBarConfigurationToXML( rElement.xSettings, xOutputStream );
443*cdf0e10cSrcweir                             }
444*cdf0e10cSrcweir                             catch ( ::com::sun::star::lang::WrappedTargetException& )
445*cdf0e10cSrcweir                             {
446*cdf0e10cSrcweir                             }
447*cdf0e10cSrcweir                         }
448*cdf0e10cSrcweir                         break;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir                         case ::com::sun::star::ui::UIElementType::TOOLBAR:
451*cdf0e10cSrcweir                         {
452*cdf0e10cSrcweir                             try
453*cdf0e10cSrcweir                             {
454*cdf0e10cSrcweir                                 ToolBoxConfiguration::StoreToolBox( m_xServiceManager, xOutputStream, rElement.xSettings );
455*cdf0e10cSrcweir                             }
456*cdf0e10cSrcweir                             catch ( ::com::sun::star::lang::WrappedTargetException& )
457*cdf0e10cSrcweir                             {
458*cdf0e10cSrcweir                             }
459*cdf0e10cSrcweir                         }
460*cdf0e10cSrcweir                         break;
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir                         case ::com::sun::star::ui::UIElementType::STATUSBAR:
463*cdf0e10cSrcweir                         {
464*cdf0e10cSrcweir                             try
465*cdf0e10cSrcweir                             {
466*cdf0e10cSrcweir                                 StatusBarConfiguration::StoreStatusBar( m_xServiceManager, xOutputStream, rElement.xSettings );
467*cdf0e10cSrcweir                             }
468*cdf0e10cSrcweir                             catch ( ::com::sun::star::lang::WrappedTargetException& )
469*cdf0e10cSrcweir                             {
470*cdf0e10cSrcweir                             }
471*cdf0e10cSrcweir                         }
472*cdf0e10cSrcweir                         break;
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir                         default:
475*cdf0e10cSrcweir                         break;
476*cdf0e10cSrcweir                     }
477*cdf0e10cSrcweir                 }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir                 // mark as not modified if we store to our own storage
480*cdf0e10cSrcweir                 if ( bResetModifyState )
481*cdf0e10cSrcweir                     rElement.bModified = sal_False;
482*cdf0e10cSrcweir             }
483*cdf0e10cSrcweir         }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir         ++pIter;
486*cdf0e10cSrcweir     }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir     // commit element type storage
489*cdf0e10cSrcweir     Reference< XTransactedObject > xTransactedObject( xStorage, UNO_QUERY );
490*cdf0e10cSrcweir 	if ( xTransactedObject.is() )
491*cdf0e10cSrcweir     	xTransactedObject->commit();
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     // mark UIElementType as not modified if we store to our own storage
494*cdf0e10cSrcweir     if ( bResetModifyState )
495*cdf0e10cSrcweir         rElementType.bModified = sal_False;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir // This is only allowed to be called on the LAYER_USER_DEFINED!
499*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_resetElementTypeData(
500*cdf0e10cSrcweir     UIElementType& rUserElementType,
501*cdf0e10cSrcweir     UIElementType& rDefaultElementType,
502*cdf0e10cSrcweir     ConfigEventNotifyContainer& rRemoveNotifyContainer,
503*cdf0e10cSrcweir     ConfigEventNotifyContainer& rReplaceNotifyContainer )
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir     UIElementDataHashMap& rHashMap          = rUserElementType.aElementsHashMap;
506*cdf0e10cSrcweir     UIElementDataHashMap::iterator pIter    = rHashMap.begin();
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir     Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
509*cdf0e10cSrcweir     Reference< XNameAccess > xDefaultNameAccess( rDefaultElementType.xStorage, UNO_QUERY );
510*cdf0e10cSrcweir     sal_Int16 nType = rUserElementType.nElementType;
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir     // Make copies of the event structures to be thread-safe. We have to unlock our mutex before calling
513*cdf0e10cSrcweir     // our listeners!
514*cdf0e10cSrcweir     while ( pIter != rHashMap.end() )
515*cdf0e10cSrcweir     {
516*cdf0e10cSrcweir         UIElementData& rElement = pIter->second;
517*cdf0e10cSrcweir         if ( !rElement.bDefault )
518*cdf0e10cSrcweir         {
519*cdf0e10cSrcweir             if ( m_bUseDefault && xDefaultNameAccess->hasByName( rElement.aName ))
520*cdf0e10cSrcweir             {
521*cdf0e10cSrcweir                 // Replace settings with data from default layer
522*cdf0e10cSrcweir                 Reference< XIndexAccess > xOldSettings( rElement.xSettings );
523*cdf0e10cSrcweir                 impl_requestUIElementData( nType, LAYER_DEFAULT, rElement );
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir                 ConfigurationEvent aReplaceEvent;
526*cdf0e10cSrcweir                 aReplaceEvent.ResourceURL = rElement.aResourceURL;
527*cdf0e10cSrcweir                 aReplaceEvent.Accessor <<= xThis;
528*cdf0e10cSrcweir                 aReplaceEvent.Source = m_xOwner;
529*cdf0e10cSrcweir                 aReplaceEvent.ReplacedElement <<= xOldSettings;
530*cdf0e10cSrcweir                 aReplaceEvent.Element <<= rElement.xSettings;
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir                 rReplaceNotifyContainer.push_back( aReplaceEvent );
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir                 // Mark element as default and not modified. That means "not active"
535*cdf0e10cSrcweir                 // in the user layer anymore.
536*cdf0e10cSrcweir                 rElement.bModified = false;
537*cdf0e10cSrcweir                 rElement.bDefault  = true;
538*cdf0e10cSrcweir             }
539*cdf0e10cSrcweir             else
540*cdf0e10cSrcweir             {
541*cdf0e10cSrcweir                 // Remove user-defined settings from user layer
542*cdf0e10cSrcweir                 ConfigurationEvent aEvent;
543*cdf0e10cSrcweir                 aEvent.ResourceURL = rElement.aResourceURL;
544*cdf0e10cSrcweir                 aEvent.Accessor <<= xThis;
545*cdf0e10cSrcweir                 aEvent.Source = m_xOwner;
546*cdf0e10cSrcweir                 aEvent.Element <<= rElement.xSettings;
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir                 rRemoveNotifyContainer.push_back( aEvent );
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir                 // Mark element as default and not modified. That means "not active"
551*cdf0e10cSrcweir                 // in the user layer anymore.
552*cdf0e10cSrcweir                 rElement.bModified = false;
553*cdf0e10cSrcweir                 rElement.bDefault  = true;
554*cdf0e10cSrcweir             }
555*cdf0e10cSrcweir         } // if ( !rElement.bDefault )
556*cdf0e10cSrcweir         else
557*cdf0e10cSrcweir             rElement.bModified = false;
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir         ++pIter;
560*cdf0e10cSrcweir     }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     // Remove all settings from our user interface elements
563*cdf0e10cSrcweir     rHashMap.clear();
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_reloadElementTypeData(
567*cdf0e10cSrcweir     UIElementType&              rUserElementType,
568*cdf0e10cSrcweir     UIElementType&              rDefaultElementType,
569*cdf0e10cSrcweir     ConfigEventNotifyContainer& rRemoveNotifyContainer,
570*cdf0e10cSrcweir     ConfigEventNotifyContainer& rReplaceNotifyContainer )
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir     UIElementDataHashMap& rHashMap          = rUserElementType.aElementsHashMap;
573*cdf0e10cSrcweir     UIElementDataHashMap::iterator pIter    = rHashMap.begin();
574*cdf0e10cSrcweir     Reference< XStorage > xUserStorage( rUserElementType.xStorage );
575*cdf0e10cSrcweir     Reference< XStorage > xDefaultStorage( rDefaultElementType.xStorage );
576*cdf0e10cSrcweir     Reference< XNameAccess > xUserNameAccess( rUserElementType.xStorage, UNO_QUERY );
577*cdf0e10cSrcweir     Reference< XNameAccess > xDefaultNameAccess( rDefaultElementType.xStorage, UNO_QUERY );
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
580*cdf0e10cSrcweir     sal_Int16 nType = rUserElementType.nElementType;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir     while ( pIter != rHashMap.end() )
583*cdf0e10cSrcweir     {
584*cdf0e10cSrcweir         UIElementData& rElement = pIter->second;
585*cdf0e10cSrcweir         if ( rElement.bModified )
586*cdf0e10cSrcweir         {
587*cdf0e10cSrcweir             if ( xUserNameAccess->hasByName( rElement.aName ))
588*cdf0e10cSrcweir             {
589*cdf0e10cSrcweir                 // Replace settings with data from user layer
590*cdf0e10cSrcweir                 Reference< XIndexAccess > xOldSettings( rElement.xSettings );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir                 impl_requestUIElementData( nType, LAYER_USERDEFINED, rElement );
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir                 ConfigurationEvent aReplaceEvent;
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir                 aReplaceEvent.ResourceURL = rElement.aResourceURL;
597*cdf0e10cSrcweir                 aReplaceEvent.Accessor <<= xThis;
598*cdf0e10cSrcweir                 aReplaceEvent.Source = m_xOwner;
599*cdf0e10cSrcweir                 aReplaceEvent.ReplacedElement <<= xOldSettings;
600*cdf0e10cSrcweir                 aReplaceEvent.Element <<= rElement.xSettings;
601*cdf0e10cSrcweir                 rReplaceNotifyContainer.push_back( aReplaceEvent );
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir                 rElement.bModified = false;
604*cdf0e10cSrcweir             }
605*cdf0e10cSrcweir             else if ( m_bUseDefault && xDefaultNameAccess->hasByName( rElement.aName ))
606*cdf0e10cSrcweir             {
607*cdf0e10cSrcweir                 // Replace settings with data from default layer
608*cdf0e10cSrcweir                 Reference< XIndexAccess > xOldSettings( rElement.xSettings );
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir                 impl_requestUIElementData( nType, LAYER_DEFAULT, rElement );
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir                 ConfigurationEvent aReplaceEvent;
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir                 aReplaceEvent.ResourceURL = rElement.aResourceURL;
615*cdf0e10cSrcweir                 aReplaceEvent.Accessor <<= xThis;
616*cdf0e10cSrcweir                 aReplaceEvent.Source = m_xOwner;
617*cdf0e10cSrcweir                 aReplaceEvent.ReplacedElement <<= xOldSettings;
618*cdf0e10cSrcweir                 aReplaceEvent.Element <<= rElement.xSettings;
619*cdf0e10cSrcweir                 rReplaceNotifyContainer.push_back( aReplaceEvent );
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir                 // Mark element as default and not modified. That means "not active"
622*cdf0e10cSrcweir                 // in the user layer anymore.
623*cdf0e10cSrcweir                 rElement.bModified = false;
624*cdf0e10cSrcweir                 rElement.bDefault  = true;
625*cdf0e10cSrcweir             }
626*cdf0e10cSrcweir             else
627*cdf0e10cSrcweir             {
628*cdf0e10cSrcweir                 // Element settings are not in any storage => remove
629*cdf0e10cSrcweir                 ConfigurationEvent aRemoveEvent;
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir                 aRemoveEvent.ResourceURL = rElement.aResourceURL;
632*cdf0e10cSrcweir                 aRemoveEvent.Accessor <<= xThis;
633*cdf0e10cSrcweir                 aRemoveEvent.Source = m_xOwner;
634*cdf0e10cSrcweir                 aRemoveEvent.Element <<= rElement.xSettings;
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir                 rRemoveNotifyContainer.push_back( aRemoveEvent );
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir                 // Mark element as default and not modified. That means "not active"
639*cdf0e10cSrcweir                 // in the user layer anymore.
640*cdf0e10cSrcweir                 rElement.bModified = false;
641*cdf0e10cSrcweir                 rElement.bDefault  = true;
642*cdf0e10cSrcweir             }
643*cdf0e10cSrcweir         }
644*cdf0e10cSrcweir         ++pIter;
645*cdf0e10cSrcweir     }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     rUserElementType.bModified = sal_False;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir void UIConfigurationManagerImpl::impl_Initialize()
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir     // Initialize the top-level structures with the storage data
653*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() )
654*cdf0e10cSrcweir     {
655*cdf0e10cSrcweir         // Try to access our module sub folder
656*cdf0e10cSrcweir         for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT;
657*cdf0e10cSrcweir               i++ )
658*cdf0e10cSrcweir         {
659*cdf0e10cSrcweir             Reference< XStorage > xElementTypeStorage;
660*cdf0e10cSrcweir             try
661*cdf0e10cSrcweir             {
662*cdf0e10cSrcweir                 if ( m_pStorageHandler[i] )
663*cdf0e10cSrcweir                     xElementTypeStorage = m_pStorageHandler[i]->getWorkingStorageUser();
664*cdf0e10cSrcweir             }
665*cdf0e10cSrcweir             catch ( com::sun::star::container::NoSuchElementException& )
666*cdf0e10cSrcweir             {
667*cdf0e10cSrcweir             }
668*cdf0e10cSrcweir             catch ( ::com::sun::star::embed::InvalidStorageException& )
669*cdf0e10cSrcweir             {
670*cdf0e10cSrcweir             }
671*cdf0e10cSrcweir             catch ( ::com::sun::star::lang::IllegalArgumentException& )
672*cdf0e10cSrcweir             {
673*cdf0e10cSrcweir             }
674*cdf0e10cSrcweir             catch ( ::com::sun::star::io::IOException& )
675*cdf0e10cSrcweir             {
676*cdf0e10cSrcweir             }
677*cdf0e10cSrcweir             catch ( ::com::sun::star::embed::StorageWrappedTargetException& )
678*cdf0e10cSrcweir             {
679*cdf0e10cSrcweir             }
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir             m_aUIElements[LAYER_USERDEFINED][i].nElementType = i;
682*cdf0e10cSrcweir             m_aUIElements[LAYER_USERDEFINED][i].bModified = false;
683*cdf0e10cSrcweir             m_aUIElements[LAYER_USERDEFINED][i].xStorage = xElementTypeStorage;
684*cdf0e10cSrcweir             m_aUIElements[LAYER_USERDEFINED][i].bDefaultLayer = false;
685*cdf0e10cSrcweir         }
686*cdf0e10cSrcweir     } // if ( m_xUserConfigStorage.is() )
687*cdf0e10cSrcweir     else if ( !m_bUseDefault )
688*cdf0e10cSrcweir     {
689*cdf0e10cSrcweir         // We have no storage, just initialize ui element types with empty storage!
690*cdf0e10cSrcweir         for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
691*cdf0e10cSrcweir             m_aUIElements[LAYER_USERDEFINED][i].xStorage.clear();
692*cdf0e10cSrcweir     }
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir     if ( m_bUseDefault && m_xUserConfigStorage.is() )
695*cdf0e10cSrcweir     {
696*cdf0e10cSrcweir         Reference< XNameAccess > xNameAccess( m_xDefaultConfigStorage, UNO_QUERY_THROW );
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir         // Try to access our module sub folder
699*cdf0e10cSrcweir         for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT;
700*cdf0e10cSrcweir               i++ )
701*cdf0e10cSrcweir         {
702*cdf0e10cSrcweir             Reference< XStorage > xElementTypeStorage;
703*cdf0e10cSrcweir             try
704*cdf0e10cSrcweir             {
705*cdf0e10cSrcweir                 xNameAccess->getByName( rtl::OUString::createFromAscii( UIELEMENTTYPENAMES[i] )) >>= xElementTypeStorage;
706*cdf0e10cSrcweir             }
707*cdf0e10cSrcweir             catch ( com::sun::star::container::NoSuchElementException& )
708*cdf0e10cSrcweir             {
709*cdf0e10cSrcweir             }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir             m_aUIElements[LAYER_DEFAULT][i].nElementType = i;
712*cdf0e10cSrcweir             m_aUIElements[LAYER_DEFAULT][i].bModified = false;
713*cdf0e10cSrcweir             m_aUIElements[LAYER_DEFAULT][i].xStorage = xElementTypeStorage;
714*cdf0e10cSrcweir             m_aUIElements[LAYER_DEFAULT][i].bDefaultLayer = true;
715*cdf0e10cSrcweir         }
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir }
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir UIConfigurationManagerImpl::UIConfigurationManagerImpl( const Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
720*cdf0e10cSrcweir                                                        ,const Reference< XInterface >& _xOwner
721*cdf0e10cSrcweir                                                        , bool _bUseDefault) :
722*cdf0e10cSrcweir     ThreadHelpBase( &Application::GetSolarMutex() )
723*cdf0e10cSrcweir     , m_xOwner( _xOwner )
724*cdf0e10cSrcweir     , m_bUseDefault(_bUseDefault)
725*cdf0e10cSrcweir     , m_bReadOnly( true )
726*cdf0e10cSrcweir     , m_bInitialized( false )
727*cdf0e10cSrcweir     , m_bModified( false )
728*cdf0e10cSrcweir     , m_bConfigRead( false )
729*cdf0e10cSrcweir     , m_bDisposed( false )
730*cdf0e10cSrcweir     , m_aXMLPostfix( RTL_CONSTASCII_USTRINGPARAM( ".xml" ))
731*cdf0e10cSrcweir     , m_aPropUIName( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))
732*cdf0e10cSrcweir     , m_aPropResourceURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))
733*cdf0e10cSrcweir     , m_xServiceManager( xServiceManager )
734*cdf0e10cSrcweir     , m_aListenerContainer( m_aLock.getShareableOslMutex() )
735*cdf0e10cSrcweir {
736*cdf0e10cSrcweir     for ( int i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
737*cdf0e10cSrcweir         m_pStorageHandler[i] = 0;
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir     // Make sure we have a default initialized entry for every layer and user interface element type!
740*cdf0e10cSrcweir     // The following code depends on this!
741*cdf0e10cSrcweir     m_aUIElements[LAYER_DEFAULT].resize( ::com::sun::star::ui::UIElementType::COUNT );
742*cdf0e10cSrcweir     m_aUIElements[LAYER_USERDEFINED].resize( ::com::sun::star::ui::UIElementType::COUNT );
743*cdf0e10cSrcweir }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir UIConfigurationManagerImpl::~UIConfigurationManagerImpl()
746*cdf0e10cSrcweir {
747*cdf0e10cSrcweir     for ( int i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
748*cdf0e10cSrcweir         delete m_pStorageHandler[i];
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir // XComponent
752*cdf0e10cSrcweir void UIConfigurationManagerImpl::dispose() throw (::com::sun::star::uno::RuntimeException)
753*cdf0e10cSrcweir {
754*cdf0e10cSrcweir     css::lang::EventObject aEvent( m_xOwner );
755*cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir 	{
758*cdf0e10cSrcweir 	    ResetableGuard aGuard( m_aLock );
759*cdf0e10cSrcweir         try
760*cdf0e10cSrcweir         {
761*cdf0e10cSrcweir             if ( m_xModuleImageManager.is() )
762*cdf0e10cSrcweir                 m_xModuleImageManager->dispose();
763*cdf0e10cSrcweir         }
764*cdf0e10cSrcweir         catch ( Exception& )
765*cdf0e10cSrcweir         {
766*cdf0e10cSrcweir         }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir         m_xModuleImageManager.clear();
769*cdf0e10cSrcweir         m_aUIElements[LAYER_USERDEFINED].clear();
770*cdf0e10cSrcweir         m_aUIElements[LAYER_DEFAULT].clear();
771*cdf0e10cSrcweir         m_xDefaultConfigStorage.clear();
772*cdf0e10cSrcweir         m_xUserConfigStorage.clear();
773*cdf0e10cSrcweir         m_xUserRootCommit.clear();
774*cdf0e10cSrcweir         m_bConfigRead = false;
775*cdf0e10cSrcweir         m_bModified = false;
776*cdf0e10cSrcweir         m_bDisposed = true;
777*cdf0e10cSrcweir     }
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir void UIConfigurationManagerImpl::addEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
781*cdf0e10cSrcweir {
782*cdf0e10cSrcweir     {
783*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 	    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
786*cdf0e10cSrcweir         if ( m_bDisposed )
787*cdf0e10cSrcweir             throw DisposedException();
788*cdf0e10cSrcweir     }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
791*cdf0e10cSrcweir }
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir void UIConfigurationManagerImpl::removeEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
796*cdf0e10cSrcweir     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
797*cdf0e10cSrcweir }
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir // XInitialization
800*cdf0e10cSrcweir void UIConfigurationManagerImpl::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
801*cdf0e10cSrcweir {
802*cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir     if ( !m_bInitialized )
805*cdf0e10cSrcweir     {
806*cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap lArgs(aArguments);
807*cdf0e10cSrcweir         m_aModuleIdentifier = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleIdentifier"), ::rtl::OUString());
808*cdf0e10cSrcweir         m_aModuleShortName  = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleShortName"), ::rtl::OUString());
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir         for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
811*cdf0e10cSrcweir         {
812*cdf0e10cSrcweir             rtl::OUString aResourceType;
813*cdf0e10cSrcweir             if ( i == ::com::sun::star::ui::UIElementType::MENUBAR )
814*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_MENUBAR();
815*cdf0e10cSrcweir             else if ( i == ::com::sun::star::ui::UIElementType::TOOLBAR )
816*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_TOOLBAR();
817*cdf0e10cSrcweir             else if ( i == ::com::sun::star::ui::UIElementType::STATUSBAR )
818*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_STATUSBAR();
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir             if ( aResourceType.getLength() > 0 )
821*cdf0e10cSrcweir             {
822*cdf0e10cSrcweir                 m_pStorageHandler[i] = new PresetHandler( m_xServiceManager );
823*cdf0e10cSrcweir                 m_pStorageHandler[i]->connectToResource( PresetHandler::E_MODULES,
824*cdf0e10cSrcweir                                                          aResourceType, // this path wont be used later ... seee next lines!
825*cdf0e10cSrcweir                                                          m_aModuleShortName,
826*cdf0e10cSrcweir                                                          css::uno::Reference< css::embed::XStorage >()); // no document root used here!
827*cdf0e10cSrcweir             }
828*cdf0e10cSrcweir         }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir         // initialize root storages for all resource types
831*cdf0e10cSrcweir         m_xUserRootCommit       = css::uno::Reference< css::embed::XTransactedObject >(
832*cdf0e10cSrcweir                                     m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getOrCreateRootStorageUser(), css::uno::UNO_QUERY); // can be empty
833*cdf0e10cSrcweir         m_xDefaultConfigStorage = m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getParentStorageShare(
834*cdf0e10cSrcweir                                     m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getWorkingStorageShare());
835*cdf0e10cSrcweir         m_xUserConfigStorage    = m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getParentStorageUser(
836*cdf0e10cSrcweir                                     m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getWorkingStorageUser());
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir         if ( m_xUserConfigStorage.is() )
839*cdf0e10cSrcweir         {
840*cdf0e10cSrcweir             Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY );
841*cdf0e10cSrcweir             if ( xPropSet.is() )
842*cdf0e10cSrcweir             {
843*cdf0e10cSrcweir                 long nOpenMode = 0;
844*cdf0e10cSrcweir                 if ( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))) >>= nOpenMode )
845*cdf0e10cSrcweir                     m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
846*cdf0e10cSrcweir             }
847*cdf0e10cSrcweir         }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir         impl_Initialize();
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir         m_bInitialized = true;
852*cdf0e10cSrcweir     }
853*cdf0e10cSrcweir }
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir // XUIConfiguration
856*cdf0e10cSrcweir void UIConfigurationManagerImpl::addConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
857*cdf0e10cSrcweir {
858*cdf0e10cSrcweir     {
859*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
862*cdf0e10cSrcweir         if ( m_bDisposed )
863*cdf0e10cSrcweir             throw DisposedException();
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener );
867*cdf0e10cSrcweir }
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir void UIConfigurationManagerImpl::removeConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
872*cdf0e10cSrcweir     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener );
873*cdf0e10cSrcweir }
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir // XUIConfigurationManager
877*cdf0e10cSrcweir void UIConfigurationManagerImpl::reset() throw (::com::sun::star::uno::RuntimeException)
878*cdf0e10cSrcweir {
879*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
882*cdf0e10cSrcweir     if ( m_bDisposed )
883*cdf0e10cSrcweir         throw DisposedException();
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir     bool bResetStorage( false );
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir     if ( !isReadOnly() )
888*cdf0e10cSrcweir     {
889*cdf0e10cSrcweir         // Remove all elements from our user-defined storage!
890*cdf0e10cSrcweir         try
891*cdf0e10cSrcweir         {
892*cdf0e10cSrcweir             for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
893*cdf0e10cSrcweir             {
894*cdf0e10cSrcweir                 UIElementType&        rElementType = m_aUIElements[LAYER_USERDEFINED][i];
895*cdf0e10cSrcweir                 Reference< XStorage > xSubStorage( rElementType.xStorage, UNO_QUERY );
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir                 if ( xSubStorage.is() )
898*cdf0e10cSrcweir                 {
899*cdf0e10cSrcweir                     bool bCommitSubStorage( false );
900*cdf0e10cSrcweir                     Reference< XNameAccess > xSubStorageNameAccess( xSubStorage, UNO_QUERY );
901*cdf0e10cSrcweir                     Sequence< rtl::OUString > aUIElementStreamNames = xSubStorageNameAccess->getElementNames();
902*cdf0e10cSrcweir                     for ( sal_Int32 j = 0; j < aUIElementStreamNames.getLength(); j++ )
903*cdf0e10cSrcweir                     {
904*cdf0e10cSrcweir                         xSubStorage->removeElement( aUIElementStreamNames[j] );
905*cdf0e10cSrcweir                         bCommitSubStorage = true;
906*cdf0e10cSrcweir                     }
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir                     if ( bCommitSubStorage )
909*cdf0e10cSrcweir                     {
910*cdf0e10cSrcweir                         Reference< XTransactedObject > xTransactedObject( xSubStorage, UNO_QUERY );
911*cdf0e10cSrcweir 						if ( xTransactedObject.is() )
912*cdf0e10cSrcweir                         	xTransactedObject->commit();
913*cdf0e10cSrcweir                         m_pStorageHandler[i]->commitUserChanges();
914*cdf0e10cSrcweir                     }
915*cdf0e10cSrcweir                 }
916*cdf0e10cSrcweir             }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir             bResetStorage = true;
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir             // remove settings from user defined layer and notify listener about removed settings data!
921*cdf0e10cSrcweir             ConfigEventNotifyContainer aRemoveEventNotifyContainer;
922*cdf0e10cSrcweir             ConfigEventNotifyContainer aReplaceEventNotifyContainer;
923*cdf0e10cSrcweir             for ( sal_Int16 j = 1; j < ::com::sun::star::ui::UIElementType::COUNT; j++ )
924*cdf0e10cSrcweir             {
925*cdf0e10cSrcweir                 try
926*cdf0e10cSrcweir                 {
927*cdf0e10cSrcweir                     UIElementType& rUserElementType     = m_aUIElements[LAYER_USERDEFINED][j];
928*cdf0e10cSrcweir                     UIElementType& rDefaultElementType  = m_aUIElements[LAYER_DEFAULT][j];
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir                     impl_resetElementTypeData( rUserElementType, rDefaultElementType, aRemoveEventNotifyContainer, aReplaceEventNotifyContainer );
931*cdf0e10cSrcweir                     rUserElementType.bModified = sal_False;
932*cdf0e10cSrcweir                 }
933*cdf0e10cSrcweir                 catch ( Exception& )
934*cdf0e10cSrcweir                 {
935*cdf0e10cSrcweir                     throw IOException();
936*cdf0e10cSrcweir                 }
937*cdf0e10cSrcweir             }
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir             m_bModified = sal_False;
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir             // Unlock mutex before notify our listeners
942*cdf0e10cSrcweir             aGuard.unlock();
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir             // Notify our listeners
945*cdf0e10cSrcweir             ::std::for_each(aRemoveEventNotifyContainer.begin(),aRemoveEventNotifyContainer.end(),::boost::bind(&UIConfigurationManagerImpl::implts_notifyContainerListener,this,_1,NotifyOp_Remove));
946*cdf0e10cSrcweir             ::std::for_each(aReplaceEventNotifyContainer.begin(),aReplaceEventNotifyContainer.end(),::boost::bind(&UIConfigurationManagerImpl::implts_notifyContainerListener,this,_1,NotifyOp_Replace));
947*cdf0e10cSrcweir         }
948*cdf0e10cSrcweir         catch ( ::com::sun::star::lang::IllegalArgumentException& )
949*cdf0e10cSrcweir         {
950*cdf0e10cSrcweir         }
951*cdf0e10cSrcweir         catch ( ::com::sun::star::container::NoSuchElementException& )
952*cdf0e10cSrcweir         {
953*cdf0e10cSrcweir         }
954*cdf0e10cSrcweir         catch ( ::com::sun::star::embed::InvalidStorageException& )
955*cdf0e10cSrcweir         {
956*cdf0e10cSrcweir         }
957*cdf0e10cSrcweir         catch ( ::com::sun::star::embed::StorageWrappedTargetException& )
958*cdf0e10cSrcweir         {
959*cdf0e10cSrcweir         }
960*cdf0e10cSrcweir     }
961*cdf0e10cSrcweir }
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > UIConfigurationManagerImpl::getUIElementsInfo( sal_Int16 ElementType )
964*cdf0e10cSrcweir throw ( IllegalArgumentException, RuntimeException )
965*cdf0e10cSrcweir {
966*cdf0e10cSrcweir     if (( ElementType < 0 ) || ( ElementType >= ::com::sun::star::ui::UIElementType::COUNT ))
967*cdf0e10cSrcweir         throw IllegalArgumentException();
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
970*cdf0e10cSrcweir     if ( m_bDisposed )
971*cdf0e10cSrcweir         throw DisposedException();
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir     Sequence< Sequence< PropertyValue > > aElementInfoSeq;
974*cdf0e10cSrcweir     UIElementInfoHashMap aUIElementInfoCollection;
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir     if ( ElementType == ::com::sun::star::ui::UIElementType::UNKNOWN )
977*cdf0e10cSrcweir     {
978*cdf0e10cSrcweir         for ( sal_Int16 i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
979*cdf0e10cSrcweir             impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, sal_Int16( i ) );
980*cdf0e10cSrcweir     }
981*cdf0e10cSrcweir     else
982*cdf0e10cSrcweir         impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, ElementType );
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir     Sequence< PropertyValue > aUIElementInfo( 2 );
985*cdf0e10cSrcweir     aUIElementInfo[0].Name = m_aPropResourceURL;
986*cdf0e10cSrcweir     aUIElementInfo[1].Name = m_aPropUIName;
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir     aElementInfoSeq.realloc( aUIElementInfoCollection.size() );
989*cdf0e10cSrcweir     UIElementInfoHashMap::const_iterator pIter = aUIElementInfoCollection.begin();
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir     sal_Int32 n = 0;
992*cdf0e10cSrcweir     while ( pIter != aUIElementInfoCollection.end() )
993*cdf0e10cSrcweir     {
994*cdf0e10cSrcweir         aUIElementInfo[0].Value <<= pIter->second.aResourceURL;
995*cdf0e10cSrcweir         aUIElementInfo[1].Value <<= pIter->second.aUIName;
996*cdf0e10cSrcweir         aElementInfoSeq[n++] = aUIElementInfo;
997*cdf0e10cSrcweir         ++pIter;
998*cdf0e10cSrcweir     }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir     return aElementInfoSeq;
1001*cdf0e10cSrcweir }
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir Reference< XIndexContainer > UIConfigurationManagerImpl::createSettings() throw (::com::sun::star::uno::RuntimeException)
1004*cdf0e10cSrcweir {
1005*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir     if ( m_bDisposed )
1008*cdf0e10cSrcweir         throw DisposedException();
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir     // Creates an empty item container which can be filled from outside
1011*cdf0e10cSrcweir     return Reference< XIndexContainer >( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY );
1012*cdf0e10cSrcweir }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir sal_Bool UIConfigurationManagerImpl::hasSettings( const ::rtl::OUString& ResourceURL )
1015*cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1016*cdf0e10cSrcweir {
1017*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1020*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1021*cdf0e10cSrcweir         throw IllegalArgumentException();
1022*cdf0e10cSrcweir     else
1023*cdf0e10cSrcweir     {
1024*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1025*cdf0e10cSrcweir 
1026*cdf0e10cSrcweir         if ( m_bDisposed )
1027*cdf0e10cSrcweir             throw DisposedException();
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false );
1030*cdf0e10cSrcweir         if ( pDataSettings && ( m_bUseDefault || !pDataSettings->bDefault) )
1031*cdf0e10cSrcweir             return sal_True;
1032*cdf0e10cSrcweir     }
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir     return sal_False;
1035*cdf0e10cSrcweir }
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir Reference< XIndexAccess > UIConfigurationManagerImpl::getSettings( const ::rtl::OUString& ResourceURL, sal_Bool bWriteable )
1038*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1039*cdf0e10cSrcweir {
1040*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1043*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1044*cdf0e10cSrcweir         throw IllegalArgumentException();
1045*cdf0e10cSrcweir     else
1046*cdf0e10cSrcweir     {
1047*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir         if ( m_bDisposed )
1050*cdf0e10cSrcweir             throw DisposedException();
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
1053*cdf0e10cSrcweir         if ( pDataSettings && ( m_bUseDefault || !pDataSettings->bDefault) )
1054*cdf0e10cSrcweir         {
1055*cdf0e10cSrcweir             // Create a copy of our data if someone wants to change the data.
1056*cdf0e10cSrcweir             if ( bWriteable )
1057*cdf0e10cSrcweir                 return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY );
1058*cdf0e10cSrcweir             else
1059*cdf0e10cSrcweir                 return pDataSettings->xSettings;
1060*cdf0e10cSrcweir         }
1061*cdf0e10cSrcweir     }
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir     throw NoSuchElementException();
1064*cdf0e10cSrcweir }
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir void UIConfigurationManagerImpl::replaceSettings( const ::rtl::OUString& ResourceURL, const Reference< ::com::sun::star::container::XIndexAccess >& aNewData )
1067*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException)
1068*cdf0e10cSrcweir {
1069*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1072*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1073*cdf0e10cSrcweir         throw IllegalArgumentException();
1074*cdf0e10cSrcweir     else if ( m_bReadOnly )
1075*cdf0e10cSrcweir         throw IllegalAccessException();
1076*cdf0e10cSrcweir     else
1077*cdf0e10cSrcweir     {
1078*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir         if ( m_bDisposed )
1081*cdf0e10cSrcweir             throw DisposedException();
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
1084*cdf0e10cSrcweir         if ( pDataSettings && ( m_bUseDefault || !pDataSettings->bDefault) )
1085*cdf0e10cSrcweir         {
1086*cdf0e10cSrcweir             if ( !m_bUseDefault || !pDataSettings->bDefaultNode )
1087*cdf0e10cSrcweir             {
1088*cdf0e10cSrcweir                 // we have a settings entry in our user-defined layer - replace
1089*cdf0e10cSrcweir                 Reference< XIndexAccess > xOldSettings = pDataSettings->xSettings;
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir                 // Create a copy of the data if the container is not const
1092*cdf0e10cSrcweir                 Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY );
1093*cdf0e10cSrcweir                 if ( xReplace.is() )
1094*cdf0e10cSrcweir                     pDataSettings->xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY );
1095*cdf0e10cSrcweir                 else
1096*cdf0e10cSrcweir                     pDataSettings->xSettings = aNewData;
1097*cdf0e10cSrcweir                 pDataSettings->bDefault  = false;
1098*cdf0e10cSrcweir                 pDataSettings->bModified = true;
1099*cdf0e10cSrcweir                 m_bModified = true;
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir                 // Modify type container
1102*cdf0e10cSrcweir                 UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType];
1103*cdf0e10cSrcweir                 rElementType.bModified = true;
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir                 Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir                 // Create event to notify listener about replaced element settings
1108*cdf0e10cSrcweir                 ConfigurationEvent aEvent;
1109*cdf0e10cSrcweir 
1110*cdf0e10cSrcweir                 aEvent.ResourceURL = ResourceURL;
1111*cdf0e10cSrcweir                 aEvent.Accessor <<= xThis;
1112*cdf0e10cSrcweir                 aEvent.Source = m_xOwner;
1113*cdf0e10cSrcweir                 aEvent.ReplacedElement <<= xOldSettings;
1114*cdf0e10cSrcweir                 aEvent.Element <<= pDataSettings->xSettings;
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir                 aGuard.unlock();
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir                 implts_notifyContainerListener( aEvent, NotifyOp_Replace );
1119*cdf0e10cSrcweir             }
1120*cdf0e10cSrcweir             else
1121*cdf0e10cSrcweir             {
1122*cdf0e10cSrcweir                 // we have no settings in our user-defined layer - insert
1123*cdf0e10cSrcweir                 UIElementData aUIElementData;
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir                 aUIElementData.bDefault     = false;
1126*cdf0e10cSrcweir                 aUIElementData.bDefaultNode = false;
1127*cdf0e10cSrcweir                 aUIElementData.bModified    = true;
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir                 // Create a copy of the data if the container is not const
1130*cdf0e10cSrcweir                 Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY );
1131*cdf0e10cSrcweir                 if ( xReplace.is() )
1132*cdf0e10cSrcweir                     aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY );
1133*cdf0e10cSrcweir                 else
1134*cdf0e10cSrcweir                     aUIElementData.xSettings = aNewData;
1135*cdf0e10cSrcweir                 aUIElementData.aName        = RetrieveNameFromResourceURL( ResourceURL ) + m_aXMLPostfix;
1136*cdf0e10cSrcweir                 aUIElementData.aResourceURL = ResourceURL;
1137*cdf0e10cSrcweir                 m_bModified = true;
1138*cdf0e10cSrcweir 
1139*cdf0e10cSrcweir                 // Modify type container
1140*cdf0e10cSrcweir                 UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType];
1141*cdf0e10cSrcweir                 rElementType.bModified = true;
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir                 UIElementDataHashMap& rElements = rElementType.aElementsHashMap;
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir                 // Check our user element settings hash map as it can already contain settings that have been set to default!
1146*cdf0e10cSrcweir                 // If no node can be found, we have to insert it.
1147*cdf0e10cSrcweir                 UIElementDataHashMap::iterator pIter = rElements.find( ResourceURL );
1148*cdf0e10cSrcweir                 if ( pIter != rElements.end() )
1149*cdf0e10cSrcweir                     pIter->second = aUIElementData;
1150*cdf0e10cSrcweir                 else
1151*cdf0e10cSrcweir                     rElements.insert( UIElementDataHashMap::value_type( ResourceURL, aUIElementData ));
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir                 Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
1154*cdf0e10cSrcweir 
1155*cdf0e10cSrcweir                 // Create event to notify listener about replaced element settings
1156*cdf0e10cSrcweir                 ConfigurationEvent aEvent;
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir                 aEvent.ResourceURL = ResourceURL;
1159*cdf0e10cSrcweir                 aEvent.Accessor <<= xThis;
1160*cdf0e10cSrcweir                 aEvent.Source = m_xOwner;
1161*cdf0e10cSrcweir                 aEvent.ReplacedElement <<= pDataSettings->xSettings;
1162*cdf0e10cSrcweir                 aEvent.Element <<= aUIElementData.xSettings;
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir                 aGuard.unlock();
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir                 implts_notifyContainerListener( aEvent, NotifyOp_Replace );
1167*cdf0e10cSrcweir             }
1168*cdf0e10cSrcweir         }
1169*cdf0e10cSrcweir         else
1170*cdf0e10cSrcweir             throw NoSuchElementException();
1171*cdf0e10cSrcweir     }
1172*cdf0e10cSrcweir }
1173*cdf0e10cSrcweir 
1174*cdf0e10cSrcweir void UIConfigurationManagerImpl::removeSettings( const ::rtl::OUString& ResourceURL )
1175*cdf0e10cSrcweir throw ( NoSuchElementException, IllegalArgumentException, IllegalAccessException, RuntimeException)
1176*cdf0e10cSrcweir {
1177*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1180*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1181*cdf0e10cSrcweir         throw IllegalArgumentException();
1182*cdf0e10cSrcweir     else if ( m_bReadOnly )
1183*cdf0e10cSrcweir         throw IllegalAccessException();
1184*cdf0e10cSrcweir     else
1185*cdf0e10cSrcweir     {
1186*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir         if ( m_bDisposed )
1189*cdf0e10cSrcweir             throw DisposedException();
1190*cdf0e10cSrcweir 
1191*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
1192*cdf0e10cSrcweir         if ( pDataSettings )
1193*cdf0e10cSrcweir         {
1194*cdf0e10cSrcweir             // If element settings are default, we don't need to change anything!
1195*cdf0e10cSrcweir             if ( pDataSettings->bDefault )
1196*cdf0e10cSrcweir                 return;
1197*cdf0e10cSrcweir             else
1198*cdf0e10cSrcweir             {
1199*cdf0e10cSrcweir                 Reference< XIndexAccess > xRemovedSettings = pDataSettings->xSettings;
1200*cdf0e10cSrcweir                 pDataSettings->bDefault = true;
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir                 // check if this is a default layer node
1203*cdf0e10cSrcweir                 if ( !m_bUseDefault || !pDataSettings->bDefaultNode )
1204*cdf0e10cSrcweir                     pDataSettings->bModified = true; // we have to remove this node from the user layer!
1205*cdf0e10cSrcweir                 pDataSettings->xSettings.clear();
1206*cdf0e10cSrcweir                 m_bModified = true; // user layer must be written
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir                 // Modify type container
1209*cdf0e10cSrcweir                 UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType];
1210*cdf0e10cSrcweir                 rElementType.bModified = true;
1211*cdf0e10cSrcweir 
1212*cdf0e10cSrcweir                 Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
1213*cdf0e10cSrcweir                 // Check if we have settings in the default layer which replaces the user-defined one!
1214*cdf0e10cSrcweir                 UIElementData* pDefaultDataSettings = m_bUseDefault ? impl_findUIElementData( ResourceURL, nElementType ) : NULL;
1215*cdf0e10cSrcweir                 if ( pDefaultDataSettings )
1216*cdf0e10cSrcweir                 {
1217*cdf0e10cSrcweir                     // Create event to notify listener about replaced element settings
1218*cdf0e10cSrcweir                     ConfigurationEvent aEvent;
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir                     aEvent.ResourceURL = ResourceURL;
1221*cdf0e10cSrcweir                     aEvent.Accessor <<= xThis;
1222*cdf0e10cSrcweir                     aEvent.Source = m_xOwner;
1223*cdf0e10cSrcweir                     aEvent.Element <<= xRemovedSettings;
1224*cdf0e10cSrcweir                     aEvent.ReplacedElement <<= pDefaultDataSettings->xSettings;
1225*cdf0e10cSrcweir 
1226*cdf0e10cSrcweir                     aGuard.unlock();
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir                     implts_notifyContainerListener( aEvent, NotifyOp_Replace );
1229*cdf0e10cSrcweir                 }
1230*cdf0e10cSrcweir                 else
1231*cdf0e10cSrcweir                 {
1232*cdf0e10cSrcweir                     // Create event to notify listener about removed element settings
1233*cdf0e10cSrcweir                     ConfigurationEvent aEvent;
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir                     aEvent.ResourceURL = ResourceURL;
1236*cdf0e10cSrcweir                     aEvent.Accessor <<= xThis;
1237*cdf0e10cSrcweir                     aEvent.Source = m_xOwner;
1238*cdf0e10cSrcweir                     aEvent.Element <<= xRemovedSettings;
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir                     aGuard.unlock();
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir                     implts_notifyContainerListener( aEvent, NotifyOp_Remove );
1243*cdf0e10cSrcweir                 }
1244*cdf0e10cSrcweir             }
1245*cdf0e10cSrcweir         }
1246*cdf0e10cSrcweir         else
1247*cdf0e10cSrcweir             throw NoSuchElementException();
1248*cdf0e10cSrcweir     }
1249*cdf0e10cSrcweir }
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir void UIConfigurationManagerImpl::insertSettings( const ::rtl::OUString& NewResourceURL, const Reference< XIndexAccess >& aNewData )
1252*cdf0e10cSrcweir throw ( ElementExistException, IllegalArgumentException, IllegalAccessException, RuntimeException )
1253*cdf0e10cSrcweir {
1254*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( NewResourceURL );
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1257*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1258*cdf0e10cSrcweir         throw IllegalArgumentException();
1259*cdf0e10cSrcweir     else if ( m_bReadOnly )
1260*cdf0e10cSrcweir         throw IllegalAccessException();
1261*cdf0e10cSrcweir     else
1262*cdf0e10cSrcweir     {
1263*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1264*cdf0e10cSrcweir 
1265*cdf0e10cSrcweir         if ( m_bDisposed )
1266*cdf0e10cSrcweir             throw DisposedException();
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir         bool           bInsertData( false );
1269*cdf0e10cSrcweir         UIElementData aUIElementData;
1270*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( NewResourceURL, nElementType );
1271*cdf0e10cSrcweir         if ( !m_bUseDefault )
1272*cdf0e10cSrcweir         {
1273*cdf0e10cSrcweir             if ( pDataSettings && !pDataSettings->bDefault )
1274*cdf0e10cSrcweir                 throw ElementExistException();
1275*cdf0e10cSrcweir             if ( !pDataSettings )
1276*cdf0e10cSrcweir             {
1277*cdf0e10cSrcweir                 pDataSettings = &aUIElementData;
1278*cdf0e10cSrcweir                 bInsertData   = true;
1279*cdf0e10cSrcweir             }
1280*cdf0e10cSrcweir         }
1281*cdf0e10cSrcweir         if ( !pDataSettings || !m_bUseDefault )
1282*cdf0e10cSrcweir         {
1283*cdf0e10cSrcweir             aUIElementData.bDefault     = false;
1284*cdf0e10cSrcweir             if ( !m_bUseDefault )
1285*cdf0e10cSrcweir                 aUIElementData.bDefaultNode = false;
1286*cdf0e10cSrcweir             aUIElementData.bModified    = true;
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir             // Create a copy of the data if the container is not const
1289*cdf0e10cSrcweir             Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY );
1290*cdf0e10cSrcweir             if ( xReplace.is() )
1291*cdf0e10cSrcweir                 aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY );
1292*cdf0e10cSrcweir             else
1293*cdf0e10cSrcweir                 aUIElementData.xSettings = aNewData;
1294*cdf0e10cSrcweir 
1295*cdf0e10cSrcweir             m_bModified = true;
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir             UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType];
1298*cdf0e10cSrcweir             rElementType.bModified = true;
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir             if ( bInsertData )
1301*cdf0e10cSrcweir             {
1302*cdf0e10cSrcweir                 aUIElementData.aName        = RetrieveNameFromResourceURL( NewResourceURL ) + m_aXMLPostfix;
1303*cdf0e10cSrcweir                 aUIElementData.aResourceURL = NewResourceURL;
1304*cdf0e10cSrcweir                 UIElementDataHashMap& rElements = rElementType.aElementsHashMap;
1305*cdf0e10cSrcweir                 rElements.insert( UIElementDataHashMap::value_type( NewResourceURL, aUIElementData ));
1306*cdf0e10cSrcweir             }
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir             Reference< XIndexAccess > xInsertSettings( aUIElementData.xSettings );
1309*cdf0e10cSrcweir             Reference< XUIConfigurationManager > xThis( m_xOwner, UNO_QUERY );
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir             // Create event to notify listener about removed element settings
1312*cdf0e10cSrcweir             ConfigurationEvent aEvent;
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir             aEvent.ResourceURL = NewResourceURL;
1315*cdf0e10cSrcweir             aEvent.Accessor <<= xThis;
1316*cdf0e10cSrcweir             aEvent.Source = m_xOwner;
1317*cdf0e10cSrcweir             aEvent.Element <<= xInsertSettings;
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir             aGuard.unlock();
1320*cdf0e10cSrcweir 
1321*cdf0e10cSrcweir             implts_notifyContainerListener( aEvent, NotifyOp_Insert );
1322*cdf0e10cSrcweir         }
1323*cdf0e10cSrcweir         else
1324*cdf0e10cSrcweir             throw ElementExistException();
1325*cdf0e10cSrcweir     }
1326*cdf0e10cSrcweir }
1327*cdf0e10cSrcweir 
1328*cdf0e10cSrcweir Reference< XInterface > UIConfigurationManagerImpl::getImageManager() throw (::com::sun::star::uno::RuntimeException)
1329*cdf0e10cSrcweir {
1330*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir     if ( m_bDisposed )
1333*cdf0e10cSrcweir         throw DisposedException();
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir     if ( !m_xModuleImageManager.is() )
1336*cdf0e10cSrcweir     {
1337*cdf0e10cSrcweir         if ( m_bUseDefault )
1338*cdf0e10cSrcweir             m_xModuleImageManager = Reference< XComponent >( static_cast< cppu::OWeakObject *>( new ModuleImageManager( m_xServiceManager )),
1339*cdf0e10cSrcweir                                                          UNO_QUERY );
1340*cdf0e10cSrcweir         else
1341*cdf0e10cSrcweir             m_xModuleImageManager = Reference< XComponent >( static_cast< cppu::OWeakObject *>( new ImageManager( m_xServiceManager )),
1342*cdf0e10cSrcweir                                                          UNO_QUERY );
1343*cdf0e10cSrcweir         Reference< XInitialization > xInit( m_xModuleImageManager, UNO_QUERY );
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir         Sequence< Any > aPropSeq( m_bUseDefault ? 3 : 2 );
1346*cdf0e10cSrcweir         PropertyValue aPropValue;
1347*cdf0e10cSrcweir         aPropValue.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" ));
1348*cdf0e10cSrcweir         aPropValue.Value <<= m_xUserConfigStorage;
1349*cdf0e10cSrcweir         aPropSeq[0] <<= aPropValue;
1350*cdf0e10cSrcweir         aPropValue.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
1351*cdf0e10cSrcweir         aPropValue.Value <<= m_aModuleIdentifier;
1352*cdf0e10cSrcweir         aPropSeq[1] <<= aPropValue;
1353*cdf0e10cSrcweir         if ( m_bUseDefault )
1354*cdf0e10cSrcweir         {
1355*cdf0e10cSrcweir             aPropValue.Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserRootCommit" ));
1356*cdf0e10cSrcweir             aPropValue.Value <<= m_xUserRootCommit;
1357*cdf0e10cSrcweir             aPropSeq[2] <<= aPropValue;
1358*cdf0e10cSrcweir         }
1359*cdf0e10cSrcweir 
1360*cdf0e10cSrcweir         xInit->initialize( aPropSeq );
1361*cdf0e10cSrcweir     }
1362*cdf0e10cSrcweir 
1363*cdf0e10cSrcweir     return Reference< XInterface >( m_xModuleImageManager, UNO_QUERY );
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir //    return Reference< XInterface >();
1366*cdf0e10cSrcweir }
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir Reference< XInterface > UIConfigurationManagerImpl::getShortCutManager() throw (::com::sun::star::uno::RuntimeException)
1369*cdf0e10cSrcweir {
1370*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1371*cdf0e10cSrcweir     if ( !m_bUseDefault && m_xAccConfig.is())
1372*cdf0e10cSrcweir         return m_xAccConfig;
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir     Reference< XMultiServiceFactory > xSMGR   = m_xServiceManager;
1375*cdf0e10cSrcweir     ::rtl::OUString                   aModule = m_aModuleIdentifier;
1376*cdf0e10cSrcweir     Reference< XStorage >             xDocumentRoot = m_xUserConfigStorage;
1377*cdf0e10cSrcweir     aGuard.unlock();
1378*cdf0e10cSrcweir     Reference< XInterface >      xManager = xSMGR->createInstance(m_bUseDefault ? SERVICENAME_MODULEACCELERATORCONFIGURATION : SERVICENAME_DOCUMENTACCELERATORCONFIGURATION );
1379*cdf0e10cSrcweir     Reference< XInitialization > xInit    (xManager, UNO_QUERY_THROW);
1380*cdf0e10cSrcweir 
1381*cdf0e10cSrcweir     PropertyValue aProp;
1382*cdf0e10cSrcweir     Sequence< Any > lArgs(1);
1383*cdf0e10cSrcweir     if ( m_bUseDefault )
1384*cdf0e10cSrcweir     {
1385*cdf0e10cSrcweir         aProp.Name    = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ModuleIdentifier"));
1386*cdf0e10cSrcweir         aProp.Value <<= aModule;
1387*cdf0e10cSrcweir     } // if ( m_bUseDefault )
1388*cdf0e10cSrcweir     else
1389*cdf0e10cSrcweir     {
1390*cdf0e10cSrcweir         aProp.Name    = ::rtl::OUString::createFromAscii("DocumentRoot");
1391*cdf0e10cSrcweir         aProp.Value <<= xDocumentRoot;
1392*cdf0e10cSrcweir     }
1393*cdf0e10cSrcweir     lArgs[0] <<= aProp;
1394*cdf0e10cSrcweir     xInit->initialize(lArgs);
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir     if ( !m_bUseDefault )
1397*cdf0e10cSrcweir     {
1398*cdf0e10cSrcweir         // SAFE ->
1399*cdf0e10cSrcweir         aGuard.lock();
1400*cdf0e10cSrcweir         m_xAccConfig = xManager;
1401*cdf0e10cSrcweir         aGuard.unlock();
1402*cdf0e10cSrcweir         // <- SAFE
1403*cdf0e10cSrcweir     }
1404*cdf0e10cSrcweir 
1405*cdf0e10cSrcweir     return xManager;
1406*cdf0e10cSrcweir }
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir Reference< XInterface > UIConfigurationManagerImpl::getEventsManager() throw (::com::sun::star::uno::RuntimeException)
1409*cdf0e10cSrcweir {
1410*cdf0e10cSrcweir     return Reference< XInterface >();
1411*cdf0e10cSrcweir }
1412*cdf0e10cSrcweir // XUIConfigurationStorage
1413*cdf0e10cSrcweir void UIConfigurationManagerImpl::setStorage( const Reference< XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException)
1414*cdf0e10cSrcweir {
1415*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1416*cdf0e10cSrcweir 
1417*cdf0e10cSrcweir     if ( m_bDisposed )
1418*cdf0e10cSrcweir         throw DisposedException();
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() )
1421*cdf0e10cSrcweir     {
1422*cdf0e10cSrcweir         try
1423*cdf0e10cSrcweir         {
1424*cdf0e10cSrcweir             // Dispose old storage to be sure that it will be closed
1425*cdf0e10cSrcweir             Reference< XComponent > xComponent( m_xUserConfigStorage, UNO_QUERY );
1426*cdf0e10cSrcweir             if ( xComponent.is() )
1427*cdf0e10cSrcweir                 xComponent->dispose();
1428*cdf0e10cSrcweir         }
1429*cdf0e10cSrcweir         catch ( Exception& )
1430*cdf0e10cSrcweir         {
1431*cdf0e10cSrcweir         }
1432*cdf0e10cSrcweir     }
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir     // We store the new storage. Be careful it could be an empty reference!
1435*cdf0e10cSrcweir     m_xUserConfigStorage = Storage;
1436*cdf0e10cSrcweir     m_bReadOnly         = sal_True;
1437*cdf0e10cSrcweir 
1438*cdf0e10cSrcweir     Reference< XUIConfigurationStorage > xAccUpdate(m_xAccConfig, UNO_QUERY);
1439*cdf0e10cSrcweir     if ( xAccUpdate.is() )
1440*cdf0e10cSrcweir         xAccUpdate->setStorage( m_xUserConfigStorage );
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir     if ( m_xModuleImageManager.is() )
1443*cdf0e10cSrcweir     {
1444*cdf0e10cSrcweir         ImageManager* pImageManager = (ImageManager*)m_xModuleImageManager.get();
1445*cdf0e10cSrcweir         if ( pImageManager )
1446*cdf0e10cSrcweir             pImageManager->setStorage( m_xUserConfigStorage );
1447*cdf0e10cSrcweir     }
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() )
1450*cdf0e10cSrcweir     {
1451*cdf0e10cSrcweir         ::rtl::OUString sEmpty;
1452*cdf0e10cSrcweir         for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
1453*cdf0e10cSrcweir         {
1454*cdf0e10cSrcweir             rtl::OUString aResourceType;
1455*cdf0e10cSrcweir             if ( i == ::com::sun::star::ui::UIElementType::MENUBAR )
1456*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_MENUBAR();
1457*cdf0e10cSrcweir             else if ( i == ::com::sun::star::ui::UIElementType::TOOLBAR )
1458*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_TOOLBAR();
1459*cdf0e10cSrcweir             else if ( i == ::com::sun::star::ui::UIElementType::STATUSBAR )
1460*cdf0e10cSrcweir                 aResourceType = PresetHandler::RESOURCETYPE_STATUSBAR();
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir             //if ( aResourceType.getLength() > 0 )
1463*cdf0e10cSrcweir             {
1464*cdf0e10cSrcweir                 m_pStorageHandler[i] = new PresetHandler( m_xServiceManager );
1465*cdf0e10cSrcweir                 m_pStorageHandler[i]->connectToResource( PresetHandler::E_DOCUMENT,
1466*cdf0e10cSrcweir                                                          rtl::OUString::createFromAscii( UIELEMENTTYPENAMES[i] ), // this path wont be used later ... seee next lines!
1467*cdf0e10cSrcweir                                                          sEmpty,
1468*cdf0e10cSrcweir                                                          m_xUserConfigStorage);
1469*cdf0e10cSrcweir             }
1470*cdf0e10cSrcweir         }
1471*cdf0e10cSrcweir         Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY );
1472*cdf0e10cSrcweir         if ( xPropSet.is() )
1473*cdf0e10cSrcweir         {
1474*cdf0e10cSrcweir             try
1475*cdf0e10cSrcweir             {
1476*cdf0e10cSrcweir                 long nOpenMode = 0;
1477*cdf0e10cSrcweir                 if ( xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))) >>= nOpenMode )
1478*cdf0e10cSrcweir                     m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
1479*cdf0e10cSrcweir             }
1480*cdf0e10cSrcweir             catch ( com::sun::star::beans::UnknownPropertyException& )
1481*cdf0e10cSrcweir             {
1482*cdf0e10cSrcweir             }
1483*cdf0e10cSrcweir 			catch ( com::sun::star::lang::WrappedTargetException& )
1484*cdf0e10cSrcweir             {
1485*cdf0e10cSrcweir             }
1486*cdf0e10cSrcweir         }
1487*cdf0e10cSrcweir     }
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir     impl_Initialize();
1490*cdf0e10cSrcweir }
1491*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1492*cdf0e10cSrcweir sal_Bool UIConfigurationManagerImpl::hasStorage() throw (::com::sun::star::uno::RuntimeException)
1493*cdf0e10cSrcweir {
1494*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1495*cdf0e10cSrcweir 
1496*cdf0e10cSrcweir     if ( m_bDisposed )
1497*cdf0e10cSrcweir         throw DisposedException();
1498*cdf0e10cSrcweir 
1499*cdf0e10cSrcweir     return ( m_xUserConfigStorage.is() );
1500*cdf0e10cSrcweir }
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir // XUIConfigurationManagerImpl
1503*cdf0e10cSrcweir sal_Bool UIConfigurationManagerImpl::isDefaultSettings( const ::rtl::OUString& ResourceURL )
1504*cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1505*cdf0e10cSrcweir {
1506*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1507*cdf0e10cSrcweir 
1508*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1509*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1510*cdf0e10cSrcweir         throw IllegalArgumentException();
1511*cdf0e10cSrcweir     else
1512*cdf0e10cSrcweir     {
1513*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1514*cdf0e10cSrcweir 
1515*cdf0e10cSrcweir         if ( m_bDisposed )
1516*cdf0e10cSrcweir             throw DisposedException();
1517*cdf0e10cSrcweir 
1518*cdf0e10cSrcweir         UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false );
1519*cdf0e10cSrcweir         if ( pDataSettings && pDataSettings->bDefaultNode )
1520*cdf0e10cSrcweir             return sal_True;
1521*cdf0e10cSrcweir     }
1522*cdf0e10cSrcweir 
1523*cdf0e10cSrcweir     return sal_False;
1524*cdf0e10cSrcweir }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir Reference< XIndexAccess > UIConfigurationManagerImpl::getDefaultSettings( const ::rtl::OUString& ResourceURL )
1527*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1528*cdf0e10cSrcweir {
1529*cdf0e10cSrcweir     sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
1530*cdf0e10cSrcweir 
1531*cdf0e10cSrcweir     if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) ||
1532*cdf0e10cSrcweir         ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT   ))
1533*cdf0e10cSrcweir         throw IllegalArgumentException();
1534*cdf0e10cSrcweir     else
1535*cdf0e10cSrcweir     {
1536*cdf0e10cSrcweir         ResetableGuard aGuard( m_aLock );
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir         if ( m_bDisposed )
1539*cdf0e10cSrcweir             throw DisposedException();
1540*cdf0e10cSrcweir 
1541*cdf0e10cSrcweir         // preload list of element types on demand
1542*cdf0e10cSrcweir         impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType );
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir         // Look into our default vector/hash_map combination
1545*cdf0e10cSrcweir         UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap;
1546*cdf0e10cSrcweir         UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL );
1547*cdf0e10cSrcweir         if ( pIter != rDefaultHashMap.end() )
1548*cdf0e10cSrcweir         {
1549*cdf0e10cSrcweir             if ( !pIter->second.xSettings.is() )
1550*cdf0e10cSrcweir                 impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second );
1551*cdf0e10cSrcweir             return pIter->second.xSettings;
1552*cdf0e10cSrcweir         }
1553*cdf0e10cSrcweir     }
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir     // Nothing has been found!
1556*cdf0e10cSrcweir     throw NoSuchElementException();
1557*cdf0e10cSrcweir }
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir // XUIConfigurationPersistence
1560*cdf0e10cSrcweir void UIConfigurationManagerImpl::reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1561*cdf0e10cSrcweir {
1562*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir     if ( m_bDisposed )
1565*cdf0e10cSrcweir         throw DisposedException();
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly )
1568*cdf0e10cSrcweir     {
1569*cdf0e10cSrcweir         // Try to access our module sub folder
1570*cdf0e10cSrcweir         ConfigEventNotifyContainer aRemoveNotifyContainer;
1571*cdf0e10cSrcweir         ConfigEventNotifyContainer aReplaceNotifyContainer;
1572*cdf0e10cSrcweir         for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
1573*cdf0e10cSrcweir         {
1574*cdf0e10cSrcweir             try
1575*cdf0e10cSrcweir             {
1576*cdf0e10cSrcweir                 UIElementType& rUserElementType    = m_aUIElements[LAYER_USERDEFINED][i];
1577*cdf0e10cSrcweir                 UIElementType& rDefaultElementType = m_aUIElements[LAYER_DEFAULT][i];
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir                 if ( rUserElementType.bModified )
1580*cdf0e10cSrcweir                     impl_reloadElementTypeData( rUserElementType, rDefaultElementType, aRemoveNotifyContainer, aReplaceNotifyContainer );
1581*cdf0e10cSrcweir             }
1582*cdf0e10cSrcweir             catch ( Exception& )
1583*cdf0e10cSrcweir             {
1584*cdf0e10cSrcweir                 throw IOException();
1585*cdf0e10cSrcweir             }
1586*cdf0e10cSrcweir         }
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir         m_bModified = sal_False;
1589*cdf0e10cSrcweir 
1590*cdf0e10cSrcweir         // Unlock mutex before notify our listeners
1591*cdf0e10cSrcweir         aGuard.unlock();
1592*cdf0e10cSrcweir 
1593*cdf0e10cSrcweir         // Notify our listeners
1594*cdf0e10cSrcweir         ::std::for_each(aRemoveNotifyContainer.begin(),aRemoveNotifyContainer.end(),::boost::bind(&UIConfigurationManagerImpl::implts_notifyContainerListener,this,_1,NotifyOp_Remove));
1595*cdf0e10cSrcweir         ::std::for_each(aReplaceNotifyContainer.begin(),aReplaceNotifyContainer.end(),::boost::bind(&UIConfigurationManagerImpl::implts_notifyContainerListener,this,_1,NotifyOp_Replace));
1596*cdf0e10cSrcweir     }
1597*cdf0e10cSrcweir }
1598*cdf0e10cSrcweir 
1599*cdf0e10cSrcweir void UIConfigurationManagerImpl::store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1600*cdf0e10cSrcweir {
1601*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir     if ( m_bDisposed )
1604*cdf0e10cSrcweir         throw DisposedException();
1605*cdf0e10cSrcweir 
1606*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly )
1607*cdf0e10cSrcweir     {
1608*cdf0e10cSrcweir         // Try to access our module sub folder
1609*cdf0e10cSrcweir         for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
1610*cdf0e10cSrcweir         {
1611*cdf0e10cSrcweir             try
1612*cdf0e10cSrcweir             {
1613*cdf0e10cSrcweir                 UIElementType&        rElementType = m_aUIElements[LAYER_USERDEFINED][i];
1614*cdf0e10cSrcweir                 Reference< XStorage > xStorage( rElementType.xStorage, UNO_QUERY );
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir                 if ( rElementType.bModified && xStorage.is() )
1617*cdf0e10cSrcweir                 {
1618*cdf0e10cSrcweir                     impl_storeElementTypeData( xStorage, rElementType );
1619*cdf0e10cSrcweir                     m_pStorageHandler[i]->commitUserChanges();
1620*cdf0e10cSrcweir                 }
1621*cdf0e10cSrcweir             }
1622*cdf0e10cSrcweir             catch ( Exception& )
1623*cdf0e10cSrcweir             {
1624*cdf0e10cSrcweir                 throw IOException();
1625*cdf0e10cSrcweir             }
1626*cdf0e10cSrcweir         }
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir         m_bModified = false;
1629*cdf0e10cSrcweir     }
1630*cdf0e10cSrcweir }
1631*cdf0e10cSrcweir 
1632*cdf0e10cSrcweir void UIConfigurationManagerImpl::storeToStorage( const Reference< XStorage >& Storage ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1633*cdf0e10cSrcweir {
1634*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1635*cdf0e10cSrcweir 
1636*cdf0e10cSrcweir     if ( m_bDisposed )
1637*cdf0e10cSrcweir         throw DisposedException();
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir     if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly )
1640*cdf0e10cSrcweir     {
1641*cdf0e10cSrcweir         // Try to access our module sub folder
1642*cdf0e10cSrcweir         for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ )
1643*cdf0e10cSrcweir         {
1644*cdf0e10cSrcweir             try
1645*cdf0e10cSrcweir             {
1646*cdf0e10cSrcweir                 Reference< XStorage > xElementTypeStorage( Storage->openStorageElement(
1647*cdf0e10cSrcweir                                                             rtl::OUString::createFromAscii( UIELEMENTTYPENAMES[i] ), ElementModes::READWRITE ));
1648*cdf0e10cSrcweir                 UIElementType&        rElementType = m_aUIElements[LAYER_USERDEFINED][i];
1649*cdf0e10cSrcweir 
1650*cdf0e10cSrcweir                 if ( rElementType.bModified && xElementTypeStorage.is() )
1651*cdf0e10cSrcweir                     impl_storeElementTypeData( xElementTypeStorage, rElementType, false ); // store data to storage, but don't reset modify flag!
1652*cdf0e10cSrcweir             }
1653*cdf0e10cSrcweir             catch ( Exception& )
1654*cdf0e10cSrcweir             {
1655*cdf0e10cSrcweir                 throw IOException();
1656*cdf0e10cSrcweir             }
1657*cdf0e10cSrcweir         }
1658*cdf0e10cSrcweir 
1659*cdf0e10cSrcweir         Reference< XTransactedObject > xTransactedObject( Storage, UNO_QUERY );
1660*cdf0e10cSrcweir 		if ( xTransactedObject.is() )
1661*cdf0e10cSrcweir         	xTransactedObject->commit();
1662*cdf0e10cSrcweir     }
1663*cdf0e10cSrcweir }
1664*cdf0e10cSrcweir 
1665*cdf0e10cSrcweir sal_Bool UIConfigurationManagerImpl::isModified() throw (::com::sun::star::uno::RuntimeException)
1666*cdf0e10cSrcweir {
1667*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1668*cdf0e10cSrcweir 
1669*cdf0e10cSrcweir     return m_bModified;
1670*cdf0e10cSrcweir }
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir sal_Bool UIConfigurationManagerImpl::isReadOnly() throw (::com::sun::star::uno::RuntimeException)
1673*cdf0e10cSrcweir {
1674*cdf0e10cSrcweir     ResetableGuard aGuard( m_aLock );
1675*cdf0e10cSrcweir 
1676*cdf0e10cSrcweir     return m_bReadOnly;
1677*cdf0e10cSrcweir }
1678*cdf0e10cSrcweir 
1679*cdf0e10cSrcweir void UIConfigurationManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp )
1680*cdf0e10cSrcweir {
1681*cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer( ::getCppuType( ( const css::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >*) NULL ) );
1682*cdf0e10cSrcweir     if ( pContainer != NULL )
1683*cdf0e10cSrcweir 	{
1684*cdf0e10cSrcweir         ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1685*cdf0e10cSrcweir         while ( pIterator.hasMoreElements() )
1686*cdf0e10cSrcweir         {
1687*cdf0e10cSrcweir             try
1688*cdf0e10cSrcweir             {
1689*cdf0e10cSrcweir                 switch ( eOp )
1690*cdf0e10cSrcweir                 {
1691*cdf0e10cSrcweir                     case NotifyOp_Replace:
1692*cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementReplaced( aEvent );
1693*cdf0e10cSrcweir                         break;
1694*cdf0e10cSrcweir                     case NotifyOp_Insert:
1695*cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementInserted( aEvent );
1696*cdf0e10cSrcweir                         break;
1697*cdf0e10cSrcweir                     case NotifyOp_Remove:
1698*cdf0e10cSrcweir                         ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementRemoved( aEvent );
1699*cdf0e10cSrcweir                         break;
1700*cdf0e10cSrcweir                 }
1701*cdf0e10cSrcweir             }
1702*cdf0e10cSrcweir             catch( css::uno::RuntimeException& )
1703*cdf0e10cSrcweir             {
1704*cdf0e10cSrcweir                 pIterator.remove();
1705*cdf0e10cSrcweir             }
1706*cdf0e10cSrcweir         }
1707*cdf0e10cSrcweir 	}
1708*cdf0e10cSrcweir }
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir } // namespace framework
1711