From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sc/source/core/tool/defaultsoptions.cxx | 151 ++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 sc/source/core/tool/defaultsoptions.cxx (limited to 'sc/source/core/tool/defaultsoptions.cxx') diff --git a/sc/source/core/tool/defaultsoptions.cxx b/sc/source/core/tool/defaultsoptions.cxx new file mode 100644 index 000000000..3f18da093 --- /dev/null +++ b/sc/source/core/tool/defaultsoptions.cxx @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 +#include +#include + +using namespace utl; +using namespace com::sun::star::uno; + + +ScDefaultsOptions::ScDefaultsOptions() +{ + SetDefaults(); +} + +void ScDefaultsOptions::SetDefaults() +{ + nInitTabCount = 1; + aInitTabPrefix = ScResId(STR_TABLE_DEF); // Default Prefix "Sheet" + bJumboSheets = false; +} + +bool ScDefaultsOptions::operator==( const ScDefaultsOptions& rOpt ) const +{ + return rOpt.nInitTabCount == nInitTabCount + && rOpt.aInitTabPrefix == aInitTabPrefix + && rOpt.bJumboSheets == bJumboSheets; +} + +ScTpDefaultsItem::ScTpDefaultsItem( const ScDefaultsOptions& rOpt ) : + SfxPoolItem ( SID_SCDEFAULTSOPTIONS ), + theOptions ( rOpt ) +{ +} + +ScTpDefaultsItem::~ScTpDefaultsItem() +{ +} + +bool ScTpDefaultsItem::operator==( const SfxPoolItem& rItem ) const +{ + assert(SfxPoolItem::operator==(rItem)); + + const ScTpDefaultsItem& rPItem = static_cast(rItem); + return ( theOptions == rPItem.theOptions ); +} + +ScTpDefaultsItem* ScTpDefaultsItem::Clone( SfxItemPool * ) const +{ + return new ScTpDefaultsItem( *this ); +} + +constexpr OUStringLiteral CFGPATH_FORMULA = u"Office.Calc/Defaults"; + +#define SCDEFAULTSOPT_TAB_COUNT 0 +#define SCDEFAULTSOPT_TAB_PREFIX 1 +#define SCDEFAULTSOPT_JUMBO_SHEETS 2 + +Sequence ScDefaultsCfg::GetPropertyNames() +{ + return {"Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT + "Sheet/SheetPrefix", // SCDEFAULTSOPT_TAB_PREFIX + "Sheet/JumboSheets"}; // SCDEFAULTSOPT_JUMBO_SHEETS + +} + +ScDefaultsCfg::ScDefaultsCfg() : + ConfigItem( CFGPATH_FORMULA ) +{ + OUString aPrefix; + + Sequence aNames = GetPropertyNames(); + Sequence aValues = GetProperties(aNames); + const Any* pValues = aValues.getConstArray(); + OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed"); + if(aValues.getLength() != aNames.getLength()) + return; + + sal_Int32 nIntVal = 0; + for(int nProp = 0; nProp < aNames.getLength(); nProp++) + { + if(pValues[nProp].hasValue()) + { + switch (nProp) + { + case SCDEFAULTSOPT_TAB_COUNT: + if (pValues[nProp] >>= nIntVal) + SetInitTabCount( static_cast(nIntVal) ); + break; + case SCDEFAULTSOPT_TAB_PREFIX: + if (pValues[nProp] >>= aPrefix) + SetInitTabPrefix(aPrefix); + break; + case SCDEFAULTSOPT_JUMBO_SHEETS: +#if HAVE_FEATURE_JUMBO_SHEETS + { + bool bValue; + if (pValues[nProp] >>= bValue) + SetInitJumboSheets(bValue); + } +#endif + break; + } + } + } +} + +void ScDefaultsCfg::ImplCommit() +{ + Sequence aNames = GetPropertyNames(); + Sequence aValues(aNames.getLength()); + Any* pValues = aValues.getArray(); + + for (int nProp = 0; nProp < aNames.getLength(); ++nProp) + { + switch(nProp) + { + case SCDEFAULTSOPT_TAB_COUNT: + pValues[nProp] <<= static_cast(GetInitTabCount()); + break; + case SCDEFAULTSOPT_TAB_PREFIX: + pValues[nProp] <<= GetInitTabPrefix(); + break; + case SCDEFAULTSOPT_JUMBO_SHEETS: + pValues[nProp] <<= GetInitJumboSheets(); + break; + } + } + PutProperties(aNames, aValues); +} + +void ScDefaultsCfg::SetOptions( const ScDefaultsOptions& rNew ) +{ + *static_cast(this) = rNew; + SetModified(); +} + +void ScDefaultsCfg::Notify( const css::uno::Sequence< OUString >& ) {} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3