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