1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <com/sun/star/uno/Any.hxx>
11 #include <com/sun/star/uno/Sequence.hxx>
12 #include <osl/diagnose.h>
14 #include "defaultsoptions.hxx"
15 #include "miscuno.hxx"
17 #include "globstr.hrc"
20 using namespace com::sun::star::uno
;
22 TYPEINIT1(ScTpDefaultsItem
, SfxPoolItem
);
24 ScDefaultsOptions::ScDefaultsOptions()
29 ScDefaultsOptions::ScDefaultsOptions( const ScDefaultsOptions
& rCpy
) :
30 nInitTabCount( rCpy
.nInitTabCount
),
31 aInitTabPrefix( rCpy
.aInitTabPrefix
)
35 ScDefaultsOptions::~ScDefaultsOptions()
39 void ScDefaultsOptions::SetDefaults()
42 aInitTabPrefix
= ScGlobal::GetRscString(STR_TABLE_DEF
); // Default Prefix "Sheet"
45 ScDefaultsOptions
& ScDefaultsOptions::operator=( const ScDefaultsOptions
& rCpy
)
47 nInitTabCount
= rCpy
.nInitTabCount
;
48 aInitTabPrefix
= rCpy
.aInitTabPrefix
;
53 bool ScDefaultsOptions::operator==( const ScDefaultsOptions
& rOpt
) const
55 return rOpt
.nInitTabCount
== nInitTabCount
56 && rOpt
.aInitTabPrefix
== aInitTabPrefix
;
59 bool ScDefaultsOptions::operator!=( const ScDefaultsOptions
& rOpt
) const
61 return !(operator==(rOpt
));
64 ScTpDefaultsItem::ScTpDefaultsItem( sal_uInt16 nWhichP
, const ScDefaultsOptions
& rOpt
) :
65 SfxPoolItem ( nWhichP
),
70 ScTpDefaultsItem::ScTpDefaultsItem( const ScTpDefaultsItem
& rItem
) :
71 SfxPoolItem ( rItem
),
72 theOptions ( rItem
.theOptions
)
76 ScTpDefaultsItem::~ScTpDefaultsItem()
80 bool ScTpDefaultsItem::operator==( const SfxPoolItem
& rItem
) const
82 assert(SfxPoolItem::operator==(rItem
));
84 const ScTpDefaultsItem
& rPItem
= static_cast<const ScTpDefaultsItem
&>(rItem
);
85 return ( theOptions
== rPItem
.theOptions
);
88 SfxPoolItem
* ScTpDefaultsItem::Clone( SfxItemPool
* ) const
90 return new ScTpDefaultsItem( *this );
93 #define CFGPATH_FORMULA "Office.Calc/Defaults"
95 #define SCDEFAULTSOPT_TAB_COUNT 0
96 #define SCDEFAULTSOPT_TAB_PREFIX 1
97 #define SCDEFAULTSOPT_COUNT 2
99 Sequence
<OUString
> ScDefaultsCfg::GetPropertyNames()
101 static const char* aPropNames
[] =
103 "Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT
104 "Sheet/SheetPrefix" // SCDEFAULTSOPT_TAB_PREFIX
106 Sequence
<OUString
> aNames(SCDEFAULTSOPT_COUNT
);
107 OUString
* pNames
= aNames
.getArray();
108 for (int i
= 0; i
< SCDEFAULTSOPT_COUNT
; ++i
)
109 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
114 ScDefaultsCfg::ScDefaultsCfg() :
115 ConfigItem( OUString( CFGPATH_FORMULA
) )
119 Sequence
<OUString
> aNames
= GetPropertyNames();
120 Sequence
<Any
> aValues
= GetProperties(aNames
);
121 const Any
* pValues
= aValues
.getConstArray();
122 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
123 if(aValues
.getLength() == aNames
.getLength())
125 sal_Int32 nIntVal
= 0;
126 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
128 if(pValues
[nProp
].hasValue())
132 case SCDEFAULTSOPT_TAB_COUNT
:
133 if (pValues
[nProp
] >>= nIntVal
)
134 SetInitTabCount( static_cast<SCTAB
>(nIntVal
) );
136 case SCDEFAULTSOPT_TAB_PREFIX
:
137 if (pValues
[nProp
] >>= aPrefix
)
138 SetInitTabPrefix(aPrefix
);
146 void ScDefaultsCfg::ImplCommit()
148 Sequence
<OUString
> aNames
= GetPropertyNames();
149 Sequence
<Any
> aValues(aNames
.getLength());
150 Any
* pValues
= aValues
.getArray();
152 for (int nProp
= 0; nProp
< aNames
.getLength(); ++nProp
)
156 case SCDEFAULTSOPT_TAB_COUNT
:
157 pValues
[nProp
] <<= static_cast<sal_Int32
>(GetInitTabCount());
159 case SCDEFAULTSOPT_TAB_PREFIX
:
160 pValues
[nProp
] <<= GetInitTabPrefix();
164 PutProperties(aNames
, aValues
);
167 void ScDefaultsCfg::SetOptions( const ScDefaultsOptions
& rNew
)
169 *(ScDefaultsOptions
*)this = rNew
;
173 void ScDefaultsCfg::Notify( const ::com::sun::star::uno::Sequence
< OUString
>& ) {}
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */