fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uiconfiguration / globalsettings.cxx
blob6ce4811593215c6329c7d7f30a741c1470d33b26
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "uiconfiguration/globalsettings.hxx"
21 #include "services.h"
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/configuration/theDefaultProvider.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <com/sun/star/lang/XComponent.hpp>
30 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <rtl/ustrbuf.hxx>
33 #include <rtl/instance.hxx>
34 #include <cppuhelper/implbase2.hxx>
36 // Defines
38 using namespace ::com::sun::star;
40 // Namespace
42 static const char GLOBALSETTINGS_ROOT_ACCESS[] = "/org.openoffice.Office.UI.GlobalSettings/Toolbars";
44 static const char GLOBALSETTINGS_NODEREF_STATES[] = "States";
45 static const char GLOBALSETTINGS_PROPERTY_LOCKED[] = "Locked";
46 static const char GLOBALSETTINGS_PROPERTY_DOCKED[] = "Docked";
47 static const char GLOBALSETTINGS_PROPERTY_STATESENABLED[] = "StatesEnabled";
49 namespace framework
52 // Configuration access class for WindowState supplier implementation
54 class GlobalSettings_Access : public ::cppu::WeakImplHelper2<
55 ::com::sun::star::lang::XComponent,
56 ::com::sun::star::lang::XEventListener>
58 public:
59 GlobalSettings_Access( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
60 virtual ~GlobalSettings_Access();
62 // XComponent
63 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
67 // XEventListener
68 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
70 // settings access
71 bool HasStatesInfo( GlobalSettings::UIElementType eElementType );
72 bool GetStateInfo( GlobalSettings::UIElementType eElementType, GlobalSettings::StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue );
74 private:
75 bool impl_initConfigAccess();
77 osl::Mutex m_mutex;
78 bool m_bDisposed : 1,
79 m_bConfigRead : 1;
80 OUString m_aNodeRefStates;
81 OUString m_aPropStatesEnabled;
82 OUString m_aPropLocked;
83 OUString m_aPropDocked;
84 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xConfigAccess;
85 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
88 GlobalSettings_Access::GlobalSettings_Access( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) :
89 m_bDisposed( false ),
90 m_bConfigRead( false ),
91 m_aNodeRefStates( GLOBALSETTINGS_NODEREF_STATES ),
92 m_aPropStatesEnabled( GLOBALSETTINGS_PROPERTY_STATESENABLED ),
93 m_aPropLocked( GLOBALSETTINGS_PROPERTY_LOCKED ),
94 m_aPropDocked( GLOBALSETTINGS_PROPERTY_DOCKED ),
95 m_xContext( rxContext )
99 GlobalSettings_Access::~GlobalSettings_Access()
103 // XComponent
104 void SAL_CALL GlobalSettings_Access::dispose()
105 throw ( css::uno::RuntimeException, std::exception )
107 osl::MutexGuard g(m_mutex);
108 m_xConfigAccess.clear();
109 m_bDisposed = true;
112 void SAL_CALL GlobalSettings_Access::addEventListener( const css::uno::Reference< css::lang::XEventListener >& )
113 throw (css::uno::RuntimeException, std::exception)
117 void SAL_CALL GlobalSettings_Access::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& )
118 throw (css::uno::RuntimeException, std::exception)
122 // XEventListener
123 void SAL_CALL GlobalSettings_Access::disposing( const css::lang::EventObject& )
124 throw (css::uno::RuntimeException, std::exception)
126 osl::MutexGuard g(m_mutex);
127 m_xConfigAccess.clear();
130 // settings access
131 bool GlobalSettings_Access::HasStatesInfo( GlobalSettings::UIElementType eElementType )
133 osl::MutexGuard g(m_mutex);
134 if ( eElementType == GlobalSettings::UIELEMENT_TYPE_DOCKWINDOW )
135 return false;
136 else if ( eElementType == GlobalSettings::UIELEMENT_TYPE_STATUSBAR )
137 return false;
139 if ( m_bDisposed )
140 return false;
142 if ( !m_bConfigRead )
144 m_bConfigRead = true;
145 impl_initConfigAccess();
148 if ( m_xConfigAccess.is() )
152 css::uno::Any a;
153 bool bValue;
154 a = m_xConfigAccess->getByName( m_aPropStatesEnabled );
155 if ( a >>= bValue )
156 return bValue;
158 catch ( const css::container::NoSuchElementException& )
161 catch ( const css::uno::Exception& )
166 return false;
169 bool GlobalSettings_Access::GetStateInfo( GlobalSettings::UIElementType eElementType, GlobalSettings::StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue )
171 osl::MutexGuard g(m_mutex);
172 if ( eElementType == GlobalSettings::UIELEMENT_TYPE_DOCKWINDOW )
173 return false;
174 else if ( eElementType == GlobalSettings::UIELEMENT_TYPE_STATUSBAR )
175 return false;
177 if ( m_bDisposed )
178 return false;
180 if ( !m_bConfigRead )
182 m_bConfigRead = true;
183 impl_initConfigAccess();
186 if ( m_xConfigAccess.is() )
190 css::uno::Any a;
191 a = m_xConfigAccess->getByName( m_aNodeRefStates );
192 css::uno::Reference< css::container::XNameAccess > xNameAccess;
193 if ( a >>= xNameAccess )
195 if ( eStateInfo == GlobalSettings::STATEINFO_LOCKED )
196 a = xNameAccess->getByName( m_aPropLocked );
197 else if ( eStateInfo == GlobalSettings::STATEINFO_DOCKED )
198 a = xNameAccess->getByName( m_aPropDocked );
200 aValue = a;
201 return true;
204 catch ( const css::container::NoSuchElementException& )
207 catch ( const css::uno::Exception& )
212 return false;
215 bool GlobalSettings_Access::impl_initConfigAccess()
217 css::uno::Sequence< css::uno::Any > aArgs( 2 );
218 css::beans::PropertyValue aPropValue;
222 if ( m_xContext.is() )
224 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider =
225 css::configuration::theDefaultProvider::get( m_xContext );
227 aPropValue.Name = "nodepath";
228 aPropValue.Value = css::uno::makeAny( OUString( GLOBALSETTINGS_ROOT_ACCESS ));
229 aArgs[0] = css::uno::makeAny( aPropValue );
230 aPropValue.Name = "lazywrite";
231 aPropValue.Value = css::uno::makeAny( sal_True );
232 aArgs[1] = css::uno::makeAny( aPropValue );
234 m_xConfigAccess = css::uno::Reference< css::container::XNameAccess >(
235 xConfigProvider->createInstanceWithArguments(
236 SERVICENAME_CFGREADACCESS, aArgs ),
237 css::uno::UNO_QUERY );
239 css::uno::Reference< css::lang::XComponent >(
240 xConfigProvider, css::uno::UNO_QUERY_THROW )->addEventListener(
241 css::uno::Reference< css::lang::XEventListener >(
242 static_cast< cppu::OWeakObject* >( this ),
243 css::uno::UNO_QUERY ));
246 return m_xConfigAccess.is();
248 catch ( const css::lang::WrappedTargetException& )
251 catch ( const css::uno::Exception& )
255 return false;
258 // global class
260 struct mutexGlobalSettings : public rtl::Static< osl::Mutex, mutexGlobalSettings > {};
261 static GlobalSettings_Access* pStaticSettings = 0;
263 static GlobalSettings_Access* GetGlobalSettings( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext )
265 osl::MutexGuard aGuard(mutexGlobalSettings::get());
266 if ( !pStaticSettings )
267 pStaticSettings = new GlobalSettings_Access( rxContext );
268 return pStaticSettings;
271 GlobalSettings::GlobalSettings( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) :
272 m_xContext( rxContext )
276 GlobalSettings::~GlobalSettings()
280 // settings access
281 bool GlobalSettings::HasStatesInfo( UIElementType eElementType )
283 GlobalSettings_Access* pSettings( GetGlobalSettings( m_xContext ));
285 if ( pSettings )
286 return pSettings->HasStatesInfo( eElementType );
287 else
288 return false;
291 bool GlobalSettings::GetStateInfo( UIElementType eElementType, StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue )
293 GlobalSettings_Access* pSettings( GetGlobalSettings( m_xContext ));
295 if ( pSettings )
296 return pSettings->GetStateInfo( eElementType, eStateInfo, aValue );
297 else
298 return false;
301 } // namespace framework
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */