tdf#132145: Synchronize ScPrintCfg with configuration
Change-Id: I903e8277fea5c223081244ae30dff31bbda7d554
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125904
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sc/inc/printopt.hxx b/sc/inc/printopt.hxx
index 1f00ab1..f646a35 100644
--- a/sc/inc/printopt.hxx
+++ b/sc/inc/printopt.hxx
@@ -69,16 +69,17 @@ private:
// config item
class ScPrintCfg final : public ScPrintOptions, public utl::ConfigItem
class ScPrintCfg final : private ScPrintOptions, public utl::ConfigItem
{
private:
static css::uno::Sequence<OUString> GetPropertyNames();
void ReadCfg();
virtual void ImplCommit() override;
public:
ScPrintCfg();
const ScPrintOptions& GetOptions() const { return *this; }
void SetOptions( const ScPrintOptions& rNew );
virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
diff --git a/sc/source/core/tool/printopt.cxx b/sc/source/core/tool/printopt.cxx
index b598672..930de81 100644
--- a/sc/source/core/tool/printopt.cxx
+++ b/sc/source/core/tool/printopt.cxx
@@ -88,32 +88,24 @@ ScPrintCfg::ScPrintCfg() :
ConfigItem( CFGPATH_PRINT )
{
Sequence<OUString> aNames = GetPropertyNames();
Sequence<Any> aValues = GetProperties(aNames);
const Any* pValues = aValues.getConstArray();
EnableNotification(aNames);
ReadCfg();
}
void ScPrintCfg::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())
{
switch(nProp)
{
case SCPRINTOPT_EMPTYPAGES:
// reversed
SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
break;
case SCPRINTOPT_ALLSHEETS:
SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
break;
case SCPRINTOPT_FORCEBREAKS:
SetForceBreaks( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
break;
}
}
}
if (bool bVal; aValues[SCPRINTOPT_EMPTYPAGES] >>= bVal)
SetSkipEmpty(!bVal); // reversed
if (bool bVal; aValues[SCPRINTOPT_ALLSHEETS] >>= bVal)
SetAllSheets(bVal);
if (bool bVal; aValues[SCPRINTOPT_FORCEBREAKS] >>= bVal)
SetForceBreaks(bVal);
}
void ScPrintCfg::ImplCommit()
@@ -122,22 +114,9 @@ void ScPrintCfg::ImplCommit()
Sequence<Any> aValues(aNames.getLength());
Any* pValues = aValues.getArray();
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
switch(nProp)
{
case SCPRINTOPT_EMPTYPAGES:
// reversed
pValues[nProp] <<= !GetSkipEmpty();
break;
case SCPRINTOPT_ALLSHEETS:
pValues[nProp] <<= GetAllSheets();
break;
case SCPRINTOPT_FORCEBREAKS:
pValues[nProp] <<= GetForceBreaks();
break;
}
}
pValues[SCPRINTOPT_EMPTYPAGES] <<= !GetSkipEmpty(); // reversed
pValues[SCPRINTOPT_ALLSHEETS] <<= GetAllSheets();
pValues[SCPRINTOPT_FORCEBREAKS] <<= GetForceBreaks();
PutProperties(aNames, aValues);
}
@@ -145,8 +124,9 @@ void ScPrintCfg::SetOptions( const ScPrintOptions& rNew )
{
*static_cast<ScPrintOptions*>(this) = rNew;
SetModified();
Commit();
}
void ScPrintCfg::Notify( const css::uno::Sequence< OUString >& ) {}
void ScPrintCfg::Notify( const css::uno::Sequence< OUString >& ) { ReadCfg(); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index dee33b4..d97a102 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -793,7 +793,7 @@ const ScPrintOptions& ScModule::GetPrintOptions()
if ( !m_pPrintCfg )
m_pPrintCfg.reset( new ScPrintCfg );
return *m_pPrintCfg;
return m_pPrintCfg->GetOptions();
}
ScNavipiCfg& ScModule::GetNavipiCfg()
diff --git a/test/source/sheet/globalsheetsettings.cxx b/test/source/sheet/globalsheetsettings.cxx
index 0d07ace..b707a77 100644
--- a/test/source/sheet/globalsheetsettings.cxx
+++ b/test/source/sheet/globalsheetsettings.cxx
@@ -30,24 +30,25 @@ void GlobalSheetSettings::testGlobalSheetSettingsProperties()
uno::Reference<beans::XPropertySet> xGlobalSheetSettings(init(), UNO_QUERY_THROW);
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) {
auto DoCheck = [&xGlobalSheetSettings, &configProvider](
const OUString& propName, const auto& origValue, const auto& newValue,
const OUString& regNodeName, const OUString& regValueName) {
OString sMessage = "PropertyValue " + propName.toUtf8();
css::uno::Any aOrigValue(origValue), aNewValue(newValue);
css::uno::Sequence<css::uno::Any> args{ css::uno::Any(
css::beans::NamedValue("nodepath", css::uno::makeAny(regNodeName))) };
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);
// 1. Check initial value
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue,
xGlobalSheetSettings->getPropertyValue(propName));
@@ -70,16 +71,17 @@ void GlobalSheetSettings::testGlobalSheetSettingsProperties()
xGlobalSheetSettings->getPropertyValue(propName));
};
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");
OUString node = "/org.openoffice.Office.Calc/Input";
DoCheck("MoveSelection", true, false, node, "MoveSelection");
DoCheck("MoveDirection", sal_Int16(0), sal_Int16(1), node, "MoveSelectionDirection");
DoCheck("EnterEdit", false, true, node, "SwitchToEditMode");
DoCheck("ExtendFormat", false, true, node, "ExpandFormatting");
DoCheck("RangeFinder", true, false, node, "ShowReference");
DoCheck("ExpandReferences", false, true, node, "ExpandReference");
DoCheck("MarkHeader", true, false, node, "HighlightSelection");
DoCheck("UseTabCol", false, true, node, "UseTabCol");
DoCheck("UsePrinterMetrics", false, true, node, "UsePrinterMetrics");
DoCheck("ReplaceCellsWarning", true, false, node, "ReplaceCellsWarning");
OUString propName;
uno::Any aNewValue;
@@ -162,25 +164,9 @@ void GlobalSheetSettings::testGlobalSheetSettingsProperties()
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue LinkUpdateMode", sal_Int16(1),
aLinkUpdateMode);
propName = "PrintAllSheets";
bool aPrintAllSheets = true;
CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintAllSheets);
CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue PrintAllSheets", !aPrintAllSheets);
aNewValue <<= true;
xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintAllSheets);
CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue PrintAllSheets", aPrintAllSheets);
propName = "PrintEmptyPages";
bool aPrintEmptyPages = true;
CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintEmptyPages);
CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue PrintEmptyPages", !aPrintEmptyPages);
aNewValue <<= true;
xGlobalSheetSettings->setPropertyValue(propName, aNewValue);
CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aPrintEmptyPages);
CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue PrintEmptyPages", aPrintEmptyPages);
node = "/org.openoffice.Office.Calc/Print/";
DoCheck("PrintAllSheets", false, true, node + "Other", "AllSheets");
DoCheck("PrintEmptyPages", false, true, node + "Page", "EmptyPages");
}
}