1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <unotools/compatibilityviewoptions.hxx>
11 #include <unotools/configitem.hxx>
12 #include "itemholder1.hxx"
14 #define ROOTNODE_COMPATIBILITY_VIEW "Office.Compatibility/View"
16 #define PROPERTYNAME_MSCOMPATIBLEFORMSMENU "MSCompatibleFormsMenu"
18 #define PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU 0
20 class SvtCompatibilityViewOptions_Impl
: public utl::ConfigItem
23 bool m_bShowMSCompatibleFormsMenu
;
26 SvtCompatibilityViewOptions_Impl();
27 virtual ~SvtCompatibilityViewOptions_Impl() override
;
30 @short Called for notify of configmanager.
32 This method is called from the ConfigManager before application ends or from the
33 PropertyChangeListener if the sub tree broadcasts changes. You must update your
36 @see baseclass ConfigItem
38 @param "seqPropertyNames" is the list of properties which should be updated.
40 virtual void Notify(const css::uno::Sequence
<OUString
>& seqPropertyNames
) override
;
42 bool HasMSOCompatibleFormsMenu() const { return m_bShowMSCompatibleFormsMenu
; }
43 void SetMSOCompatibleFormsMenu(bool bSet
)
45 bool bModified
= (m_bShowMSCompatibleFormsMenu
!= bSet
);
48 m_bShowMSCompatibleFormsMenu
= bSet
;
55 virtual void ImplCommit() override
;
58 @short Return list of fix key names of our configuration management which represent our module tree.
60 This method returns a static const list of key names. We need it to get needed values from our
61 configuration management.
63 @return A list of needed configuration keys is returned.
65 static css::uno::Sequence
<OUString
> const& impl_GetPropertyNames();
68 SvtCompatibilityViewOptions_Impl::SvtCompatibilityViewOptions_Impl()
69 : ConfigItem(ROOTNODE_COMPATIBILITY_VIEW
)
70 , m_bShowMSCompatibleFormsMenu(false)
72 // Use our static list of configuration keys to get his values.
73 css::uno::Sequence
<OUString
> seqNames
= impl_GetPropertyNames();
74 css::uno::Sequence
<css::uno::Any
> seqValues
= GetProperties(seqNames
);
75 assert(seqNames
.getLength() == seqValues
.getLength());
77 if (seqValues
[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU
].hasValue())
79 assert(seqValues
[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU
].getValueTypeClass()
80 == css::uno::TypeClass_BOOLEAN
);
81 seqValues
[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU
] >>= m_bShowMSCompatibleFormsMenu
;
84 EnableNotification(seqNames
);
87 SvtCompatibilityViewOptions_Impl::~SvtCompatibilityViewOptions_Impl()
89 assert(!IsModified()); // should have been committed
92 void SvtCompatibilityViewOptions_Impl::Notify(const css::uno::Sequence
<OUString
>& seqPropertyNames
)
94 // Use given list of updated properties to get his values from configuration directly!
95 css::uno::Sequence
<css::uno::Any
> seqValues
= GetProperties(seqPropertyNames
);
96 assert(seqPropertyNames
.getLength() == seqValues
.getLength());
98 for (sal_Int32 nProperty
= 0; nProperty
< seqPropertyNames
.getLength(); ++nProperty
)
100 if (seqPropertyNames
[nProperty
] == PROPERTYNAME_MSCOMPATIBLEFORMSMENU
)
102 assert(seqValues
[nProperty
].getValueTypeClass() == css::uno::TypeClass_BOOLEAN
);
103 seqValues
[nProperty
] >>= m_bShowMSCompatibleFormsMenu
;
108 void SvtCompatibilityViewOptions_Impl::ImplCommit()
110 // Get names of supported properties, create a list for values and copy current values to it.
111 css::uno::Sequence
<OUString
> seqNames
= impl_GetPropertyNames();
112 css::uno::Sequence
<css::uno::Any
> seqValues(seqNames
.getLength());
114 seqValues
[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU
] <<= m_bShowMSCompatibleFormsMenu
;
116 // Set properties in configuration.
117 PutProperties(seqNames
, seqValues
);
120 css::uno::Sequence
<OUString
> const& SvtCompatibilityViewOptions_Impl::impl_GetPropertyNames()
122 static const css::uno::Sequence
<OUString
> seqPropertyNames
{ OUString(
123 PROPERTYNAME_MSCOMPATIBLEFORMSMENU
) };
124 return seqPropertyNames
;
129 std::weak_ptr
<SvtCompatibilityViewOptions_Impl
> theOptions
;
132 SvtCompatibilityViewOptions::SvtCompatibilityViewOptions()
134 // Global access, must be guarded (multithreading!).
135 osl::MutexGuard
aGuard(GetOwnStaticMutex());
137 m_pImpl
= theOptions
.lock();
140 m_pImpl
= std::make_shared
<SvtCompatibilityViewOptions_Impl
>();
141 theOptions
= m_pImpl
;
142 ItemHolder1::holdConfigItem(EItem::CompatibilityView
);
146 SvtCompatibilityViewOptions::~SvtCompatibilityViewOptions()
148 // Global access, must be guarded (multithreading!)
149 osl::MutexGuard
aGuard(GetOwnStaticMutex());
153 bool SvtCompatibilityViewOptions::HasMSOCompatibleFormsMenu() const
155 return m_pImpl
->HasMSOCompatibleFormsMenu();
158 void SvtCompatibilityViewOptions::SetMSOCompatibleFormsMenu(bool bSet
)
160 m_pImpl
->SetMSOCompatibleFormsMenu(bSet
);
163 osl::Mutex
& SvtCompatibilityViewOptions::GetOwnStaticMutex()
165 static osl::Mutex ourMutex
;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */