1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <unotools/localisationoptions.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
28 #include <rtl/logfile.hxx>
29 #include "itemholder1.hxx"
31 using namespace ::utl
;
32 using namespace ::rtl
;
33 using namespace ::osl
;
34 using namespace ::com::sun::star::uno
;
36 #define ROOTNODE_LOCALISATION OUString("Office.Common/View/Localisation")
37 #define DEFAULT_AUTOMNEMONIC sal_False
38 #define DEFAULT_DIALOGSCALE 0
40 #define PROPERTYNAME_AUTOMNEMONIC OUString("AutoMnemonic")
41 #define PROPERTYNAME_DIALOGSCALE OUString("DialogScale")
43 #define PROPERTYHANDLE_AUTOMNEMONIC 0
44 #define PROPERTYHANDLE_DIALOGSCALE 1
46 #define PROPERTYCOUNT 2
48 class SvtLocalisationOptions_Impl
: public ConfigItem
52 SvtLocalisationOptions_Impl();
53 ~SvtLocalisationOptions_Impl();
55 /*-****************************************************************************************************//**
56 @short called for notify of configmanager
57 @descr These method is called from the ConfigManager before application ends or from the
58 PropertyChangeListener if the sub tree broadcasts changes. You must update your
61 @seealso baseclass ConfigItem
63 @param "seqPropertyNames" is the list of properties which should be updated.
67 *//*-*****************************************************************************************************/
69 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
);
71 /*-****************************************************************************************************//**
72 @short write changes to configuration
73 @descr These method writes the changed values into the sub tree
74 and should always called in our destructor to guarantee consistency of config data.
76 @seealso baseclass ConfigItem
82 *//*-*****************************************************************************************************/
84 virtual void Commit();
86 /*-****************************************************************************************************//**
87 @short access method to get internal values
88 @descr These method give us a chance to regulate acces to ouer internal values.
89 It's not used in the moment - but it's possible for the feature!
97 *//*-*****************************************************************************************************/
99 sal_Bool
IsAutoMnemonic ( ) const ;
100 sal_Int32
GetDialogScale ( ) const ;
104 /*-****************************************************************************************************//**
105 @short return list of key names of ouer configuration management which represent oue module tree
106 @descr These methods return a static const list of key names. We need it to get needed values from our
107 configuration management.
112 @return A list of needed configuration keys is returned.
115 *//*-*****************************************************************************************************/
117 static Sequence
< OUString
> GetPropertyNames();
121 sal_Bool m_bAutoMnemonic
;
122 sal_Int32 m_nDialogScale
;
125 //*****************************************************************************************************************
127 //*****************************************************************************************************************
128 SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()
129 // Init baseclasses first
130 : ConfigItem ( ROOTNODE_LOCALISATION
)
132 , m_bAutoMnemonic ( DEFAULT_AUTOMNEMONIC
)
133 , m_nDialogScale ( DEFAULT_DIALOGSCALE
)
135 // Use our static list of configuration keys to get his values.
136 Sequence
< OUString
> seqNames
= GetPropertyNames ( );
137 Sequence
< Any
> seqValues
= GetProperties ( seqNames
);
139 // Safe impossible cases.
140 // We need values from ALL configuration keys.
141 // Follow assignment use order of values in relation to our list of key names!
142 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nI miss some values of configuration keys!\n" );
144 // Copy values from list in right order to our internal member.
145 sal_Int32 nPropertyCount
= seqValues
.getLength();
146 for( sal_Int32 nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
148 if (!seqValues
[nProperty
].hasValue())
152 case PROPERTYHANDLE_AUTOMNEMONIC
: {
153 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" );
154 seqValues
[nProperty
] >>= m_bAutoMnemonic
;
158 case PROPERTYHANDLE_DIALOGSCALE
: {
159 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_LONG
), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" );
160 seqValues
[nProperty
] >>= m_nDialogScale
;
166 // Enable notification mechanism of ouer baseclass.
167 // We need it to get information about changes outside these class on ouer used configuration keys!
168 EnableNotification( seqNames
);
171 //*****************************************************************************************************************
173 //*****************************************************************************************************************
174 SvtLocalisationOptions_Impl::~SvtLocalisationOptions_Impl()
176 // We must save our current values .. if user forget it!
177 if( IsModified() == sal_True
)
183 //*****************************************************************************************************************
185 //*****************************************************************************************************************
186 void SvtLocalisationOptions_Impl::Notify( const Sequence
< OUString
>& seqPropertyNames
)
188 // Use given list of updated properties to get his values from configuration directly!
189 Sequence
< Any
> seqValues
= GetProperties( seqPropertyNames
);
190 // Safe impossible cases.
191 // We need values from ALL notified configuration keys.
192 DBG_ASSERT( !(seqPropertyNames
.getLength()!=seqValues
.getLength()), "SvtLocalisationOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
193 // Step over list of property names and get right value from coreesponding value list to set it on internal members!
194 sal_Int32 nCount
= seqPropertyNames
.getLength();
195 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
197 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_AUTOMNEMONIC
)
199 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\AutoMnemonic\"?" );
200 seqValues
[nProperty
] >>= m_bAutoMnemonic
;
203 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_DIALOGSCALE
)
205 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_LONG
), "SvtLocalisationOptions_Impl::SvtLocalisationOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Localisation\\DialogScale\"?" );
206 seqValues
[nProperty
] >>= m_nDialogScale
;
208 #if OSL_DEBUG_LEVEL > 1
209 else DBG_ASSERT( sal_False
, "SvtLocalisationOptions_Impl::Notify()\nUnknown property detected ... I can't handle these!\n" );
216 //*****************************************************************************************************************
218 //*****************************************************************************************************************
219 void SvtLocalisationOptions_Impl::Commit()
221 // Get names of supported properties, create a list for values and copy current values to it.
222 Sequence
< OUString
> seqNames
= GetPropertyNames ();
223 sal_Int32 nCount
= seqNames
.getLength();
224 Sequence
< Any
> seqValues ( nCount
);
225 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
229 case PROPERTYHANDLE_AUTOMNEMONIC
: {
230 seqValues
[nProperty
] <<= m_bAutoMnemonic
;
234 case PROPERTYHANDLE_DIALOGSCALE
: {
235 seqValues
[nProperty
] <<= m_nDialogScale
;
240 // Set properties in configuration.
241 PutProperties( seqNames
, seqValues
);
244 //*****************************************************************************************************************
246 //*****************************************************************************************************************
247 sal_Bool
SvtLocalisationOptions_Impl::IsAutoMnemonic() const
249 return m_bAutoMnemonic
;
252 //*****************************************************************************************************************
254 //*****************************************************************************************************************
255 sal_Int32
SvtLocalisationOptions_Impl::GetDialogScale() const
257 return m_nDialogScale
;
260 Sequence
< OUString
> SvtLocalisationOptions_Impl::GetPropertyNames()
262 // Build static list of configuration key names.
263 const OUString aProperties
[] =
265 PROPERTYNAME_AUTOMNEMONIC
,
266 PROPERTYNAME_DIALOGSCALE
,
268 // Initialize return sequence with these list ...
269 Sequence
< OUString
> seqPropertyNames(aProperties
, PROPERTYCOUNT
);
270 // ... and return it.
271 return seqPropertyNames
;
274 //*****************************************************************************************************************
275 // initialize static member
276 // DON'T DO IT IN YOUR HEADER!
277 // see definition for further information
278 //*****************************************************************************************************************
279 SvtLocalisationOptions_Impl
* SvtLocalisationOptions::m_pDataContainer
= NULL
;
280 sal_Int32
SvtLocalisationOptions::m_nRefCount
= 0 ;
282 //*****************************************************************************************************************
284 //*****************************************************************************************************************
285 SvtLocalisationOptions::SvtLocalisationOptions()
287 // Global access, must be guarded (multithreading!).
288 MutexGuard
aGuard( GetOwnStaticMutex() );
289 // Increase ouer refcount ...
291 // ... and initialize ouer data container only if it not already exist!
292 if( m_pDataContainer
== NULL
)
294 RTL_LOGFILE_CONTEXT(aLog
, "unotools ( ??? ) ::SvtLocalisationOptions_Impl::ctor()");
295 m_pDataContainer
= new SvtLocalisationOptions_Impl
;
297 ItemHolder1::holdConfigItem(E_LOCALISATIONOPTIONS
);
301 //*****************************************************************************************************************
303 //*****************************************************************************************************************
304 SvtLocalisationOptions::~SvtLocalisationOptions()
306 // Global access, must be guarded (multithreading!)
307 MutexGuard
aGuard( GetOwnStaticMutex() );
308 // Decrease ouer refcount.
310 // If last instance was deleted ...
311 // we must destroy ouer static data container!
312 if( m_nRefCount
<= 0 )
314 delete m_pDataContainer
;
315 m_pDataContainer
= NULL
;
319 //*****************************************************************************************************************
321 //*****************************************************************************************************************
322 sal_Bool
SvtLocalisationOptions::IsAutoMnemonic() const
324 MutexGuard
aGuard( GetOwnStaticMutex() );
325 return m_pDataContainer
->IsAutoMnemonic();
328 //*****************************************************************************************************************
330 //*****************************************************************************************************************
331 sal_Int32
SvtLocalisationOptions::GetDialogScale() const
333 MutexGuard
aGuard( GetOwnStaticMutex() );
334 return m_pDataContainer
->GetDialogScale();
339 class theLocalisationOptionsMutex
: public rtl::Static
<osl::Mutex
, theLocalisationOptionsMutex
>{};
342 //*****************************************************************************************************************
344 //*****************************************************************************************************************
345 Mutex
& SvtLocalisationOptions::GetOwnStaticMutex()
347 return theLocalisationOptionsMutex::get();
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */