Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / defaultsoptions.cxx
blob896a94a672ff66803959ab21090b60d5e926a9d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <com/sun/star/uno/Any.hxx>
11 #include <com/sun/star/uno/Sequence.hxx>
13 #include "defaultsoptions.hxx"
14 #include "miscuno.hxx"
15 #include "global.hxx"
16 #include "globstr.hrc"
18 using namespace utl;
19 using namespace com::sun::star::uno;
21 TYPEINIT1(ScTpDefaultsItem, SfxPoolItem);
23 ScDefaultsOptions::ScDefaultsOptions()
25 SetDefaults();
28 ScDefaultsOptions::ScDefaultsOptions( const ScDefaultsOptions& rCpy ) :
29 nInitTabCount( rCpy.nInitTabCount ),
30 aInitTabPrefix( rCpy.aInitTabPrefix )
34 ScDefaultsOptions::~ScDefaultsOptions()
38 void ScDefaultsOptions::SetDefaults()
40 nInitTabCount = 1;
41 aInitTabPrefix = ScGlobal::GetRscString(STR_TABLE_DEF); // Default Prefix "Sheet"
44 ScDefaultsOptions& ScDefaultsOptions::operator=( const ScDefaultsOptions& rCpy )
46 nInitTabCount = rCpy.nInitTabCount;
47 aInitTabPrefix = rCpy.aInitTabPrefix;
49 return *this;
52 bool ScDefaultsOptions::operator==( const ScDefaultsOptions& rOpt ) const
54 return rOpt.nInitTabCount == nInitTabCount
55 && rOpt.aInitTabPrefix == aInitTabPrefix;
58 bool ScDefaultsOptions::operator!=( const ScDefaultsOptions& rOpt ) const
60 return !(operator==(rOpt));
63 ScTpDefaultsItem::ScTpDefaultsItem( sal_uInt16 nWhichP, const ScDefaultsOptions& rOpt ) :
64 SfxPoolItem ( nWhichP ),
65 theOptions ( rOpt )
69 ScTpDefaultsItem::ScTpDefaultsItem( const ScTpDefaultsItem& rItem ) :
70 SfxPoolItem ( rItem ),
71 theOptions ( rItem.theOptions )
75 ScTpDefaultsItem::~ScTpDefaultsItem()
79 OUString ScTpDefaultsItem::GetValueText() const
81 return OUString("ScTpDefaultsItem");
84 int ScTpDefaultsItem::operator==( const SfxPoolItem& rItem ) const
86 OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
88 const ScTpDefaultsItem& rPItem = (const ScTpDefaultsItem&)rItem;
89 return ( theOptions == rPItem.theOptions );
92 SfxPoolItem* ScTpDefaultsItem::Clone( SfxItemPool * ) const
94 return new ScTpDefaultsItem( *this );
97 #define CFGPATH_FORMULA "Office.Calc/Defaults"
99 #define SCDEFAULTSOPT_TAB_COUNT 0
100 #define SCDEFAULTSOPT_TAB_PREFIX 1
101 #define SCDEFAULTSOPT_COUNT 2
103 Sequence<OUString> ScDefaultsCfg::GetPropertyNames()
105 static const char* aPropNames[] =
107 "Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT
108 "Sheet/SheetPrefix" // SCDEFAULTSOPT_TAB_PREFIX
110 Sequence<OUString> aNames(SCDEFAULTSOPT_COUNT);
111 OUString* pNames = aNames.getArray();
112 for (int i = 0; i < SCDEFAULTSOPT_COUNT; ++i)
113 pNames[i] = OUString::createFromAscii(aPropNames[i]);
115 return aNames;
118 ScDefaultsCfg::ScDefaultsCfg() :
119 ConfigItem( OUString( CFGPATH_FORMULA ) )
121 OUString aPrefix;
123 Sequence<OUString> aNames = GetPropertyNames();
124 Sequence<Any> aValues = GetProperties(aNames);
125 const Any* pValues = aValues.getConstArray();
126 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
127 if(aValues.getLength() == aNames.getLength())
129 sal_Int32 nIntVal = 0;
130 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
132 if(pValues[nProp].hasValue())
134 switch (nProp)
136 case SCDEFAULTSOPT_TAB_COUNT:
137 if (pValues[nProp] >>= nIntVal)
138 SetInitTabCount( static_cast<SCTAB>(nIntVal) );
139 break;
140 case SCDEFAULTSOPT_TAB_PREFIX:
141 if (pValues[nProp] >>= aPrefix)
142 SetInitTabPrefix(aPrefix);
143 break;
150 void ScDefaultsCfg::Commit()
152 Sequence<OUString> aNames = GetPropertyNames();
153 Sequence<Any> aValues(aNames.getLength());
154 Any* pValues = aValues.getArray();
156 for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
158 switch(nProp)
160 case SCDEFAULTSOPT_TAB_COUNT:
161 pValues[nProp] <<= static_cast<sal_Int32>(GetInitTabCount());
162 break;
163 case SCDEFAULTSOPT_TAB_PREFIX:
164 pValues[nProp] <<= GetInitTabPrefix();
165 break;
168 PutProperties(aNames, aValues);
171 void ScDefaultsCfg::SetOptions( const ScDefaultsOptions& rNew )
173 *(ScDefaultsOptions*)this = rNew;
174 SetModified();
177 void ScDefaultsCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */