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