Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Albert Thuswaldner <albert.thuswaldner@gmail.com>
17 : * Portions created by the Initial Developer are Copyright (C) 2012 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <com/sun/star/uno/Any.hxx>
30 : #include <com/sun/star/uno/Sequence.hxx>
31 :
32 : #include "defaultsoptions.hxx"
33 : #include "miscuno.hxx"
34 : #include "global.hxx"
35 : #include "globstr.hrc"
36 :
37 : using namespace utl;
38 : using namespace com::sun::star::uno;
39 : using ::rtl::OUString;
40 :
41 : // -----------------------------------------------------------------------
42 :
43 0 : TYPEINIT1(ScTpDefaultsItem, SfxPoolItem);
44 :
45 : // -----------------------------------------------------------------------
46 :
47 4 : ScDefaultsOptions::ScDefaultsOptions()
48 : {
49 4 : SetDefaults();
50 4 : }
51 :
52 0 : ScDefaultsOptions::ScDefaultsOptions( const ScDefaultsOptions& rCpy ) :
53 : nInitTabCount( rCpy.nInitTabCount ),
54 0 : aInitTabPrefix( rCpy.aInitTabPrefix )
55 : {
56 0 : }
57 :
58 0 : ScDefaultsOptions::~ScDefaultsOptions()
59 : {
60 0 : }
61 :
62 4 : void ScDefaultsOptions::SetDefaults()
63 : {
64 4 : nInitTabCount = 1;
65 4 : aInitTabPrefix = ScGlobal::GetRscString(STR_TABLE_DEF); // Default Prefix "Sheet"
66 4 : }
67 :
68 0 : ScDefaultsOptions& ScDefaultsOptions::operator=( const ScDefaultsOptions& rCpy )
69 : {
70 0 : nInitTabCount = rCpy.nInitTabCount;
71 0 : aInitTabPrefix = rCpy.aInitTabPrefix;
72 :
73 0 : return *this;
74 : }
75 :
76 0 : bool ScDefaultsOptions::operator==( const ScDefaultsOptions& rOpt ) const
77 : {
78 : return rOpt.nInitTabCount == nInitTabCount
79 0 : && rOpt.aInitTabPrefix == aInitTabPrefix;
80 : }
81 :
82 0 : bool ScDefaultsOptions::operator!=( const ScDefaultsOptions& rOpt ) const
83 : {
84 0 : return !(operator==(rOpt));
85 : }
86 :
87 : // -----------------------------------------------------------------------
88 :
89 :
90 0 : ScTpDefaultsItem::ScTpDefaultsItem( sal_uInt16 nWhichP, const ScDefaultsOptions& rOpt ) :
91 : SfxPoolItem ( nWhichP ),
92 0 : theOptions ( rOpt )
93 : {
94 0 : }
95 :
96 0 : ScTpDefaultsItem::ScTpDefaultsItem( const ScTpDefaultsItem& rItem ) :
97 : SfxPoolItem ( rItem ),
98 0 : theOptions ( rItem.theOptions )
99 : {
100 0 : }
101 :
102 0 : ScTpDefaultsItem::~ScTpDefaultsItem()
103 : {
104 0 : }
105 :
106 0 : String ScTpDefaultsItem::GetValueText() const
107 : {
108 0 : return rtl::OUString("ScTpDefaultsItem");
109 : }
110 :
111 0 : int ScTpDefaultsItem::operator==( const SfxPoolItem& rItem ) const
112 : {
113 : OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
114 :
115 0 : const ScTpDefaultsItem& rPItem = (const ScTpDefaultsItem&)rItem;
116 0 : return ( theOptions == rPItem.theOptions );
117 : }
118 :
119 0 : SfxPoolItem* ScTpDefaultsItem::Clone( SfxItemPool * ) const
120 : {
121 0 : return new ScTpDefaultsItem( *this );
122 : }
123 :
124 : // -----------------------------------------------------------------------
125 :
126 : #define CFGPATH_FORMULA "Office.Calc/Defaults"
127 :
128 : #define SCDEFAULTSOPT_TAB_COUNT 0
129 : #define SCDEFAULTSOPT_TAB_PREFIX 1
130 : #define SCDEFAULTSOPT_COUNT 2
131 :
132 4 : Sequence<OUString> ScDefaultsCfg::GetPropertyNames()
133 : {
134 : static const char* aPropNames[] =
135 : {
136 : "Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT
137 : "Sheet/SheetPrefix" // SCDEFAULTSOPT_TAB_PREFIX
138 : };
139 4 : Sequence<OUString> aNames(SCDEFAULTSOPT_COUNT);
140 4 : OUString* pNames = aNames.getArray();
141 12 : for (int i = 0; i < SCDEFAULTSOPT_COUNT; ++i)
142 8 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
143 :
144 4 : return aNames;
145 : }
146 :
147 4 : ScDefaultsCfg::ScDefaultsCfg() :
148 4 : ConfigItem( OUString(RTL_CONSTASCII_USTRINGPARAM( CFGPATH_FORMULA )) )
149 : {
150 4 : OUString aPrefix;
151 :
152 4 : Sequence<OUString> aNames = GetPropertyNames();
153 4 : Sequence<Any> aValues = GetProperties(aNames);
154 4 : const Any* pValues = aValues.getConstArray();
155 : OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
156 4 : if(aValues.getLength() == aNames.getLength())
157 : {
158 4 : sal_Int32 nIntVal = 0;
159 12 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
160 : {
161 8 : if(pValues[nProp].hasValue())
162 : {
163 4 : switch (nProp)
164 : {
165 : case SCDEFAULTSOPT_TAB_COUNT:
166 4 : if (pValues[nProp] >>= nIntVal)
167 4 : SetInitTabCount( static_cast<SCTAB>(nIntVal) );
168 4 : break;
169 : case SCDEFAULTSOPT_TAB_PREFIX:
170 0 : if (pValues[nProp] >>= aPrefix)
171 0 : SetInitTabPrefix(aPrefix);
172 0 : break;
173 : }
174 : }
175 : }
176 4 : }
177 4 : }
178 :
179 0 : void ScDefaultsCfg::Commit()
180 : {
181 0 : Sequence<OUString> aNames = GetPropertyNames();
182 0 : Sequence<Any> aValues(aNames.getLength());
183 0 : Any* pValues = aValues.getArray();
184 :
185 0 : for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
186 : {
187 0 : switch(nProp)
188 : {
189 : case SCDEFAULTSOPT_TAB_COUNT:
190 0 : pValues[nProp] <<= static_cast<sal_Int32>(GetInitTabCount());
191 0 : break;
192 : case SCDEFAULTSOPT_TAB_PREFIX:
193 0 : pValues[nProp] <<= GetInitTabPrefix();
194 0 : break;
195 : }
196 : }
197 0 : PutProperties(aNames, aValues);
198 0 : }
199 :
200 0 : void ScDefaultsCfg::SetOptions( const ScDefaultsOptions& rNew )
201 : {
202 0 : *(ScDefaultsOptions*)this = rNew;
203 0 : SetModified();
204 0 : }
205 :
206 0 : void ScDefaultsCfg::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
207 :
208 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|