Change-Id: Icda2d7a2f16fbcdf3a1e796026540bfa568be2d9 Reviewed-on: https://gerrit.libreoffice.org/28800 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
159 lines
4.1 KiB
C++
159 lines
4.1 KiB
C++
/* -*- 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 <com/sun/star/uno/Sequence.hxx>
|
|
#include <osl/diagnose.h>
|
|
|
|
#include "defaultsoptions.hxx"
|
|
#include "miscuno.hxx"
|
|
#include "global.hxx"
|
|
#include "globstr.hrc"
|
|
|
|
using namespace utl;
|
|
using namespace com::sun::star::uno;
|
|
|
|
|
|
ScDefaultsOptions::ScDefaultsOptions()
|
|
{
|
|
SetDefaults();
|
|
}
|
|
|
|
ScDefaultsOptions::ScDefaultsOptions( const ScDefaultsOptions& rCpy ) :
|
|
nInitTabCount( rCpy.nInitTabCount ),
|
|
aInitTabPrefix( rCpy.aInitTabPrefix )
|
|
{
|
|
}
|
|
|
|
ScDefaultsOptions::~ScDefaultsOptions()
|
|
{
|
|
}
|
|
|
|
void ScDefaultsOptions::SetDefaults()
|
|
{
|
|
nInitTabCount = 1;
|
|
aInitTabPrefix = ScGlobal::GetRscString(STR_TABLE_DEF); // Default Prefix "Sheet"
|
|
}
|
|
|
|
ScDefaultsOptions& ScDefaultsOptions::operator=( const ScDefaultsOptions& rCpy )
|
|
{
|
|
nInitTabCount = rCpy.nInitTabCount;
|
|
aInitTabPrefix = rCpy.aInitTabPrefix;
|
|
|
|
return *this;
|
|
}
|
|
|
|
bool ScDefaultsOptions::operator==( const ScDefaultsOptions& rOpt ) const
|
|
{
|
|
return rOpt.nInitTabCount == nInitTabCount
|
|
&& rOpt.aInitTabPrefix == aInitTabPrefix;
|
|
}
|
|
|
|
ScTpDefaultsItem::ScTpDefaultsItem( sal_uInt16 nWhichP, const ScDefaultsOptions& rOpt ) :
|
|
SfxPoolItem ( nWhichP ),
|
|
theOptions ( rOpt )
|
|
{
|
|
}
|
|
|
|
ScTpDefaultsItem::ScTpDefaultsItem( const ScTpDefaultsItem& rItem ) :
|
|
SfxPoolItem ( rItem ),
|
|
theOptions ( rItem.theOptions )
|
|
{
|
|
}
|
|
|
|
ScTpDefaultsItem::~ScTpDefaultsItem()
|
|
{
|
|
}
|
|
|
|
bool ScTpDefaultsItem::operator==( const SfxPoolItem& rItem ) const
|
|
{
|
|
assert(SfxPoolItem::operator==(rItem));
|
|
|
|
const ScTpDefaultsItem& rPItem = static_cast<const ScTpDefaultsItem&>(rItem);
|
|
return ( theOptions == rPItem.theOptions );
|
|
}
|
|
|
|
SfxPoolItem* ScTpDefaultsItem::Clone( SfxItemPool * ) const
|
|
{
|
|
return new ScTpDefaultsItem( *this );
|
|
}
|
|
|
|
#define CFGPATH_FORMULA "Office.Calc/Defaults"
|
|
|
|
#define SCDEFAULTSOPT_TAB_COUNT 0
|
|
#define SCDEFAULTSOPT_TAB_PREFIX 1
|
|
|
|
Sequence<OUString> ScDefaultsCfg::GetPropertyNames()
|
|
{
|
|
return {"Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT
|
|
"Sheet/SheetPrefix"}; // SCDEFAULTSOPT_TAB_PREFIX
|
|
}
|
|
|
|
ScDefaultsCfg::ScDefaultsCfg() :
|
|
ConfigItem( OUString( CFGPATH_FORMULA ) )
|
|
{
|
|
OUString aPrefix;
|
|
|
|
Sequence<OUString> aNames = GetPropertyNames();
|
|
Sequence<Any> aValues = GetProperties(aNames);
|
|
const Any* pValues = aValues.getConstArray();
|
|
OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
|
|
if(aValues.getLength() == aNames.getLength())
|
|
{
|
|
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<SCTAB>(nIntVal) );
|
|
break;
|
|
case SCDEFAULTSOPT_TAB_PREFIX:
|
|
if (pValues[nProp] >>= aPrefix)
|
|
SetInitTabPrefix(aPrefix);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ScDefaultsCfg::ImplCommit()
|
|
{
|
|
Sequence<OUString> aNames = GetPropertyNames();
|
|
Sequence<Any> 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<sal_Int32>(GetInitTabCount());
|
|
break;
|
|
case SCDEFAULTSOPT_TAB_PREFIX:
|
|
pValues[nProp] <<= GetInitTabPrefix();
|
|
break;
|
|
}
|
|
}
|
|
PutProperties(aNames, aValues);
|
|
}
|
|
|
|
void ScDefaultsCfg::SetOptions( const ScDefaultsOptions& rNew )
|
|
{
|
|
*static_cast<ScDefaultsOptions*>(this) = rNew;
|
|
SetModified();
|
|
}
|
|
|
|
void ScDefaultsCfg::Notify( const css::uno::Sequence< OUString >& ) {}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|