sc/inc/inputopt.hxx                       |    2 
 sc/source/core/tool/inputopt.cxx          |  148 +++++++++------------------
 test/source/sheet/globalsheetsettings.cxx |  161 ++++++++++--------------------
 3 files changed, 108 insertions(+), 203 deletions(-)

New commits:
commit 2b95775b0dd20e90bb6ec6925a6745b27cf032e6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Nov 26 22:31:35 2021 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Nov 27 07:16:24 2021 +0100

    tdf#132145: Synchronize ScInputCfg with configuration
    
    Change-Id: I45cc9b6c8cbd9205e185bebff97644f53f5cf0af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125896
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/inc/inputopt.hxx b/sc/inc/inputopt.hxx
index 5f20276cbbc6..6a3261701cff 100644
--- a/sc/inc/inputopt.hxx
+++ b/sc/inc/inputopt.hxx
@@ -77,7 +77,7 @@ class ScInputCfg final : public ScInputOptions,
                   public utl::ConfigItem
 {
     static css::uno::Sequence<OUString> GetPropertyNames();
-
+    void ReadCfg();
     virtual void    ImplCommit() override;
 
 public:
diff --git a/sc/source/core/tool/inputopt.cxx b/sc/source/core/tool/inputopt.cxx
index 5152a01beac3..aa5179bb25ec 100644
--- a/sc/source/core/tool/inputopt.cxx
+++ b/sc/source/core/tool/inputopt.cxx
@@ -91,64 +91,44 @@ ScInputCfg::ScInputCfg() :
     ConfigItem( CFGPATH_INPUT )
 {
     Sequence<OUString> aNames = GetPropertyNames();
-    Sequence<Any> aValues = GetProperties(aNames);
     EnableNotification(aNames);
-    const Any* pValues = aValues.getConstArray();
+    ReadCfg();
+}
+
+void ScInputCfg::ReadCfg()
+{
+    const Sequence<OUString> aNames = GetPropertyNames();
+    const Sequence<Any> aValues = GetProperties(aNames);
     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties 
failed");
     if(aValues.getLength() != aNames.getLength())
         return;
 
-    for(int nProp = 0; nProp < aNames.getLength(); nProp++)
-    {
-        OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
-        if(pValues[nProp].hasValue())
-        {
-            sal_Int32 nIntVal = 0;
-            switch(nProp)
-            {
-                case SCINPUTOPT_MOVEDIR:
-                    if ( pValues[nProp] >>= nIntVal )
-                        SetMoveDir( static_cast<sal_uInt16>(nIntVal) );
-                    break;
-                case SCINPUTOPT_MOVESEL:
-                    SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_EDTEREDIT:
-                    SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_EXTENDFMT:
-                    SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_RANGEFIND:
-                    SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_EXPANDREFS:
-                    SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_SORT_REF_UPDATE:
-                    
SetSortRefUpdate(ScUnoHelpFunctions::GetBoolFromAny(pValues[nProp]));
-                    break;
-                case SCINPUTOPT_MARKHEADER:
-                    SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_USETABCOL:
-                    SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_TEXTWYSIWYG:
-                    SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_REPLCELLSWARN:
-                    SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_LEGACY_CELL_SELECTION:
-                    SetLegacyCellSelection( 
ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
-                    break;
-                case SCINPUTOPT_ENTER_PASTE_MODE:
-                    SetEnterPasteMode( ScUnoHelpFunctions::GetBoolFromAny( 
pValues[nProp] ) );
-                    break;
-            }
-        }
-    }
+    if (sal_Int32 nVal; aValues[SCINPUTOPT_MOVEDIR] >>= nVal)
+        SetMoveDir(static_cast<sal_uInt16>(nVal));
+    if (bool bVal; aValues[SCINPUTOPT_MOVESEL] >>= bVal)
+        SetMoveSelection(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_EDTEREDIT] >>= bVal)
+        SetEnterEdit(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_EXTENDFMT] >>= bVal)
+        SetExtendFormat(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_RANGEFIND] >>= bVal)
+        SetRangeFinder(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_EXPANDREFS] >>= bVal)
+        SetExpandRefs(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_SORT_REF_UPDATE] >>= bVal)
+        SetSortRefUpdate(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_MARKHEADER] >>= bVal)
+        SetMarkHeader(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_USETABCOL] >>= bVal)
+        SetUseTabCol(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_TEXTWYSIWYG] >>= bVal)
+        SetTextWysiwyg(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_REPLCELLSWARN] >>= bVal)
+        SetReplaceCellsWarn(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_LEGACY_CELL_SELECTION] >>= bVal)
+        SetLegacyCellSelection(bVal);
+    if (bool bVal; aValues[SCINPUTOPT_ENTER_PASTE_MODE] >>= bVal)
+        SetEnterPasteMode(bVal);
 }
 
 void ScInputCfg::ImplCommit()
@@ -157,68 +137,38 @@ void ScInputCfg::ImplCommit()
     Sequence<Any> aValues(aNames.getLength());
     Any* pValues = aValues.getArray();
 
-    for(int nProp = 0; nProp < aNames.getLength(); nProp++)
-    {
-        switch(nProp)
-        {
-            case SCINPUTOPT_MOVEDIR:
-                pValues[nProp] <<= static_cast<sal_Int32>(GetMoveDir());
-                break;
-            case SCINPUTOPT_MOVESEL:
-                pValues[nProp] <<= GetMoveSelection();
-                break;
-            case SCINPUTOPT_EDTEREDIT:
-                pValues[nProp] <<= GetEnterEdit();
-                break;
-            case SCINPUTOPT_EXTENDFMT:
-                pValues[nProp] <<= GetExtendFormat();
-                break;
-            case SCINPUTOPT_RANGEFIND:
-                pValues[nProp] <<= GetRangeFinder();
-                break;
-            case SCINPUTOPT_EXPANDREFS:
-                pValues[nProp] <<= GetExpandRefs();
-                break;
-            case SCINPUTOPT_SORT_REF_UPDATE:
-                pValues[nProp] <<= GetSortRefUpdate();
-                break;
-            case SCINPUTOPT_MARKHEADER:
-                pValues[nProp] <<= GetMarkHeader();
-                break;
-            case SCINPUTOPT_USETABCOL:
-                pValues[nProp] <<= GetUseTabCol();
-                break;
-            case SCINPUTOPT_TEXTWYSIWYG:
-                pValues[nProp] <<= GetTextWysiwyg();
-                break;
-            case SCINPUTOPT_REPLCELLSWARN:
-                pValues[nProp] <<= GetReplaceCellsWarn();
-                break;
-            case SCINPUTOPT_LEGACY_CELL_SELECTION:
-                pValues[nProp] <<= GetLegacyCellSelection();
-                break;
-            case SCINPUTOPT_ENTER_PASTE_MODE:
-                pValues[nProp] <<= GetEnterPasteMode();
-                break;
-        }
-    }
+    pValues[SCINPUTOPT_MOVEDIR] <<= static_cast<sal_Int32>(GetMoveDir());
+    pValues[SCINPUTOPT_MOVESEL] <<= GetMoveSelection();
+    pValues[SCINPUTOPT_EDTEREDIT] <<= GetEnterEdit();
+    pValues[SCINPUTOPT_EXTENDFMT] <<= GetExtendFormat();
+    pValues[SCINPUTOPT_RANGEFIND] <<= GetRangeFinder();
+    pValues[SCINPUTOPT_EXPANDREFS] <<= GetExpandRefs();
+    pValues[SCINPUTOPT_SORT_REF_UPDATE] <<= GetSortRefUpdate();
+    pValues[SCINPUTOPT_MARKHEADER] <<= GetMarkHeader();
+    pValues[SCINPUTOPT_USETABCOL] <<= GetUseTabCol();
+    pValues[SCINPUTOPT_TEXTWYSIWYG] <<= GetTextWysiwyg();
+    pValues[SCINPUTOPT_REPLCELLSWARN] <<= GetReplaceCellsWarn();
+    pValues[SCINPUTOPT_LEGACY_CELL_SELECTION] <<= GetLegacyCellSelection();
+    pValues[SCINPUTOPT_ENTER_PASTE_MODE] <<= GetEnterPasteMode();
     PutProperties(aNames, aValues);
 }
 
 void ScInputCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ )
 {
-    OSL_FAIL("properties have been changed");
+    ReadCfg();
 }
 
 void ScInputCfg::SetOptions( const ScInputOptions& rNew )
 {
     *static_cast<ScInputOptions*>(this) = rNew;
     SetModified();
+    Commit();
 }
 
 void ScInputCfg::OptionsChanged()
 {
     SetModified();
+    Commit();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/sheet/globalsheetsettings.cxx 
b/test/source/sheet/globalsheetsettings.cxx
index 78b6d88009dc..0d07ace15abf 100644
--- a/test/source/sheet/globalsheetsettings.cxx
+++ b/test/source/sheet/globalsheetsettings.cxx
@@ -9,9 +9,14 @@
 
 #include <test/sheet/globalsheetsettings.hxx>
 
+#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/configuration/theDefaultProvider.hpp>
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/util/XChangesBatch.hpp>
+
+#include <comphelper/processfactory.hxx>
 
 #include <cppunit/TestAssert.h>
 
@@ -23,90 +28,61 @@ namespace apitest
 void GlobalSheetSettings::testGlobalSheetSettingsProperties()
 {
     uno::Reference<beans::XPropertySet> xGlobalSheetSettings(init(), 
UNO_QUERY_THROW);
-    OUString propName;
-    uno::Any aNewValue;
-
-    propName = "MoveSelection";
-    bool aMoveSelection = false;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMoveSelection);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue MoveSelection", 
aMoveSelection);
-
-    aNewValue <<= false;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMoveSelection);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue MoveSelection", 
!aMoveSelection);
-
-    propName = "MoveDirection";
-    sal_Int16 aMoveDirection = 42;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMoveDirection);
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue MoveDirection", 
sal_Int16(0),
-                                 aMoveDirection);
-
-    aNewValue <<= sal_Int16(1);
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMoveDirection);
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue MoveDirection", 
sal_Int16(1),
-                                 aMoveDirection);
-
-    propName = "EnterEdit";
-    bool aEnterEdit = true;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aEnterEdit);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnterEdit", 
!aEnterEdit);
-
-    aNewValue <<= true;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aEnterEdit);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnterEdit", 
aEnterEdit);
-
-    propName = "ExtendFormat";
-    bool aExtendFormat = true;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aExtendFormat);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ExtendFormat", 
!aExtendFormat);
-
-    aNewValue <<= true;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aExtendFormat);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ExtendFormat", 
aExtendFormat);
-
-    propName = "RangeFinder";
-    bool aRangeFinder = false;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aRangeFinder);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue RangeFinder", 
aRangeFinder);
-
-    aNewValue <<= false;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aRangeFinder);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue RangeFinder", 
!aRangeFinder);
-
-    propName = "ExpandReferences";
-    bool aExpandReferences = true;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aExpandReferences);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ExpandReferences", 
!aExpandReferences);
-
-    aNewValue <<= true;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aExpandReferences);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ExpandReferences", 
aExpandReferences);
-
-    propName = "MarkHeader";
-    bool aMarkHeader = false;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMarkHeader);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue MarkHeader", 
aMarkHeader);
-
-    aNewValue <<= false;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aMarkHeader);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue MarkHeader", 
!aMarkHeader);
+    auto configProvider
+        = 
css::configuration::theDefaultProvider::get(comphelper::getProcessComponentContext());
+    css::uno::Sequence<css::uno::Any> args{ 
css::uno::Any(css::beans::NamedValue(
+        "nodepath", 
css::uno::makeAny(OUString("/org.openoffice.Office.Calc/Input")))) };
+    css::uno::Reference<beans::XPropertySet> xRegNodeRO(
+        configProvider->createInstanceWithArguments(
+            "com.sun.star.configuration.ConfigurationAccess", args),
+        css::uno::UNO_QUERY_THROW);
+    css::uno::Reference<beans::XPropertySet> xRegNodeRW(
+        configProvider->createInstanceWithArguments(
+            "com.sun.star.configuration.ConfigurationUpdateAccess", args),
+        css::uno::UNO_QUERY_THROW);
+    css::uno::Reference<css::util::XChangesBatch> xBatch(xRegNodeRW, 
css::uno::UNO_QUERY_THROW);
+
+    auto DoCheck = [&xGlobalSheetSettings, &xRegNodeRO, &xRegNodeRW,
+                    &xBatch](const OUString& propName, const auto& origValue, 
const auto& newValue,
+                             const OUString& regValueName) {
+        OString sMessage = "PropertyValue " + propName.toUtf8();
+        css::uno::Any aOrigValue(origValue), aNewValue(newValue);
+
+        // 1. Check initial value
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
+                                     
xGlobalSheetSettings->getPropertyValue(propName));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
+                                     
xRegNodeRO->getPropertyValue(regValueName));
+
+        // 2. Check setting the value through GlobalSheetSettings
+        xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue,
+                                     
xGlobalSheetSettings->getPropertyValue(propName));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue,
+                                     
xRegNodeRO->getPropertyValue(regValueName));
+
+        // 3. Check setting the value through ConfigurationUpdateAccess
+        xRegNodeRW->setPropertyValue(regValueName, aOrigValue);
+        xBatch->commitChanges();
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
+                                     
xRegNodeRO->getPropertyValue(regValueName));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
+                                     
xGlobalSheetSettings->getPropertyValue(propName));
+    };
 
-    propName = "UseTabCol";
-    bool aUseTabCol = true;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aUseTabCol);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue UseTabCol", 
!aUseTabCol);
+    DoCheck("MoveSelection", true, false, "MoveSelection");
+    DoCheck("MoveDirection", sal_Int16(0), sal_Int16(1), 
"MoveSelectionDirection");
+    DoCheck("EnterEdit", false, true, "SwitchToEditMode");
+    DoCheck("ExtendFormat", false, true, "ExpandFormatting");
+    DoCheck("RangeFinder", true, false, "ShowReference");
+    DoCheck("ExpandReferences", false, true, "ExpandReference");
+    DoCheck("MarkHeader", true, false, "HighlightSelection");
+    DoCheck("UseTabCol", false, true, "UseTabCol");
+    DoCheck("UsePrinterMetrics", false, true, "UsePrinterMetrics");
+    DoCheck("ReplaceCellsWarning", true, false, "ReplaceCellsWarning");
 
-    aNewValue <<= true;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aUseTabCol);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UseTabCol", 
aUseTabCol);
+    OUString propName;
+    uno::Any aNewValue;
 
     propName = "Metric";
     sal_Int16 aMetric = 42;
@@ -205,27 +181,6 @@ void 
GlobalSheetSettings::testGlobalSheetSettingsProperties()
     xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
     CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aPrintEmptyPages);
     CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue PrintEmptyPages", 
aPrintEmptyPages);
-
-    propName = "UsePrinterMetrics";
-    bool aUsePrinterMetrics = true;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aUsePrinterMetrics);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue UsePrinterMetrics", 
!aUsePrinterMetrics);
-
-    aNewValue <<= true;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aUsePrinterMetrics);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UsePrinterMetrics", 
aUsePrinterMetrics);
-
-    propName = "ReplaceCellsWarning";
-    bool aReplaceCellsWarning = false;
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aReplaceCellsWarning);
-    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ReplaceCellsWarning", 
aReplaceCellsWarning);
-
-    aNewValue <<= false;
-    xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
-    CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= 
aReplaceCellsWarning);
-    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ReplaceCellsWarning",
-                           !aReplaceCellsWarning);
 }
 }
 

Reply via email to