Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / tool / inputopt.cxx
blobe36cd8550e0674cf664eff17731f9be935cb9642
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>
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"
31 using namespace utl;
32 using namespace com::sun::star::uno;
34 // ScInputOptions - input options
36 ScInputOptions::ScInputOptions()
38 SetDefaults();
41 ScInputOptions::ScInputOptions( const ScInputOptions& rCpy )
43 *this = rCpy;
46 ScInputOptions::~ScInputOptions()
50 void ScInputOptions::SetDefaults()
52 nMoveDir = DIR_BOTTOM;
53 bMoveSelection = sal_True;
54 bEnterEdit = false;
55 bExtendFormat = false;
56 bRangeFinder = sal_True;
57 bExpandRefs = false;
58 bMarkHeader = sal_True;
59 bUseTabCol = false;
60 bTextWysiwyg = false;
61 bReplCellsWarn = sal_True;
62 bLegacyCellSelection = false;
65 const ScInputOptions& ScInputOptions::operator=( const ScInputOptions& rCpy )
67 nMoveDir = rCpy.nMoveDir;
68 bMoveSelection = rCpy.bMoveSelection;
69 bEnterEdit = rCpy.bEnterEdit;
70 bExtendFormat = rCpy.bExtendFormat;
71 bRangeFinder = rCpy.bRangeFinder;
72 bExpandRefs = rCpy.bExpandRefs;
73 bMarkHeader = rCpy.bMarkHeader;
74 bUseTabCol = rCpy.bUseTabCol;
75 bTextWysiwyg = rCpy.bTextWysiwyg;
76 bReplCellsWarn = rCpy.bReplCellsWarn;
77 bLegacyCellSelection = rCpy.bLegacyCellSelection;
79 return *this;
82 // Config Item containing input options
84 #define CFGPATH_INPUT "Office.Calc/Input"
86 #define SCINPUTOPT_MOVEDIR 0
87 #define SCINPUTOPT_MOVESEL 1
88 #define SCINPUTOPT_EDTEREDIT 2
89 #define SCINPUTOPT_EXTENDFMT 3
90 #define SCINPUTOPT_RANGEFIND 4
91 #define SCINPUTOPT_EXPANDREFS 5
92 #define SCINPUTOPT_MARKHEADER 6
93 #define SCINPUTOPT_USETABCOL 7
94 #define SCINPUTOPT_TEXTWYSIWYG 8
95 #define SCINPUTOPT_REPLCELLSWARN 9
96 #define SCINPUTOPT_LEGACY_CELL_SELECTION 10
97 #define SCINPUTOPT_COUNT 11
99 Sequence<OUString> ScInputCfg::GetPropertyNames()
101 static const char* aPropNames[] =
103 "MoveSelectionDirection", // SCINPUTOPT_MOVEDIR
104 "MoveSelection", // SCINPUTOPT_MOVESEL
105 "SwitchToEditMode", // SCINPUTOPT_EDTEREDIT
106 "ExpandFormatting", // SCINPUTOPT_EXTENDFMT
107 "ShowReference", // SCINPUTOPT_RANGEFIND
108 "ExpandReference", // SCINPUTOPT_EXPANDREFS
109 "HighlightSelection", // SCINPUTOPT_MARKHEADER
110 "UseTabCol", // SCINPUTOPT_USETABCOL
111 "UsePrinterMetrics", // SCINPUTOPT_TEXTWYSIWYG
112 "ReplaceCellsWarning", // SCINPUTOPT_REPLCELLSWARN
113 "LegacyCellSelection" // SCINPUTOPT_LEGACY_CELL_SELECTION
115 Sequence<OUString> aNames(SCINPUTOPT_COUNT);
116 OUString* pNames = aNames.getArray();
117 for(int i = 0; i < SCINPUTOPT_COUNT; i++)
118 pNames[i] = OUString::createFromAscii(aPropNames[i]);
120 return aNames;
123 ScInputCfg::ScInputCfg() :
124 ConfigItem( OUString( CFGPATH_INPUT ) )
126 Sequence<OUString> aNames = GetPropertyNames();
127 Sequence<Any> aValues = GetProperties(aNames);
128 EnableNotification(aNames);
129 const Any* pValues = aValues.getConstArray();
130 OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
131 if(aValues.getLength() == aNames.getLength())
133 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
135 OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
136 if(pValues[nProp].hasValue())
138 sal_Int32 nIntVal = 0;
139 switch(nProp)
141 case SCINPUTOPT_MOVEDIR:
142 if ( pValues[nProp] >>= nIntVal )
143 SetMoveDir( (sal_uInt16)nIntVal );
144 break;
145 case SCINPUTOPT_MOVESEL:
146 SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
147 break;
148 case SCINPUTOPT_EDTEREDIT:
149 SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
150 break;
151 case SCINPUTOPT_EXTENDFMT:
152 SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
153 break;
154 case SCINPUTOPT_RANGEFIND:
155 SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
156 break;
157 case SCINPUTOPT_EXPANDREFS:
158 SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
159 break;
160 case SCINPUTOPT_MARKHEADER:
161 SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
162 break;
163 case SCINPUTOPT_USETABCOL:
164 SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
165 break;
166 case SCINPUTOPT_TEXTWYSIWYG:
167 SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
168 break;
169 case SCINPUTOPT_REPLCELLSWARN:
170 SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
171 break;
172 case SCINPUTOPT_LEGACY_CELL_SELECTION:
173 SetLegacyCellSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
174 break;
181 void ScInputCfg::Commit()
183 Sequence<OUString> aNames = GetPropertyNames();
184 Sequence<Any> aValues(aNames.getLength());
185 Any* pValues = aValues.getArray();
187 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
189 switch(nProp)
191 case SCINPUTOPT_MOVEDIR:
192 pValues[nProp] <<= (sal_Int32) GetMoveDir();
193 break;
194 case SCINPUTOPT_MOVESEL:
195 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMoveSelection() );
196 break;
197 case SCINPUTOPT_EDTEREDIT:
198 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetEnterEdit() );
199 break;
200 case SCINPUTOPT_EXTENDFMT:
201 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExtendFormat() );
202 break;
203 case SCINPUTOPT_RANGEFIND:
204 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetRangeFinder() );
205 break;
206 case SCINPUTOPT_EXPANDREFS:
207 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExpandRefs() );
208 break;
209 case SCINPUTOPT_MARKHEADER:
210 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMarkHeader() );
211 break;
212 case SCINPUTOPT_USETABCOL:
213 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetUseTabCol() );
214 break;
215 case SCINPUTOPT_TEXTWYSIWYG:
216 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetTextWysiwyg() );
217 break;
218 case SCINPUTOPT_REPLCELLSWARN:
219 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetReplaceCellsWarn() );
220 break;
221 case SCINPUTOPT_LEGACY_CELL_SELECTION:
222 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetLegacyCellSelection() );
223 break;
226 PutProperties(aNames, aValues);
229 void ScInputCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ )
231 OSL_FAIL("properties have been changed");
234 void ScInputCfg::SetOptions( const ScInputOptions& rNew )
236 *(ScInputOptions*)this = rNew;
237 SetModified();
240 void ScInputCfg::OptionsChanged()
242 SetModified();
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */