1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 //------------------------------------------------------------------
30
31 #include <tools/debug.hxx>
32
33 #include <com/sun/star/uno/Any.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35
36 #include "cfgids.hxx"
37 #include "inputopt.hxx"
38 #include "rechead.hxx"
39 #include "scresid.hxx"
40 #include "global.hxx"
41 #include "sc.hrc"
42 #include "miscuno.hxx"
43
44 using namespace utl;
45 using namespace rtl;
46 using namespace com::sun::star::uno;
47
48 //------------------------------------------------------------------
49
50 // Version, ab der das Item kompatibel ist
51 #define SC_VERSION ((sal_uInt16)351)
52
53
54 //========================================================================
55 // ScInputOptions - Eingabe-Optionen
56 //========================================================================
57
ScInputOptions()58 ScInputOptions::ScInputOptions()
59 {
60 SetDefaults();
61 }
62
63 //------------------------------------------------------------------------
64
ScInputOptions(const ScInputOptions & rCpy)65 ScInputOptions::ScInputOptions( const ScInputOptions& rCpy )
66 {
67 *this = rCpy;
68 }
69
70 //------------------------------------------------------------------------
71
~ScInputOptions()72 ScInputOptions::~ScInputOptions()
73 {
74 }
75
76 //------------------------------------------------------------------------
77
SetDefaults()78 void ScInputOptions::SetDefaults()
79 {
80 nMoveDir = DIR_BOTTOM;
81 bMoveSelection = sal_True;
82 bEnterEdit = sal_False;
83 bExtendFormat = sal_False;
84 bRangeFinder = sal_True;
85 bExpandRefs = sal_False;
86 bMarkHeader = sal_True;
87 bUseTabCol = sal_False;
88 bTextWysiwyg = sal_False;
89 bReplCellsWarn = sal_True;
90 }
91
92 //------------------------------------------------------------------------
93
operator =(const ScInputOptions & rCpy)94 const ScInputOptions& ScInputOptions::operator=( const ScInputOptions& rCpy )
95 {
96 nMoveDir = rCpy.nMoveDir;
97 bMoveSelection = rCpy.bMoveSelection;
98 bEnterEdit = rCpy.bEnterEdit;
99 bExtendFormat = rCpy.bExtendFormat;
100 bRangeFinder = rCpy.bRangeFinder;
101 bExpandRefs = rCpy.bExpandRefs;
102 bMarkHeader = rCpy.bMarkHeader;
103 bUseTabCol = rCpy.bUseTabCol;
104 bTextWysiwyg = rCpy.bTextWysiwyg;
105 bReplCellsWarn = rCpy.bReplCellsWarn;
106
107 return *this;
108 }
109
110
111 //==================================================================
112 // Config Item containing input options
113 //==================================================================
114
115 #define CFGPATH_INPUT "Office.Calc/Input"
116
117 #define SCINPUTOPT_MOVEDIR 0
118 #define SCINPUTOPT_MOVESEL 1
119 #define SCINPUTOPT_EDTEREDIT 2
120 #define SCINPUTOPT_EXTENDFMT 3
121 #define SCINPUTOPT_RANGEFIND 4
122 #define SCINPUTOPT_EXPANDREFS 5
123 #define SCINPUTOPT_MARKHEADER 6
124 #define SCINPUTOPT_USETABCOL 7
125 #define SCINPUTOPT_TEXTWYSIWYG 8
126 #define SCINPUTOPT_REPLCELLSWARN 9
127 #define SCINPUTOPT_COUNT 10
128
GetPropertyNames()129 Sequence<OUString> ScInputCfg::GetPropertyNames()
130 {
131 static const char* aPropNames[] =
132 {
133 "MoveSelectionDirection", // SCINPUTOPT_MOVEDIR
134 "MoveSelection", // SCINPUTOPT_MOVESEL
135 "SwitchToEditMode", // SCINPUTOPT_EDTEREDIT
136 "ExpandFormatting", // SCINPUTOPT_EXTENDFMT
137 "ShowReference", // SCINPUTOPT_RANGEFIND
138 "ExpandReference", // SCINPUTOPT_EXPANDREFS
139 "HighlightSelection", // SCINPUTOPT_MARKHEADER
140 "UseTabCol", // SCINPUTOPT_USETABCOL
141 "UsePrinterMetrics", // SCINPUTOPT_TEXTWYSIWYG
142 "ReplaceCellsWarning" // SCINPUTOPT_REPLCELLSWARN
143 };
144 Sequence<OUString> aNames(SCINPUTOPT_COUNT);
145 OUString* pNames = aNames.getArray();
146 for(int i = 0; i < SCINPUTOPT_COUNT; i++)
147 pNames[i] = OUString::createFromAscii(aPropNames[i]);
148
149 return aNames;
150 }
151
ScInputCfg()152 ScInputCfg::ScInputCfg() :
153 ConfigItem( OUString::createFromAscii( CFGPATH_INPUT ) )
154 {
155 sal_Int32 nIntVal = 0;
156
157 Sequence<OUString> aNames = GetPropertyNames();
158 Sequence<Any> aValues = GetProperties(aNames);
159 EnableNotification(aNames);
160 const Any* pValues = aValues.getConstArray();
161 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
162 if(aValues.getLength() == aNames.getLength())
163 {
164 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
165 {
166 DBG_ASSERT(pValues[nProp].hasValue(), "property value missing");
167 if(pValues[nProp].hasValue())
168 {
169 switch(nProp)
170 {
171 case SCINPUTOPT_MOVEDIR:
172 if ( pValues[nProp] >>= nIntVal )
173 SetMoveDir( (sal_uInt16)nIntVal );
174 break;
175 case SCINPUTOPT_MOVESEL:
176 SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
177 break;
178 case SCINPUTOPT_EDTEREDIT:
179 SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
180 break;
181 case SCINPUTOPT_EXTENDFMT:
182 SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
183 break;
184 case SCINPUTOPT_RANGEFIND:
185 SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
186 break;
187 case SCINPUTOPT_EXPANDREFS:
188 SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
189 break;
190 case SCINPUTOPT_MARKHEADER:
191 SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
192 break;
193 case SCINPUTOPT_USETABCOL:
194 SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
195 break;
196 case SCINPUTOPT_TEXTWYSIWYG:
197 SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
198 break;
199 case SCINPUTOPT_REPLCELLSWARN:
200 SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
201 break;
202 }
203 }
204 }
205 }
206 }
207
208
Commit()209 void ScInputCfg::Commit()
210 {
211 Sequence<OUString> aNames = GetPropertyNames();
212 Sequence<Any> aValues(aNames.getLength());
213 Any* pValues = aValues.getArray();
214
215 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
216 {
217 switch(nProp)
218 {
219 case SCINPUTOPT_MOVEDIR:
220 pValues[nProp] <<= (sal_Int32) GetMoveDir();
221 break;
222 case SCINPUTOPT_MOVESEL:
223 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMoveSelection() );
224 break;
225 case SCINPUTOPT_EDTEREDIT:
226 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetEnterEdit() );
227 break;
228 case SCINPUTOPT_EXTENDFMT:
229 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExtendFormat() );
230 break;
231 case SCINPUTOPT_RANGEFIND:
232 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetRangeFinder() );
233 break;
234 case SCINPUTOPT_EXPANDREFS:
235 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExpandRefs() );
236 break;
237 case SCINPUTOPT_MARKHEADER:
238 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMarkHeader() );
239 break;
240 case SCINPUTOPT_USETABCOL:
241 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetUseTabCol() );
242 break;
243 case SCINPUTOPT_TEXTWYSIWYG:
244 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetTextWysiwyg() );
245 break;
246 case SCINPUTOPT_REPLCELLSWARN:
247 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetReplaceCellsWarn() );
248 break;
249 }
250 }
251 PutProperties(aNames, aValues);
252 }
253
Notify(const Sequence<rtl::OUString> &)254 void ScInputCfg::Notify( const Sequence<rtl::OUString>& /* aPropertyNames */ )
255 {
256 DBG_ERROR("properties have been changed");
257 }
258
SetOptions(const ScInputOptions & rNew)259 void ScInputCfg::SetOptions( const ScInputOptions& rNew )
260 {
261 *(ScInputOptions*)this = rNew;
262 SetModified();
263 }
264
OptionsChanged()265 void ScInputCfg::OptionsChanged()
266 {
267 SetModified();
268 }
269
270
271