include/unotools/compatibility.hxx       |   55 ++++++++++++++++++++++++++++
 sw/source/ui/config/optcomp.cxx          |   18 ++++++++-
 unotools/source/config/compatibility.cxx |   60 +++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)

New commits:
commit 35f59457ff434b7b97cad6ce1dbef6ff07f7bc96
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Thu Nov 16 17:03:39 2023 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Fri Nov 17 18:55:22 2023 +0100

    tdf#158135 - UI: Part 30 - Unify lockdown behavior of Options dialog
    
    for Writer - Compatibility Page.
    
    Change-Id: Id9ad445b451b332314f72f54e183730097584a74
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159513
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/include/unotools/compatibility.hxx 
b/include/unotools/compatibility.hxx
index 620d3c1c3fa4..9c2acefcf1d7 100644
--- a/include/unotools/compatibility.hxx
+++ b/include/unotools/compatibility.hxx
@@ -23,6 +23,7 @@
 #include <unotools/options.hxx>
 #include <unotools/unotoolsdllapi.h>
 #include <rtl/ustring.hxx>
+#include <map>
 #include <memory>
 #include <vector>
 
@@ -131,8 +132,50 @@ class SvtCompatibilityEntry
             setValue(rIdx, css::uno::Any(rValue));
         }
 
+        bool getPropertyReadOnly(const Index rIdx) const
+        {
+            if (static_cast<size_t>(rIdx) < getElementCount())
+            {
+                return m_aPropertyReadOnly.at(static_cast<int>(rIdx));
+            }
+            else
+            {
+                /* Wrong index. */
+                assert(false);
+                return false;
+            }
+        }
+
+        void setPropertyReadOnly(const Index rIdx, const bool bReadOnly)
+        {
+            if (static_cast<size_t>(rIdx) < getElementCount())
+            {
+                m_aPropertyReadOnly.insert({ static_cast<int>(rIdx), bReadOnly 
});
+            }
+            else
+            {
+                /* Wrong index. */
+                assert(false);
+            }
+        }
+
+        bool haveReadOnlyProperty() const
+        {
+            bool bRet = false;
+            for (const auto& pair : m_aPropertyReadOnly)
+            {
+                if (pair.second == true)
+                {
+                    bRet = true;
+                    break;
+                }
+            }
+            return bRet;
+        }
+
     private:
         std::vector<css::uno::Any> m_aPropertyValue;
+        std::map<int, bool> m_aPropertyReadOnly;
 };
 
 
/*-************************************************************************************************************
@@ -183,6 +226,18 @@ class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions final : 
public utl::detail::Opt
         
*//*-*****************************************************************************************************/
         std::vector< SvtCompatibilityEntry > GetList() const;
 
+        
/*-****************************************************************************************************
+            @short      return property/option is readonly or not
+            @descr      Call it to get the readonly status of default entry of
+                        compatibility options.
+            @return     Return true if the compatibility option is true, 
otherwise false.
+
+            @onerror    We return false.
+        
*//*-*****************************************************************************************************/
+        bool GetPropertyReadOnly( SvtCompatibilityEntry::Index rIdx ) const;
+        bool GetDefaultPropertyReadOnly( SvtCompatibilityEntry::Index rIdx ) 
const;
+        bool HaveDefaultReadOnlyProperty() const;
+
     private:
         std::shared_ptr<SvtCompatibilityOptions_Impl> m_pImpl;
 
diff --git a/sw/source/ui/config/optcomp.cxx b/sw/source/ui/config/optcomp.cxx
index a1ea231d305c..1393b2864d95 100644
--- a/sw/source/ui/config/optcomp.cxx
+++ b/sw/source/ui/config/optcomp.cxx
@@ -216,7 +216,7 @@ void SwCompatibilityOptPage::InitControls( const 
SfxItemSet& rSet )
             rEntry.getValue<bool>( SvtCompatibilityEntry::Index::NoExtLeading 
),
             rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::UseLineSpacing ),
             rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::AddTableSpacing ),
-            
rEntry.getValue<bool>(SvtCompatibilityEntry::Index::AddTableLineSpacing),
+            rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::AddTableLineSpacing),
             rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::UseObjectPositioning ),
             rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::UseOurTextWrapping ),
             rEntry.getValue<bool>( 
SvtCompatibilityEntry::Index::ConsiderWrappingStyle ),
@@ -277,9 +277,11 @@ IMPL_LINK_NOARG(SwCompatibilityOptPage, UseAsDefaultHdl, 
weld::Button&, void)
 void SwCompatibilityOptPage::SetCurrentOptions( sal_uInt32 nOptions )
 {
     const int nCount = m_xOptionsLB->n_children();
+    const OUString aOptionsName = m_xFormattingLB->get_active_text();
     OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry 
overflow" );
     for (int i = 0; i < nCount; ++i)
     {
+        bool bReadOnly = false;
         bool bChecked = ( ( nOptions & 0x00000001 ) == 0x00000001 );
         TriState value = bChecked ? TRISTATE_TRUE : TRISTATE_FALSE;
         if (i == int(SvtCompatibilityEntry::Index::AddTableSpacing) - 2)
@@ -292,8 +294,22 @@ void SwCompatibilityOptPage::SetCurrentOptions( sal_uInt32 
nOptions )
             }
         }
         m_xOptionsLB->set_toggle(i, value);
+
+        int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */
+        if (aOptionsName.isEmpty() || aOptionsName == 
SvtCompatibilityEntry::DEFAULT_ENTRY_NAME)
+        {
+            bReadOnly = 
m_aConfigItem.GetDefaultPropertyReadOnly(SvtCompatibilityEntry::Index(nCoptIdx));
+        }
+        else
+        {
+            bReadOnly = 
m_aConfigItem.GetPropertyReadOnly(SvtCompatibilityEntry::Index(nCoptIdx));
+        }
+        m_xOptionsLB->set_sensitive(i, !bReadOnly);
+
         nOptions = nOptions >> 1;
     }
+
+    m_xDefaultPB->set_sensitive(!m_aConfigItem.HaveDefaultReadOnlyProperty());
 }
 
 sal_uInt32 SwCompatibilityOptPage::GetDocumentOptions() const
diff --git a/unotools/source/config/compatibility.cxx 
b/unotools/source/config/compatibility.cxx
index 0aa5f79c113b..a5c8aec15845 100644
--- a/unotools/source/config/compatibility.cxx
+++ b/unotools/source/config/compatibility.cxx
@@ -123,6 +123,9 @@ class SvtCompatibilityOptions_Impl : public ConfigItem
         bool GetDefault( SvtCompatibilityEntry::Index rIdx ) const;
 
         const std::vector< SvtCompatibilityEntry > & GetOptions() const { 
return m_aOptions; }
+        bool GetOptionReadOnly( SvtCompatibilityEntry::Index rIdx ) const;
+        bool GetDefaultOptionReadOnly( SvtCompatibilityEntry::Index rIdx ) 
const;
+        bool HaveDefaultReadOnlyOption() const;
 
         
/*-****************************************************************************************************
             @short      called for notify of configmanager
@@ -159,6 +162,7 @@ 
SvtCompatibilityOptions_Impl::SvtCompatibilityOptions_Impl() : ConfigItem( ROOTN
     Sequence< OUString > lNodes;
     Sequence< OUString > lNames  = impl_GetPropertyNames( lNodes );
     Sequence< Any >      lValues = GetProperties( lNames );
+    Sequence< sal_Bool > lReadOnly = GetReadOnlyStates( lNames );
 
     // Safe impossible cases.
     // We need values from ALL configuration keys.
@@ -178,6 +182,7 @@ 
SvtCompatibilityOptions_Impl::SvtCompatibilityOptions_Impl() : ConfigItem( ROOTN
         for ( int i = static_cast<int>(SvtCompatibilityEntry::Index::Module); 
i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID); ++i )
         {
             aItem.setValue( SvtCompatibilityEntry::Index(i), lValues[ 
nDestStep ] );
+            aItem.setPropertyReadOnly( SvtCompatibilityEntry::Index(i), 
lReadOnly[ nDestStep ] );
             nDestStep++;
         }
 
@@ -289,6 +294,40 @@ Sequence< OUString > 
SvtCompatibilityOptions_Impl::impl_GetPropertyNames( Sequen
     return lProperties;
 }
 
+bool 
SvtCompatibilityOptions_Impl::GetOptionReadOnly(SvtCompatibilityEntry::Index 
rIdx) const
+{
+    /* Are not set Name and Module */
+    assert(rIdx != SvtCompatibilityEntry::Index::Name && rIdx != 
SvtCompatibilityEntry::Index::Module);
+
+    bool bReadOnly = false;
+
+    sal_uInt32 nNewCount = m_aOptions.size();
+    for (sal_uInt32 nItem = 0; nItem < nNewCount; ++nItem)
+    {
+        SvtCompatibilityEntry aItem = m_aOptions[nItem];
+        if (aItem.getValue<OUString>(SvtCompatibilityEntry::Index::Name) == 
SvtCompatibilityEntry::USER_ENTRY_NAME)
+        {
+            bReadOnly = aItem.getPropertyReadOnly(rIdx);
+            break;
+        }
+    }
+
+    return bReadOnly;
+}
+
+bool 
SvtCompatibilityOptions_Impl::GetDefaultOptionReadOnly(SvtCompatibilityEntry::Index
 rIdx) const
+{
+    /* Are not set Name and Module */
+    assert(rIdx != SvtCompatibilityEntry::Index::Name && rIdx != 
SvtCompatibilityEntry::Index::Module);
+
+    return m_aDefOptions.getPropertyReadOnly(rIdx);
+}
+
+bool SvtCompatibilityOptions_Impl::HaveDefaultReadOnlyOption() const
+{
+    return m_aDefOptions.haveReadOnlyProperty();
+}
+
 namespace
 {
     std::weak_ptr<SvtCompatibilityOptions_Impl> theOptions;
@@ -346,6 +385,27 @@ std::vector< SvtCompatibilityEntry > 
SvtCompatibilityOptions::GetList() const
     return m_pImpl->GetOptions();
 }
 
+bool SvtCompatibilityOptions::GetPropertyReadOnly( 
SvtCompatibilityEntry::Index rIdx ) const
+{
+    MutexGuard aGuard(GetOwnStaticMutex());
+
+    return m_pImpl->GetOptionReadOnly(rIdx);
+}
+
+bool SvtCompatibilityOptions::GetDefaultPropertyReadOnly( 
SvtCompatibilityEntry::Index rIdx ) const
+{
+    MutexGuard aGuard(GetOwnStaticMutex());
+
+    return m_pImpl->GetDefaultOptionReadOnly(rIdx);
+}
+
+bool SvtCompatibilityOptions::HaveDefaultReadOnlyProperty() const
+{
+    MutexGuard aGuard(GetOwnStaticMutex());
+
+    return m_pImpl->HaveDefaultReadOnlyOption();
+}
+
 Mutex& SvtCompatibilityOptions::GetOwnStaticMutex()
 {
     static osl::Mutex aMutex;

Reply via email to