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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
24 #include "inputopt.hxx"
25 #include "rechead.hxx"
26 #include "scresid.hxx"
29 #include "miscuno.hxx"
32 using namespace com::sun::star::uno
;
34 // ScInputOptions - input options
36 ScInputOptions::ScInputOptions()
41 ScInputOptions::ScInputOptions( const ScInputOptions
& rCpy
)
46 ScInputOptions::~ScInputOptions()
50 void ScInputOptions::SetDefaults()
52 nMoveDir
= DIR_BOTTOM
;
53 bMoveSelection
= true;
55 bExtendFormat
= false;
58 mbSortRefUpdate
= true;
62 bReplCellsWarn
= true;
63 bLegacyCellSelection
= false;
66 const ScInputOptions
& ScInputOptions::operator=( const ScInputOptions
& rCpy
)
68 nMoveDir
= rCpy
.nMoveDir
;
69 bMoveSelection
= rCpy
.bMoveSelection
;
70 bEnterEdit
= rCpy
.bEnterEdit
;
71 bExtendFormat
= rCpy
.bExtendFormat
;
72 bRangeFinder
= rCpy
.bRangeFinder
;
73 bExpandRefs
= rCpy
.bExpandRefs
;
74 mbSortRefUpdate
= rCpy
.mbSortRefUpdate
;
75 bMarkHeader
= rCpy
.bMarkHeader
;
76 bUseTabCol
= rCpy
.bUseTabCol
;
77 bTextWysiwyg
= rCpy
.bTextWysiwyg
;
78 bReplCellsWarn
= rCpy
.bReplCellsWarn
;
79 bLegacyCellSelection
= rCpy
.bLegacyCellSelection
;
84 // Config Item containing input options
86 #define CFGPATH_INPUT "Office.Calc/Input"
88 #define SCINPUTOPT_MOVEDIR 0
89 #define SCINPUTOPT_MOVESEL 1
90 #define SCINPUTOPT_EDTEREDIT 2
91 #define SCINPUTOPT_EXTENDFMT 3
92 #define SCINPUTOPT_RANGEFIND 4
93 #define SCINPUTOPT_EXPANDREFS 5
94 #define SCINPUTOPT_SORT_REF_UPDATE 6
95 #define SCINPUTOPT_MARKHEADER 7
96 #define SCINPUTOPT_USETABCOL 8
97 #define SCINPUTOPT_TEXTWYSIWYG 9
98 #define SCINPUTOPT_REPLCELLSWARN 10
99 #define SCINPUTOPT_LEGACY_CELL_SELECTION 11
100 #define SCINPUTOPT_COUNT 12
102 Sequence
<OUString
> ScInputCfg::GetPropertyNames()
104 static const char* aPropNames
[] =
106 "MoveSelectionDirection", // SCINPUTOPT_MOVEDIR
107 "MoveSelection", // SCINPUTOPT_MOVESEL
108 "SwitchToEditMode", // SCINPUTOPT_EDTEREDIT
109 "ExpandFormatting", // SCINPUTOPT_EXTENDFMT
110 "ShowReference", // SCINPUTOPT_RANGEFIND
111 "ExpandReference", // SCINPUTOPT_EXPANDREFS
112 "UpdateReferenceOnSort", // SCINPUTOPT_SORT_REF_UPDATE
113 "HighlightSelection", // SCINPUTOPT_MARKHEADER
114 "UseTabCol", // SCINPUTOPT_USETABCOL
115 "UsePrinterMetrics", // SCINPUTOPT_TEXTWYSIWYG
116 "ReplaceCellsWarning", // SCINPUTOPT_REPLCELLSWARN
117 "LegacyCellSelection" // SCINPUTOPT_LEGACY_CELL_SELECTION
119 Sequence
<OUString
> aNames(SCINPUTOPT_COUNT
);
120 OUString
* pNames
= aNames
.getArray();
121 for(int i
= 0; i
< SCINPUTOPT_COUNT
; i
++)
122 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
127 ScInputCfg::ScInputCfg() :
128 ConfigItem( OUString( CFGPATH_INPUT
) )
130 Sequence
<OUString
> aNames
= GetPropertyNames();
131 Sequence
<Any
> aValues
= GetProperties(aNames
);
132 EnableNotification(aNames
);
133 const Any
* pValues
= aValues
.getConstArray();
134 OSL_ENSURE(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
135 if(aValues
.getLength() == aNames
.getLength())
137 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
139 OSL_ENSURE(pValues
[nProp
].hasValue(), "property value missing");
140 if(pValues
[nProp
].hasValue())
142 sal_Int32 nIntVal
= 0;
145 case SCINPUTOPT_MOVEDIR
:
146 if ( pValues
[nProp
] >>= nIntVal
)
147 SetMoveDir( (sal_uInt16
)nIntVal
);
149 case SCINPUTOPT_MOVESEL
:
150 SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
152 case SCINPUTOPT_EDTEREDIT
:
153 SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
155 case SCINPUTOPT_EXTENDFMT
:
156 SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
158 case SCINPUTOPT_RANGEFIND
:
159 SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
161 case SCINPUTOPT_EXPANDREFS
:
162 SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
164 case SCINPUTOPT_SORT_REF_UPDATE
:
165 SetSortRefUpdate(ScUnoHelpFunctions::GetBoolFromAny(pValues
[nProp
]));
167 case SCINPUTOPT_MARKHEADER
:
168 SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
170 case SCINPUTOPT_USETABCOL
:
171 SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
173 case SCINPUTOPT_TEXTWYSIWYG
:
174 SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
176 case SCINPUTOPT_REPLCELLSWARN
:
177 SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
179 case SCINPUTOPT_LEGACY_CELL_SELECTION
:
180 SetLegacyCellSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues
[nProp
] ) );
188 void ScInputCfg::ImplCommit()
190 Sequence
<OUString
> aNames
= GetPropertyNames();
191 Sequence
<Any
> aValues(aNames
.getLength());
192 Any
* pValues
= aValues
.getArray();
194 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
198 case SCINPUTOPT_MOVEDIR
:
199 pValues
[nProp
] <<= (sal_Int32
) GetMoveDir();
201 case SCINPUTOPT_MOVESEL
:
202 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetMoveSelection() );
204 case SCINPUTOPT_EDTEREDIT
:
205 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetEnterEdit() );
207 case SCINPUTOPT_EXTENDFMT
:
208 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetExtendFormat() );
210 case SCINPUTOPT_RANGEFIND
:
211 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetRangeFinder() );
213 case SCINPUTOPT_EXPANDREFS
:
214 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetExpandRefs() );
216 case SCINPUTOPT_SORT_REF_UPDATE
:
217 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetSortRefUpdate() );
219 case SCINPUTOPT_MARKHEADER
:
220 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetMarkHeader() );
222 case SCINPUTOPT_USETABCOL
:
223 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetUseTabCol() );
225 case SCINPUTOPT_TEXTWYSIWYG
:
226 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetTextWysiwyg() );
228 case SCINPUTOPT_REPLCELLSWARN
:
229 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetReplaceCellsWarn() );
231 case SCINPUTOPT_LEGACY_CELL_SELECTION
:
232 ScUnoHelpFunctions::SetBoolInAny( pValues
[nProp
], GetLegacyCellSelection() );
236 PutProperties(aNames
, aValues
);
239 void ScInputCfg::Notify( const Sequence
<OUString
>& /* aPropertyNames */ )
241 OSL_FAIL("properties have been changed");
244 void ScInputCfg::SetOptions( const ScInputOptions
& rNew
)
246 *(ScInputOptions
*)this = rNew
;
250 void ScInputCfg::OptionsChanged()
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */