cid#1640468 Dereference after null check
[LibreOffice.git] / sc / source / core / tool / inputopt.cxx
blob01a62bb7f3a226c08e3a32212d4b853691284867
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/.
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>
22 #include <osl/diagnose.h>
24 #include <inputopt.hxx>
25 #include <global.hxx>
27 using namespace utl;
28 using namespace com::sun::star::uno;
30 // ScInputOptions - input options
32 ScInputOptions::ScInputOptions()
33 : nMoveDir(DIR_BOTTOM)
34 , bMoveSelection(true)
35 , bMoveKeepEdit(false)
36 , bEnterEdit(false)
37 , bExtendFormat(false)
38 , bRangeFinder(true)
39 , bExpandRefs(false)
40 , mbSortRefUpdate(true)
41 , bMarkHeader(true)
42 , bUseTabCol(false)
43 , bTextWysiwyg(false)
44 , bReplCellsWarn(true)
45 , bLegacyCellSelection(false)
46 , bEnterPasteMode(false)
47 , bWarnActiveSheet(true)
51 // Config Item containing input options
53 constexpr OUStringLiteral CFGPATH_INPUT = u"Office.Calc/Input";
55 #define SCINPUTOPT_MOVEDIR 0
56 #define SCINPUTOPT_MOVESEL 1
57 #define SCINPUTOPT_EDTEREDIT 2
58 #define SCINPUTOPT_EXTENDFMT 3
59 #define SCINPUTOPT_RANGEFIND 4
60 #define SCINPUTOPT_EXPANDREFS 5
61 #define SCINPUTOPT_SORT_REF_UPDATE 6
62 #define SCINPUTOPT_MARKHEADER 7
63 #define SCINPUTOPT_USETABCOL 8
64 #define SCINPUTOPT_REPLCELLSWARN 9
65 #define SCINPUTOPT_LEGACY_CELL_SELECTION 10
66 #define SCINPUTOPT_ENTER_PASTE_MODE 11
67 #define SCINPUTOPT_WARNACTIVESHEET 12
69 Sequence<OUString> ScInputCfg::GetPropertyNames()
71 return {u"MoveSelectionDirection"_ustr, // SCINPUTOPT_MOVEDIR
72 u"MoveSelection"_ustr, // SCINPUTOPT_MOVESEL
73 u"SwitchToEditMode"_ustr, // SCINPUTOPT_EDTEREDIT
74 u"ExpandFormatting"_ustr, // SCINPUTOPT_EXTENDFMT
75 u"ShowReference"_ustr, // SCINPUTOPT_RANGEFIND
76 u"ExpandReference"_ustr, // SCINPUTOPT_EXPANDREFS
77 u"UpdateReferenceOnSort"_ustr, // SCINPUTOPT_SORT_REF_UPDATE
78 u"HighlightSelection"_ustr, // SCINPUTOPT_MARKHEADER
79 u"UseTabCol"_ustr, // SCINPUTOPT_USETABCOL
80 u"ReplaceCellsWarning"_ustr, // SCINPUTOPT_REPLCELLSWARN
81 u"LegacyCellSelection"_ustr, // SCINPUTOPT_LEGACY_CELL_SELECTION
82 u"EnterPasteMode"_ustr, // SCINPUTOPT_ENTER_PASTE_MODE
83 u"WarnActiveSheet"_ustr}; // SCINPUTOPT_WARNACTIVESHEET
86 ScInputCfg::ScInputCfg() :
87 ConfigItem( CFGPATH_INPUT )
89 Sequence<OUString> aNames = GetPropertyNames();
90 EnableNotification(aNames);
91 ReadCfg();
94 void ScInputCfg::ReadCfg()
96 const Sequence<OUString> aNames = GetPropertyNames();
97 const Sequence<Any> aValues = GetProperties(aNames);
98 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
99 if(aValues.getLength() != aNames.getLength())
100 return;
102 if (sal_Int32 nVal; aValues[SCINPUTOPT_MOVEDIR] >>= nVal)
103 SetMoveDir(static_cast<sal_uInt16>(nVal));
104 if (bool bVal; aValues[SCINPUTOPT_MOVESEL] >>= bVal)
105 SetMoveSelection(bVal);
106 if (bool bVal; aValues[SCINPUTOPT_EDTEREDIT] >>= bVal)
107 SetEnterEdit(bVal);
108 if (bool bVal; aValues[SCINPUTOPT_EXTENDFMT] >>= bVal)
109 SetExtendFormat(bVal);
110 if (bool bVal; aValues[SCINPUTOPT_RANGEFIND] >>= bVal)
111 SetRangeFinder(bVal);
112 if (bool bVal; aValues[SCINPUTOPT_EXPANDREFS] >>= bVal)
113 SetExpandRefs(bVal);
114 if (bool bVal; aValues[SCINPUTOPT_SORT_REF_UPDATE] >>= bVal)
115 SetSortRefUpdate(bVal);
116 if (bool bVal; aValues[SCINPUTOPT_MARKHEADER] >>= bVal)
117 SetMarkHeader(bVal);
118 if (bool bVal; aValues[SCINPUTOPT_USETABCOL] >>= bVal)
119 SetUseTabCol(bVal);
120 if (bool bVal; aValues[SCINPUTOPT_REPLCELLSWARN] >>= bVal)
121 SetReplaceCellsWarn(bVal);
122 if (bool bVal; aValues[SCINPUTOPT_LEGACY_CELL_SELECTION] >>= bVal)
123 SetLegacyCellSelection(bVal);
124 if (bool bVal; aValues[SCINPUTOPT_ENTER_PASTE_MODE] >>= bVal)
125 SetEnterPasteMode(bVal);
126 if (bool bVal; aValues[SCINPUTOPT_WARNACTIVESHEET] >>= bVal)
127 SetWarnActiveSheet(bVal);
130 void ScInputCfg::ImplCommit()
132 Sequence<OUString> aNames = GetPropertyNames();
133 Sequence<Any> aValues(aNames.getLength());
134 Any* pValues = aValues.getArray();
136 pValues[SCINPUTOPT_MOVEDIR] <<= static_cast<sal_Int32>(GetMoveDir());
137 pValues[SCINPUTOPT_MOVESEL] <<= GetMoveSelection();
138 pValues[SCINPUTOPT_EDTEREDIT] <<= GetEnterEdit();
139 pValues[SCINPUTOPT_EXTENDFMT] <<= GetExtendFormat();
140 pValues[SCINPUTOPT_RANGEFIND] <<= GetRangeFinder();
141 pValues[SCINPUTOPT_EXPANDREFS] <<= GetExpandRefs();
142 pValues[SCINPUTOPT_SORT_REF_UPDATE] <<= GetSortRefUpdate();
143 pValues[SCINPUTOPT_MARKHEADER] <<= GetMarkHeader();
144 pValues[SCINPUTOPT_USETABCOL] <<= GetUseTabCol();
145 pValues[SCINPUTOPT_REPLCELLSWARN] <<= GetReplaceCellsWarn();
146 pValues[SCINPUTOPT_LEGACY_CELL_SELECTION] <<= GetLegacyCellSelection();
147 pValues[SCINPUTOPT_ENTER_PASTE_MODE] <<= GetEnterPasteMode();
148 pValues[SCINPUTOPT_WARNACTIVESHEET] <<= GetWarnActiveSheet();
149 PutProperties(aNames, aValues);
152 void ScInputCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ )
154 ReadCfg();
157 void ScInputCfg::SetOptions( const ScInputOptions& rNew )
159 *static_cast<ScInputOptions*>(this) = rNew;
160 SetModified();
161 Commit();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */