Resolves: tdf#162093 TableRef item specifier may occur standalone
[LibreOffice.git] / sc / source / core / tool / inputopt.cxx
blobbdf49863919c4799e217ac06a7157b5f248be5a5
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)
50 // Config Item containing input options
52 constexpr OUStringLiteral CFGPATH_INPUT = u"Office.Calc/Input";
54 #define SCINPUTOPT_MOVEDIR 0
55 #define SCINPUTOPT_MOVESEL 1
56 #define SCINPUTOPT_EDTEREDIT 2
57 #define SCINPUTOPT_EXTENDFMT 3
58 #define SCINPUTOPT_RANGEFIND 4
59 #define SCINPUTOPT_EXPANDREFS 5
60 #define SCINPUTOPT_SORT_REF_UPDATE 6
61 #define SCINPUTOPT_MARKHEADER 7
62 #define SCINPUTOPT_USETABCOL 8
63 #define SCINPUTOPT_REPLCELLSWARN 9
64 #define SCINPUTOPT_LEGACY_CELL_SELECTION 10
65 #define SCINPUTOPT_ENTER_PASTE_MODE 11
67 Sequence<OUString> ScInputCfg::GetPropertyNames()
69 return {u"MoveSelectionDirection"_ustr, // SCINPUTOPT_MOVEDIR
70 u"MoveSelection"_ustr, // SCINPUTOPT_MOVESEL
71 u"SwitchToEditMode"_ustr, // SCINPUTOPT_EDTEREDIT
72 u"ExpandFormatting"_ustr, // SCINPUTOPT_EXTENDFMT
73 u"ShowReference"_ustr, // SCINPUTOPT_RANGEFIND
74 u"ExpandReference"_ustr, // SCINPUTOPT_EXPANDREFS
75 u"UpdateReferenceOnSort"_ustr, // SCINPUTOPT_SORT_REF_UPDATE
76 u"HighlightSelection"_ustr, // SCINPUTOPT_MARKHEADER
77 u"UseTabCol"_ustr, // SCINPUTOPT_USETABCOL
78 u"ReplaceCellsWarning"_ustr, // SCINPUTOPT_REPLCELLSWARN
79 u"LegacyCellSelection"_ustr, // SCINPUTOPT_LEGACY_CELL_SELECTION
80 u"EnterPasteMode"_ustr}; // SCINPUTOPT_ENTER_PASTE_MODE
83 ScInputCfg::ScInputCfg() :
84 ConfigItem( CFGPATH_INPUT )
86 Sequence<OUString> aNames = GetPropertyNames();
87 EnableNotification(aNames);
88 ReadCfg();
91 void ScInputCfg::ReadCfg()
93 const Sequence<OUString> aNames = GetPropertyNames();
94 const Sequence<Any> aValues = GetProperties(aNames);
95 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
96 if(aValues.getLength() != aNames.getLength())
97 return;
99 if (sal_Int32 nVal; aValues[SCINPUTOPT_MOVEDIR] >>= nVal)
100 SetMoveDir(static_cast<sal_uInt16>(nVal));
101 if (bool bVal; aValues[SCINPUTOPT_MOVESEL] >>= bVal)
102 SetMoveSelection(bVal);
103 if (bool bVal; aValues[SCINPUTOPT_EDTEREDIT] >>= bVal)
104 SetEnterEdit(bVal);
105 if (bool bVal; aValues[SCINPUTOPT_EXTENDFMT] >>= bVal)
106 SetExtendFormat(bVal);
107 if (bool bVal; aValues[SCINPUTOPT_RANGEFIND] >>= bVal)
108 SetRangeFinder(bVal);
109 if (bool bVal; aValues[SCINPUTOPT_EXPANDREFS] >>= bVal)
110 SetExpandRefs(bVal);
111 if (bool bVal; aValues[SCINPUTOPT_SORT_REF_UPDATE] >>= bVal)
112 SetSortRefUpdate(bVal);
113 if (bool bVal; aValues[SCINPUTOPT_MARKHEADER] >>= bVal)
114 SetMarkHeader(bVal);
115 if (bool bVal; aValues[SCINPUTOPT_USETABCOL] >>= bVal)
116 SetUseTabCol(bVal);
117 if (bool bVal; aValues[SCINPUTOPT_REPLCELLSWARN] >>= bVal)
118 SetReplaceCellsWarn(bVal);
119 if (bool bVal; aValues[SCINPUTOPT_LEGACY_CELL_SELECTION] >>= bVal)
120 SetLegacyCellSelection(bVal);
121 if (bool bVal; aValues[SCINPUTOPT_ENTER_PASTE_MODE] >>= bVal)
122 SetEnterPasteMode(bVal);
125 void ScInputCfg::ImplCommit()
127 Sequence<OUString> aNames = GetPropertyNames();
128 Sequence<Any> aValues(aNames.getLength());
129 Any* pValues = aValues.getArray();
131 pValues[SCINPUTOPT_MOVEDIR] <<= static_cast<sal_Int32>(GetMoveDir());
132 pValues[SCINPUTOPT_MOVESEL] <<= GetMoveSelection();
133 pValues[SCINPUTOPT_EDTEREDIT] <<= GetEnterEdit();
134 pValues[SCINPUTOPT_EXTENDFMT] <<= GetExtendFormat();
135 pValues[SCINPUTOPT_RANGEFIND] <<= GetRangeFinder();
136 pValues[SCINPUTOPT_EXPANDREFS] <<= GetExpandRefs();
137 pValues[SCINPUTOPT_SORT_REF_UPDATE] <<= GetSortRefUpdate();
138 pValues[SCINPUTOPT_MARKHEADER] <<= GetMarkHeader();
139 pValues[SCINPUTOPT_USETABCOL] <<= GetUseTabCol();
140 pValues[SCINPUTOPT_REPLCELLSWARN] <<= GetReplaceCellsWarn();
141 pValues[SCINPUTOPT_LEGACY_CELL_SELECTION] <<= GetLegacyCellSelection();
142 pValues[SCINPUTOPT_ENTER_PASTE_MODE] <<= GetEnterPasteMode();
143 PutProperties(aNames, aValues);
146 void ScInputCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ )
148 ReadCfg();
151 void ScInputCfg::SetOptions( const ScInputOptions& rNew )
153 *static_cast<ScInputOptions*>(this) = rNew;
154 SetModified();
155 Commit();
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */