nss: upgrade to release 3.73
[LibreOffice.git] / svtools / source / config / menuoptions.cxx
blob49d2128eb0a7ab013eae38d5a3c8b7c13c5d3653
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 <svtools/menuoptions.hxx>
21 #include <unotools/configitem.hxx>
22 #include <tools/debug.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
28 #include "itemholder2.hxx"
30 // namespaces
32 using namespace ::utl ;
33 using namespace ::osl ;
34 using namespace ::com::sun::star::uno ;
36 #define ROOTNODE_MENU "Office.Common/View/Menu"
37 #define DEFAULT_DONTHIDEDISABLEDENTRIES false
38 #define DEFAULT_FOLLOWMOUSE true
39 #define DEFAULT_MENUICONS TRISTATE_INDET
40 #define DEFAULT_CONTEXTMENUSHORTCUTS TRISTATE_INDET
42 #define PROPERTYNAME_DONTHIDEDISABLEDENTRIES "DontHideDisabledEntry"
43 #define PROPERTYNAME_FOLLOWMOUSE "FollowMouse"
44 #define PROPERTYNAME_SHOWICONSINMENUES "ShowIconsInMenues"
45 #define PROPERTYNAME_SYSTEMICONSINMENUES "IsSystemIconsInMenus"
46 #define PROPERTYNAME_SHORTCUTSINCONTEXMENU "ShortcutsInContextMenus"
48 #define PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES 0
49 #define PROPERTYHANDLE_FOLLOWMOUSE 1
50 #define PROPERTYHANDLE_SHOWICONSINMENUES 2
51 #define PROPERTYHANDLE_SYSTEMICONSINMENUES 3
52 #define PROPERTYHANDLE_SHORTCUTSINCONTEXMENU 4
54 // private declarations!
56 class SvtMenuOptions_Impl : public ConfigItem
59 // private member
61 private:
62 bool m_bDontHideDisabledEntries ; /// cache "DontHideDisabledEntries" of Menu section
63 bool m_bFollowMouse ; /// cache "FollowMouse" of Menu section
64 TriState m_eMenuIcons ; /// cache "MenuIcons" of Menu section
65 TriState m_eContextMenuShortcuts ; /// cache "ShortcutsInContextMenus" of Menu section
67 // public methods
69 public:
71 // constructor / destructor
73 SvtMenuOptions_Impl();
74 virtual ~SvtMenuOptions_Impl() override;
76 // override methods of baseclass
78 /*-****************************************************************************************************
79 @short called for notify of configmanager
80 @descr This method is called from the ConfigManager before application ends or from the
81 PropertyChangeListener if the sub tree broadcasts changes. You must update your
82 internal values.
84 @seealso baseclass ConfigItem
86 @param "seqPropertyNames" is the list of properties which should be updated.
87 *//*-*****************************************************************************************************/
89 virtual void Notify( const Sequence< OUString >& seqPropertyNames ) override;
91 // public interface
93 /*-****************************************************************************************************
94 @short access method to get internal values
95 @descr These methods give us a chance to regulate access to our internal values.
96 It's not used at the moment - but it's possible for the future!
97 *//*-*****************************************************************************************************/
99 bool IsEntryHidingEnabled() const
100 { return m_bDontHideDisabledEntries; }
102 TriState GetMenuIconsState() const
103 { return m_eMenuIcons; }
105 void SetMenuIconsState(TriState eState)
107 m_eMenuIcons = eState;
108 SetModified();
109 // tdf#93451: don't Commit() here, it's too early
112 TriState GetContextMenuShortcuts() const
113 { return m_eContextMenuShortcuts; }
115 void SetContextMenuShortcuts(TriState eState)
117 m_eContextMenuShortcuts = eState;
118 SetModified();
119 Commit();
122 // private methods
124 private:
126 virtual void ImplCommit() override;
128 /*-****************************************************************************************************
129 @short return list of fix key names of our configuration management which represent our module tree
130 @descr This method returns a static const list of key names. We need it to get needed values from our
131 configuration management.
132 @return A list of needed configuration keys is returned.
133 *//*-*****************************************************************************************************/
135 static Sequence< OUString > const & impl_GetPropertyNames();
138 // constructor
140 SvtMenuOptions_Impl::SvtMenuOptions_Impl()
141 // Init baseclasses first
142 : ConfigItem ( ROOTNODE_MENU )
143 // Init member then.
144 , m_bDontHideDisabledEntries ( DEFAULT_DONTHIDEDISABLEDENTRIES )
145 , m_bFollowMouse ( DEFAULT_FOLLOWMOUSE )
146 , m_eMenuIcons ( DEFAULT_MENUICONS )
147 , m_eContextMenuShortcuts ( DEFAULT_CONTEXTMENUSHORTCUTS )
149 // Use our static list of configuration keys to get his values.
150 Sequence< OUString > seqNames = impl_GetPropertyNames();
151 Sequence< Any > seqValues = GetProperties( seqNames ) ;
153 // Safe impossible cases.
154 // We need values from ALL configuration keys.
155 // Follow assignment use order of values in relation to our list of key names!
156 DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nI miss some values of configuration keys!\n" );
158 bool bMenuIcons = true;
159 bool bSystemMenuIcons = true;
160 if (m_eMenuIcons == TRISTATE_INDET)
161 bMenuIcons = Application::GetSettings().GetStyleSettings().GetPreferredUseImagesInMenus();
162 else
164 bSystemMenuIcons = false;
165 bMenuIcons = m_eMenuIcons != TRISTATE_FALSE;
168 // Copy values from list in right order to our internal member.
169 sal_Int32 nPropertyCount = seqValues.getLength() ;
170 sal_Int32 nProperty = 0 ;
171 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
173 // Safe impossible cases.
174 // Check any for valid value.
175 DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nInvalid property value for property detected!\n" );
177 if (!seqValues[nProperty].hasValue())
178 continue;
180 switch( nProperty )
182 case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES : {
183 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
184 seqValues[nProperty] >>= m_bDontHideDisabledEntries;
186 break;
188 case PROPERTYHANDLE_FOLLOWMOUSE : {
189 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
190 seqValues[nProperty] >>= m_bFollowMouse;
192 break;
193 case PROPERTYHANDLE_SHOWICONSINMENUES : {
194 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
195 seqValues[nProperty] >>= bMenuIcons;
197 break;
198 case PROPERTYHANDLE_SYSTEMICONSINMENUES : {
199 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
200 seqValues[nProperty] >>= bSystemMenuIcons;
202 break;
203 case PROPERTYHANDLE_SHORTCUTSINCONTEXMENU : {
204 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_SHORT), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShortcutsInContextMenus\"?" );
205 sal_Int16 nContextMenuShortcuts;
206 if ( seqValues[nProperty] >>= nContextMenuShortcuts )
207 m_eContextMenuShortcuts = static_cast<TriState>(nContextMenuShortcuts);
209 break;
213 m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons);
215 EnableNotification( seqNames );
218 // destructor
220 SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
222 assert(!IsModified()); // should have been committed
225 // public method
227 void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
229 // Use given list of updated properties to get his values from configuration directly!
230 Sequence< Any > seqValues = GetProperties( seqPropertyNames );
231 // Safe impossible cases.
232 // We need values from ALL notified configuration keys.
233 DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
235 bool bMenuSettingsChanged = false;
236 bool bMenuIcons = true;
237 bool bSystemMenuIcons = true;
238 if (m_eMenuIcons == TRISTATE_INDET)
239 bMenuIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
240 else
242 bSystemMenuIcons = false;
243 bMenuIcons = m_eMenuIcons != TRISTATE_FALSE;
246 // Step over list of property names and get right value from corresponding value list to set it on internal members!
247 sal_Int32 nCount = seqPropertyNames.getLength();
248 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
250 if( seqPropertyNames[nProperty] == PROPERTYNAME_DONTHIDEDISABLEDENTRIES )
252 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
253 seqValues[nProperty] >>= m_bDontHideDisabledEntries;
255 else if( seqPropertyNames[nProperty] == PROPERTYNAME_FOLLOWMOUSE )
257 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
258 seqValues[nProperty] >>= m_bFollowMouse;
260 else if( seqPropertyNames[nProperty] == PROPERTYNAME_SHOWICONSINMENUES )
262 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
263 bMenuSettingsChanged |= seqValues[nProperty] >>= bMenuIcons;
265 else if( seqPropertyNames[nProperty] == PROPERTYNAME_SYSTEMICONSINMENUES )
267 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
268 bMenuSettingsChanged |= seqValues[nProperty] >>= bSystemMenuIcons;
270 else if( seqPropertyNames[nProperty] == PROPERTYNAME_SHORTCUTSINCONTEXMENU )
272 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_SHORT), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShortcutsInContextMenus\"?" );
273 sal_Int16 nContextMenuShortcuts;
274 if ( seqValues[nProperty] >>= nContextMenuShortcuts )
275 m_eContextMenuShortcuts = static_cast<TriState>(nContextMenuShortcuts);
277 else assert( false && "SvtMenuOptions_Impl::Notify()\nUnknown property detected ... I can't handle these!" );
280 if ( bMenuSettingsChanged )
281 m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons);
284 // public method
286 void SvtMenuOptions_Impl::ImplCommit()
288 // Get names of supported properties, create a list for values and copy current values to it.
289 Sequence< OUString > seqNames = impl_GetPropertyNames();
290 sal_Int32 nCount = seqNames.getLength();
291 Sequence< Any > seqValues ( nCount );
292 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
294 switch( nProperty )
296 case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES : {
297 seqValues[nProperty] <<= m_bDontHideDisabledEntries;
299 break;
301 case PROPERTYHANDLE_FOLLOWMOUSE : {
302 seqValues[nProperty] <<= m_bFollowMouse;
304 break;
305 //Output cache of current setting as possibly modified by System Theme for older version
306 case PROPERTYHANDLE_SHOWICONSINMENUES : {
307 bool bValue = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
308 seqValues[nProperty] <<= bValue;
310 break;
311 case PROPERTYHANDLE_SYSTEMICONSINMENUES : {
312 bool bValue = m_eMenuIcons == TRISTATE_INDET;
313 seqValues[nProperty] <<= bValue;
315 break;
316 case PROPERTYHANDLE_SHORTCUTSINCONTEXMENU : {
317 seqValues[nProperty] <<= static_cast<sal_Int16>(m_eContextMenuShortcuts);
319 break;
322 // Set properties in configuration.
323 PutProperties( seqNames, seqValues );
326 // private method
328 Sequence< OUString > const & SvtMenuOptions_Impl::impl_GetPropertyNames()
330 static const Sequence<OUString> seqPropertyNames {
331 OUString(PROPERTYNAME_DONTHIDEDISABLEDENTRIES) ,
332 OUString(PROPERTYNAME_FOLLOWMOUSE) ,
333 OUString(PROPERTYNAME_SHOWICONSINMENUES) ,
334 OUString(PROPERTYNAME_SYSTEMICONSINMENUES) ,
335 OUString(PROPERTYNAME_SHORTCUTSINCONTEXMENU)
337 return seqPropertyNames;
340 namespace {
342 std::weak_ptr<SvtMenuOptions_Impl> g_pMenuOptions;
346 SvtMenuOptions::SvtMenuOptions()
348 // Global access, must be guarded (multithreading!).
349 MutexGuard aGuard( GetOwnStaticMutex() );
351 m_pImpl = g_pMenuOptions.lock();
352 if( !m_pImpl )
354 m_pImpl = std::make_shared<SvtMenuOptions_Impl>();
355 g_pMenuOptions = m_pImpl;
356 svtools::ItemHolder2::holdConfigItem(EItem::MenuOptions);
360 SvtMenuOptions::~SvtMenuOptions()
362 // Global access, must be guarded (multithreading!)
363 MutexGuard aGuard( GetOwnStaticMutex() );
365 m_pImpl.reset();
368 // public method
370 bool SvtMenuOptions::IsEntryHidingEnabled() const
372 MutexGuard aGuard( GetOwnStaticMutex() );
373 return m_pImpl->IsEntryHidingEnabled();
376 // public method
378 TriState SvtMenuOptions::GetMenuIconsState() const
380 MutexGuard aGuard( GetOwnStaticMutex() );
381 return m_pImpl->GetMenuIconsState();
384 // public method
386 void SvtMenuOptions::SetMenuIconsState(TriState eState)
388 MutexGuard aGuard( GetOwnStaticMutex() );
389 m_pImpl->SetMenuIconsState(eState);
392 TriState SvtMenuOptions::GetContextMenuShortcuts() const
394 MutexGuard aGuard( GetOwnStaticMutex() );
395 return m_pImpl->GetContextMenuShortcuts();
398 void SvtMenuOptions::SetContextMenuShortcuts(TriState eState)
400 MutexGuard aGuard( GetOwnStaticMutex() );
401 m_pImpl->SetContextMenuShortcuts(eState);
404 // private method
406 Mutex& SvtMenuOptions::GetOwnStaticMutex()
408 static Mutex ourMutex;
410 return ourMutex;
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */