LCOV - code coverage report
Current view: top level - sc/source/core/tool - inputopt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 110 115 95.7 %
Date: 2014-04-11 Functions: 9 11 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/uno/Any.hxx>
      21             : #include <com/sun/star/uno/Sequence.hxx>
      22             : 
      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"
      30             : 
      31             : using namespace utl;
      32             : using namespace com::sun::star::uno;
      33             : 
      34             : // ScInputOptions - input options
      35             : 
      36          31 : ScInputOptions::ScInputOptions()
      37             : {
      38          31 :     SetDefaults();
      39          31 : }
      40             : 
      41         292 : ScInputOptions::ScInputOptions( const ScInputOptions& rCpy )
      42             : {
      43         292 :     *this = rCpy;
      44         292 : }
      45             : 
      46         301 : ScInputOptions::~ScInputOptions()
      47             : {
      48         301 : }
      49             : 
      50          31 : void ScInputOptions::SetDefaults()
      51             : {
      52          31 :     nMoveDir        = DIR_BOTTOM;
      53          31 :     bMoveSelection  = true;
      54          31 :     bEnterEdit      = false;
      55          31 :     bExtendFormat   = false;
      56          31 :     bRangeFinder    = true;
      57          31 :     bExpandRefs     = false;
      58          31 :     bMarkHeader     = true;
      59          31 :     bUseTabCol      = false;
      60          31 :     bTextWysiwyg    = false;
      61          31 :     bReplCellsWarn  = true;
      62          31 :     bLegacyCellSelection = false;
      63          31 : }
      64             : 
      65         354 : const ScInputOptions& ScInputOptions::operator=( const ScInputOptions& rCpy )
      66             : {
      67         354 :     nMoveDir        = rCpy.nMoveDir;
      68         354 :     bMoveSelection  = rCpy.bMoveSelection;
      69         354 :     bEnterEdit      = rCpy.bEnterEdit;
      70         354 :     bExtendFormat   = rCpy.bExtendFormat;
      71         354 :     bRangeFinder    = rCpy.bRangeFinder;
      72         354 :     bExpandRefs     = rCpy.bExpandRefs;
      73         354 :     bMarkHeader     = rCpy.bMarkHeader;
      74         354 :     bUseTabCol      = rCpy.bUseTabCol;
      75         354 :     bTextWysiwyg    = rCpy.bTextWysiwyg;
      76         354 :     bReplCellsWarn  = rCpy.bReplCellsWarn;
      77         354 :     bLegacyCellSelection = rCpy.bLegacyCellSelection;
      78             : 
      79         354 :     return *this;
      80             : }
      81             : 
      82             : //  Config Item containing input options
      83             : 
      84             : #define CFGPATH_INPUT           "Office.Calc/Input"
      85             : 
      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
      98             : 
      99          32 : Sequence<OUString> ScInputCfg::GetPropertyNames()
     100             : {
     101             :     static const char* aPropNames[] =
     102             :     {
     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
     114             :     };
     115          32 :     Sequence<OUString> aNames(SCINPUTOPT_COUNT);
     116          32 :     OUString* pNames = aNames.getArray();
     117         384 :     for(int i = 0; i < SCINPUTOPT_COUNT; i++)
     118         352 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     119             : 
     120          32 :     return aNames;
     121             : }
     122             : 
     123          31 : ScInputCfg::ScInputCfg() :
     124          31 :     ConfigItem( OUString( CFGPATH_INPUT ) )
     125             : {
     126          31 :     Sequence<OUString> aNames = GetPropertyNames();
     127          62 :     Sequence<Any> aValues = GetProperties(aNames);
     128          31 :     EnableNotification(aNames);
     129          31 :     const Any* pValues = aValues.getConstArray();
     130             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
     131          31 :     if(aValues.getLength() == aNames.getLength())
     132             :     {
     133         372 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     134             :         {
     135             :             OSL_ENSURE(pValues[nProp].hasValue(), "property value missing");
     136         341 :             if(pValues[nProp].hasValue())
     137             :             {
     138         341 :                 sal_Int32 nIntVal = 0;
     139         341 :                 switch(nProp)
     140             :                 {
     141             :                     case SCINPUTOPT_MOVEDIR:
     142          31 :                         if ( pValues[nProp] >>= nIntVal )
     143          31 :                             SetMoveDir( (sal_uInt16)nIntVal );
     144          31 :                         break;
     145             :                     case SCINPUTOPT_MOVESEL:
     146          31 :                         SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     147          31 :                         break;
     148             :                     case SCINPUTOPT_EDTEREDIT:
     149          31 :                         SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     150          31 :                         break;
     151             :                     case SCINPUTOPT_EXTENDFMT:
     152          31 :                         SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     153          31 :                         break;
     154             :                     case SCINPUTOPT_RANGEFIND:
     155          31 :                         SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     156          31 :                         break;
     157             :                     case SCINPUTOPT_EXPANDREFS:
     158          31 :                         SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     159          31 :                         break;
     160             :                     case SCINPUTOPT_MARKHEADER:
     161          31 :                         SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     162          31 :                         break;
     163             :                     case SCINPUTOPT_USETABCOL:
     164          31 :                         SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     165          31 :                         break;
     166             :                     case SCINPUTOPT_TEXTWYSIWYG:
     167          31 :                         SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     168          31 :                         break;
     169             :                     case SCINPUTOPT_REPLCELLSWARN:
     170          31 :                         SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     171          31 :                         break;
     172             :                     case SCINPUTOPT_LEGACY_CELL_SELECTION:
     173          31 :                         SetLegacyCellSelection( ScUnoHelpFunctions::GetBoolFromAny( pValues[nProp] ) );
     174          31 :                         break;
     175             :                 }
     176             :             }
     177             :         }
     178          31 :     }
     179          31 : }
     180             : 
     181           1 : void ScInputCfg::Commit()
     182             : {
     183           1 :     Sequence<OUString> aNames = GetPropertyNames();
     184           2 :     Sequence<Any> aValues(aNames.getLength());
     185           1 :     Any* pValues = aValues.getArray();
     186             : 
     187          12 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     188             :     {
     189          11 :         switch(nProp)
     190             :         {
     191             :             case SCINPUTOPT_MOVEDIR:
     192           1 :                 pValues[nProp] <<= (sal_Int32) GetMoveDir();
     193           1 :                 break;
     194             :             case SCINPUTOPT_MOVESEL:
     195           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMoveSelection() );
     196           1 :                 break;
     197             :             case SCINPUTOPT_EDTEREDIT:
     198           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetEnterEdit() );
     199           1 :                 break;
     200             :             case SCINPUTOPT_EXTENDFMT:
     201           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExtendFormat() );
     202           1 :                 break;
     203             :             case SCINPUTOPT_RANGEFIND:
     204           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetRangeFinder() );
     205           1 :                 break;
     206             :             case SCINPUTOPT_EXPANDREFS:
     207           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetExpandRefs() );
     208           1 :                 break;
     209             :             case SCINPUTOPT_MARKHEADER:
     210           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetMarkHeader() );
     211           1 :                 break;
     212             :             case SCINPUTOPT_USETABCOL:
     213           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetUseTabCol() );
     214           1 :                 break;
     215             :             case SCINPUTOPT_TEXTWYSIWYG:
     216           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetTextWysiwyg() );
     217           1 :                 break;
     218             :             case SCINPUTOPT_REPLCELLSWARN:
     219           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetReplaceCellsWarn() );
     220           1 :                 break;
     221             :             case SCINPUTOPT_LEGACY_CELL_SELECTION:
     222           1 :                 ScUnoHelpFunctions::SetBoolInAny( pValues[nProp], GetLegacyCellSelection() );
     223           1 :                 break;
     224             :         }
     225             :     }
     226           2 :     PutProperties(aNames, aValues);
     227           1 : }
     228             : 
     229           0 : void ScInputCfg::Notify( const Sequence<OUString>& /* aPropertyNames */ )
     230             : {
     231             :     OSL_FAIL("properties have been changed");
     232           0 : }
     233             : 
     234          62 : void ScInputCfg::SetOptions( const ScInputOptions& rNew )
     235             : {
     236          62 :     *(ScInputOptions*)this = rNew;
     237          62 :     SetModified();
     238          62 : }
     239             : 
     240           0 : void ScInputCfg::OptionsChanged()
     241             : {
     242           0 :     SetModified();
     243           0 : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10