From 11669b9cf970d953d41b8dd2c5ce85d6fa7e31ef Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Fri, 15 Feb 2019 18:34:56 +0100 Subject: MSForms: Introduce a new compatibility flag to enable MS compatible Forms menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * It's a global option not a document level setting (like other compatibility options) so I created a separate section on the GUI for this option on the same tab page. * In the configuration the option is placed under Compatibility/View since the existing Compatibility/FormattingOptions seems related to document formating and not the GUI. * Since it was added with a new configuration root I needed to add also a new ConfigItem derviative class to handle this option. Change-Id: I54668ae9808a1ca3c3b7fe81f2f201720257b3fb Reviewed-on: https://gerrit.libreoffice.org/67902 Tested-by: Jenkins Reviewed-by: Tamás Zolnai --- unotools/Library_utl.mk | 1 + .../source/config/compatibilityviewoptions.cxx | 171 +++++++++++++++++++++ unotools/source/config/itemholder1.cxx | 5 + 3 files changed, 177 insertions(+) create mode 100644 unotools/source/config/compatibilityviewoptions.cxx (limited to 'unotools') diff --git a/unotools/Library_utl.mk b/unotools/Library_utl.mk index 0bfcbad5e383..19fcd7cfce1c 100644 --- a/unotools/Library_utl.mk +++ b/unotools/Library_utl.mk @@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_exception_objects,utl,\ unotools/source/config/bootstrap \ unotools/source/config/cmdoptions \ unotools/source/config/compatibility \ + unotools/source/config/compatibilityviewoptions \ unotools/source/config/configitem \ unotools/source/config/configmgr \ unotools/source/config/confignode \ diff --git a/unotools/source/config/compatibilityviewoptions.cxx b/unotools/source/config/compatibilityviewoptions.cxx new file mode 100644 index 000000000000..52e02446608b --- /dev/null +++ b/unotools/source/config/compatibilityviewoptions.cxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include "itemholder1.hxx" + +#define ROOTNODE_COMPATIBILITY_VIEW "Office.Compatibility/View" + +#define PROPERTYNAME_MSCOMPATIBLEFORMSMENU "MSCompatibleFormsMenu" + +#define PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU 0 + +class SvtCompatibilityViewOptions_Impl : public utl::ConfigItem +{ +private: + bool m_bShowMSCompatibleFormsMenu; + +public: + SvtCompatibilityViewOptions_Impl(); + virtual ~SvtCompatibilityViewOptions_Impl() override; + + /** + @short Called for notify of configmanager. + + This method is called from the ConfigManager before application ends or from the + PropertyChangeListener if the sub tree broadcasts changes. You must update your + internal values. + + @see baseclass ConfigItem + + @param "seqPropertyNames" is the list of properties which should be updated. + */ + virtual void Notify(const css::uno::Sequence& seqPropertyNames) override; + + bool HasMSOCompatibleFormsMenu() const { return m_bShowMSCompatibleFormsMenu; } + void SetMSOCompatibleFormsMenu(bool bSet) + { + bool bModified = (m_bShowMSCompatibleFormsMenu != bSet); + if (bModified) + { + m_bShowMSCompatibleFormsMenu = bSet; + SetModified(); + Commit(); + } + } + +private: + virtual void ImplCommit() override; + + /** + @short Return list of fix key names of our configuration management which represent our module tree. + + This method returns a static const list of key names. We need it to get needed values from our + configuration management. + + @return A list of needed configuration keys is returned. + */ + static css::uno::Sequence const& impl_GetPropertyNames(); +}; + +SvtCompatibilityViewOptions_Impl::SvtCompatibilityViewOptions_Impl() + : ConfigItem(ROOTNODE_COMPATIBILITY_VIEW) + , m_bShowMSCompatibleFormsMenu(false) +{ + // Use our static list of configuration keys to get his values. + css::uno::Sequence seqNames = impl_GetPropertyNames(); + css::uno::Sequence seqValues = GetProperties(seqNames); + assert(seqNames.getLength() == seqValues.getLength()); + + if (seqValues[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU].hasValue()) + { + assert(seqValues[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU].getValueTypeClass() + == css::uno::TypeClass_BOOLEAN); + seqValues[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU] >>= m_bShowMSCompatibleFormsMenu; + } + + EnableNotification(seqNames); +} + +SvtCompatibilityViewOptions_Impl::~SvtCompatibilityViewOptions_Impl() +{ + assert(!IsModified()); // should have been committed +} + +void SvtCompatibilityViewOptions_Impl::Notify(const css::uno::Sequence& seqPropertyNames) +{ + // Use given list of updated properties to get his values from configuration directly! + css::uno::Sequence seqValues = GetProperties(seqPropertyNames); + assert(seqPropertyNames.getLength() == seqValues.getLength()); + + for (sal_Int32 nProperty = 0; nProperty < seqPropertyNames.getLength(); ++nProperty) + { + if (seqPropertyNames[nProperty] == PROPERTYNAME_MSCOMPATIBLEFORMSMENU) + { + assert(seqValues[nProperty].getValueTypeClass() == css::uno::TypeClass_BOOLEAN); + seqValues[nProperty] >>= m_bShowMSCompatibleFormsMenu; + } + } +} + +void SvtCompatibilityViewOptions_Impl::ImplCommit() +{ + // Get names of supported properties, create a list for values and copy current values to it. + css::uno::Sequence seqNames = impl_GetPropertyNames(); + css::uno::Sequence seqValues(seqNames.getLength()); + + seqValues[PROPERTYHANDLE_MSCOMPATIBLEFORMSMENU] <<= m_bShowMSCompatibleFormsMenu; + + // Set properties in configuration. + PutProperties(seqNames, seqValues); +} + +css::uno::Sequence const& SvtCompatibilityViewOptions_Impl::impl_GetPropertyNames() +{ + static const css::uno::Sequence seqPropertyNames{ OUString( + PROPERTYNAME_MSCOMPATIBLEFORMSMENU) }; + return seqPropertyNames; +} + +namespace +{ +std::weak_ptr theOptions; +} + +SvtCompatibilityViewOptions::SvtCompatibilityViewOptions() +{ + // Global access, must be guarded (multithreading!). + osl::MutexGuard aGuard(GetOwnStaticMutex()); + + m_pImpl = theOptions.lock(); + if (!m_pImpl) + { + m_pImpl = std::make_shared(); + theOptions = m_pImpl; + ItemHolder1::holdConfigItem(EItem::CompatibilityView); + } +} + +SvtCompatibilityViewOptions::~SvtCompatibilityViewOptions() +{ + // Global access, must be guarded (multithreading!) + osl::MutexGuard aGuard(GetOwnStaticMutex()); + m_pImpl.reset(); +} + +bool SvtCompatibilityViewOptions::HasMSOCompatibleFormsMenu() const +{ + return m_pImpl->HasMSOCompatibleFormsMenu(); +} + +void SvtCompatibilityViewOptions::SetMSOCompatibleFormsMenu(bool bSet) +{ + m_pImpl->SetMSOCompatibleFormsMenu(bSet); +} + +osl::Mutex& SvtCompatibilityViewOptions::GetOwnStaticMutex() +{ + static osl::Mutex ourMutex; + + return ourMutex; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/unotools/source/config/itemholder1.cxx b/unotools/source/config/itemholder1.cxx index c0444dc9f1ec..70d1880ca6ca 100644 --- a/unotools/source/config/itemholder1.cxx +++ b/unotools/source/config/itemholder1.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -130,6 +131,10 @@ void ItemHolder1::impl_newItem(TItemInfo& rItem) rItem.pItem.reset( new SvtCompatibilityOptions() ); break; + case EItem::CompatibilityView : + rItem.pItem.reset( new SvtCompatibilityViewOptions() ); + break; + case EItem::DefaultOptions : rItem.pItem.reset( new SvtDefaultOptions() ); break; -- cgit