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