LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/optdlg - tpformula.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 188 0.0 %
Date: 2012-12-17 Functions: 0 21 0.0 %
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             : #undef SC_DLLIMPLEMENTATION
      21             : 
      22             : //------------------------------------------------------------------
      23             : 
      24             : #include <scmod.hxx>
      25             : #include <svl/eitem.hxx>
      26             : #include <svl/stritem.hxx>
      27             : #include "tpformula.hxx"
      28             : #include "formulaopt.hxx"
      29             : #include "optdlg.hrc"
      30             : #include "scresid.hxx"
      31             : #include "formula/grammar.hxx"
      32             : #include "calcoptionsdlg.hxx"
      33             : #include "vcl/msgbox.hxx"
      34             : 
      35             : #include <unotools/localedatawrapper.hxx>
      36             : 
      37             : #include <com/sun/star/lang/Locale.hpp>
      38             : #include <com/sun/star/i18n/LocaleDataItem.hpp>
      39             : 
      40             : using ::rtl::OUString;
      41             : using ::com::sun::star::lang::Locale;
      42             : using ::com::sun::star::i18n::LocaleDataItem;
      43             : 
      44           0 : ScTpFormulaOptions::ScTpFormulaOptions(Window* pParent, const SfxItemSet& rCoreAttrs) :
      45             :     SfxTabPage(pParent, ScResId(RID_SCPAGE_FORMULA), rCoreAttrs),
      46             : 
      47             :     maFlFormulaOpt(this, ScResId(FL_FORMULA_OPTIONS)),
      48             :     maFtFormulaSyntax(this, ScResId(FT_FORMULA_SYNTAX)),
      49             :     maLbFormulaSyntax(this, ScResId(LB_FORMULA_SYNTAX)),
      50             :     maCbEnglishFuncName(this, ScResId(CB_ENGLISH_FUNC_NAME)),
      51             :     maFlFormulaSeps(this, ScResId(FL_FORMULA_SEPS)),
      52             :     maFtSepFuncArg(this, ScResId(FT_FORMULA_SEP_ARG)),
      53             :     maEdSepFuncArg(this, ScResId(ED_FORMULA_SEP_ARG)),
      54             :     maFtSepArrayCol(this, ScResId(FT_FORMULA_SEP_ARRAY_C)),
      55             :     maEdSepArrayCol(this, ScResId(ED_FORMULA_SEP_ARRAY_C)),
      56             :     maFtSepArrayRow(this, ScResId(FT_FORMULA_SEP_ARRAY_R)),
      57             :     maEdSepArrayRow(this, ScResId(ED_FORMULA_SEP_ARRAY_R)),
      58             :     maBtnSepReset(this, ScResId(BTN_FORMULA_SEP_RESET)),
      59             :     maFlCustomCalcOpt(this, ScResId(FL_CUSTOM_CALC_OPTIONS)),
      60             :     maBtnCustomCalcDefault(this, ScResId(BTN_CUSTOM_CALC_DEFAULT)),
      61             :     maBtnCustomCalcCustom(this, ScResId(BTN_CUSTOM_CALC_CUSTOM)),
      62             :     maBtnCustomCalcDetails(this, ScResId(BTN_CUSTOM_CALC_DETAILS)),
      63             :     maFlRecalcOptions(this, ScResId(FL_RECALC_OPTIONS)),
      64             :     maLbOOXMLRecalcOptions( this, ScResId(LB_OOXML_RECALC)),
      65           0 :     mnDecSep(0)
      66             : {
      67           0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString());
      68           0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString());
      69           0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString());
      70             : 
      71           0 :     FreeResource();
      72             : 
      73           0 :     Link aLink = LINK( this, ScTpFormulaOptions, ButtonHdl );
      74           0 :     maBtnSepReset.SetClickHdl(aLink);
      75           0 :     maBtnCustomCalcDefault.SetClickHdl(aLink);
      76           0 :     maBtnCustomCalcCustom.SetClickHdl(aLink);
      77           0 :     maBtnCustomCalcDetails.SetClickHdl(aLink);
      78             : 
      79           0 :     aLink = LINK( this, ScTpFormulaOptions, SepModifyHdl );
      80           0 :     maEdSepFuncArg.SetModifyHdl(aLink);
      81           0 :     maEdSepArrayCol.SetModifyHdl(aLink);
      82           0 :     maEdSepArrayRow.SetModifyHdl(aLink);
      83             : 
      84           0 :     aLink = LINK( this, ScTpFormulaOptions, SepEditOnFocusHdl );
      85           0 :     maEdSepFuncArg.SetGetFocusHdl(aLink);
      86           0 :     maEdSepArrayCol.SetGetFocusHdl(aLink);
      87           0 :     maEdSepArrayRow.SetGetFocusHdl(aLink);
      88             : 
      89             :     // Get the decimal separator for current locale.
      90           0 :     rtl::OUString aSep = ScGlobal::GetpLocaleData()->getNumDecimalSep();
      91           0 :     mnDecSep = aSep.isEmpty() ? sal_Unicode('.') : aSep[0];
      92           0 : }
      93             : 
      94           0 : ScTpFormulaOptions::~ScTpFormulaOptions()
      95             : {
      96           0 : }
      97             : 
      98           0 : void ScTpFormulaOptions::ResetSeparators()
      99             : {
     100           0 :     rtl::OUString aFuncArg, aArrayCol, aArrayRow;
     101           0 :     ScFormulaOptions::GetDefaultFormulaSeparators(aFuncArg, aArrayCol, aArrayRow);
     102           0 :     maEdSepFuncArg.SetText(aFuncArg);
     103           0 :     maEdSepArrayCol.SetText(aArrayCol);
     104           0 :     maEdSepArrayRow.SetText(aArrayRow);
     105           0 : }
     106             : 
     107           0 : void ScTpFormulaOptions::OnFocusSeparatorInput(Edit* pEdit)
     108             : {
     109           0 :     if (!pEdit)
     110           0 :         return;
     111             : 
     112             :     // Make sure the entire text is selected.
     113           0 :     xub_StrLen nLen = pEdit->GetText().Len();
     114           0 :     Selection aSel(0, nLen);
     115           0 :     pEdit->SetSelection(aSel);
     116           0 :     maOldSepValue = pEdit->GetText();
     117             : }
     118             : 
     119           0 : void ScTpFormulaOptions::UpdateCustomCalcRadioButtons(bool bDefault)
     120             : {
     121           0 :     if (bDefault)
     122             :     {
     123           0 :         maBtnCustomCalcDefault.Check(true);
     124           0 :         maBtnCustomCalcCustom.Check(false);
     125           0 :         maBtnCustomCalcDetails.Disable();
     126             :     }
     127             :     else
     128             :     {
     129           0 :         maBtnCustomCalcDefault.Check(false);
     130           0 :         maBtnCustomCalcCustom.Check(true);
     131           0 :         maBtnCustomCalcDetails.Enable();
     132             :     }
     133           0 : }
     134             : 
     135           0 : void ScTpFormulaOptions::LaunchCustomCalcSettings()
     136             : {
     137           0 :     ScCalcOptionsDialog aDlg(this, maCurrentConfig);
     138           0 :     if (aDlg.Execute() == RET_OK)
     139             :     {
     140           0 :         maCurrentConfig = aDlg.GetConfig();
     141           0 :     }
     142           0 : }
     143             : 
     144           0 : bool ScTpFormulaOptions::IsValidSeparator(const OUString& rSep) const
     145             : {
     146           0 :     if (rSep.getLength() != 1)
     147             :         // Must be one-character long.
     148           0 :         return false;
     149             : 
     150           0 :     if (rSep.compareToAscii("a") >= 0 && rSep.compareToAscii("z") <= 0)
     151           0 :         return false;
     152             : 
     153           0 :     if (rSep.compareToAscii("A") >= 0 && rSep.compareToAscii("Z") <= 0)
     154           0 :         return false;
     155             : 
     156           0 :     sal_Unicode c = rSep.getStr()[0];
     157           0 :     switch (c)
     158             :     {
     159             :         case '+':
     160             :         case '-':
     161             :         case '/':
     162             :         case '*':
     163             :         case '<':
     164             :         case '>':
     165             :         case '[':
     166             :         case ']':
     167             :         case '(':
     168             :         case ')':
     169             :         case '"':
     170             :         case '\'':
     171             :             // Disallowed characters.  Anything else we want to disallow ?
     172           0 :             return false;
     173             :     }
     174             : 
     175           0 :     if (c == mnDecSep)
     176             :         // decimal separator is not allowed.
     177           0 :         return false;
     178             : 
     179           0 :     return true;
     180             : }
     181             : 
     182           0 : bool ScTpFormulaOptions::IsValidSeparatorSet() const
     183             : {
     184             :     // Make sure the column and row separators are different.
     185           0 :     String aColStr = maEdSepArrayCol.GetText();
     186           0 :     String aRowStr = maEdSepArrayRow.GetText();
     187           0 :     if (aColStr == aRowStr)
     188           0 :         return false;
     189             : 
     190           0 :     return true;
     191             : }
     192             : 
     193           0 : IMPL_LINK( ScTpFormulaOptions, ButtonHdl, Button*, pBtn )
     194             : {
     195           0 :     if (pBtn == &maBtnSepReset)
     196           0 :         ResetSeparators();
     197           0 :     else if (pBtn == &maBtnCustomCalcDefault)
     198           0 :         UpdateCustomCalcRadioButtons(true);
     199           0 :     else if (pBtn == &maBtnCustomCalcCustom)
     200           0 :         UpdateCustomCalcRadioButtons(false);
     201           0 :     else if (pBtn == &maBtnCustomCalcDetails)
     202           0 :         LaunchCustomCalcSettings();
     203             : 
     204           0 :     return 0;
     205             : }
     206             : 
     207           0 : IMPL_LINK( ScTpFormulaOptions, SepModifyHdl, Edit*, pEdit )
     208             : {
     209           0 :     if (!pEdit)
     210           0 :         return 0;
     211             : 
     212           0 :     String aStr = pEdit->GetText();
     213           0 :     if (aStr.Len() > 1)
     214             :     {
     215             :         // In case the string is more than one character long, only grab the
     216             :         // first character.
     217           0 :         aStr = aStr.Copy(0, 1);
     218           0 :         pEdit->SetText(aStr);
     219             :     }
     220             : 
     221           0 :     if ((!IsValidSeparator(aStr) || !IsValidSeparatorSet()) && !maOldSepValue.isEmpty())
     222             :         // Invalid separator.  Restore the old value.
     223           0 :         pEdit->SetText(maOldSepValue);
     224             : 
     225           0 :     OnFocusSeparatorInput(pEdit);
     226           0 :     return 0;
     227             : }
     228             : 
     229           0 : IMPL_LINK( ScTpFormulaOptions, SepEditOnFocusHdl, Edit*, pEdit )
     230             : {
     231           0 :     OnFocusSeparatorInput(pEdit);
     232           0 :     return 0;
     233             : }
     234             : 
     235           0 : SfxTabPage* ScTpFormulaOptions::Create(Window* pParent, const SfxItemSet& rCoreSet)
     236             : {
     237           0 :     return new ScTpFormulaOptions(pParent, rCoreSet);
     238             : }
     239             : 
     240           0 : sal_Bool ScTpFormulaOptions::FillItemSet(SfxItemSet& rCoreSet)
     241             : {
     242           0 :     bool bRet = false;
     243           0 :     ScFormulaOptions aOpt;
     244           0 :     sal_Bool bEnglishFuncName = maCbEnglishFuncName.IsChecked();
     245           0 :     sal_Int16 aSyntaxPos      = maLbFormulaSyntax.GetSelectEntryPos();
     246           0 :     OUString aSep             = maEdSepFuncArg.GetText();
     247           0 :     OUString aSepArrayCol     = maEdSepArrayCol.GetText();
     248           0 :     OUString aSepArrayRow     = maEdSepArrayRow.GetText();
     249           0 :     sal_Int16 aOOXMLRecalcMode = maLbOOXMLRecalcOptions.GetSelectEntryPos();
     250             : 
     251           0 :     if (maBtnCustomCalcDefault.IsChecked())
     252             :     {
     253             :         // When Default is selected, reset all the calc config settings to default.
     254           0 :         maCurrentConfig.reset();
     255             :     }
     256             : 
     257           0 :     if ( maLbFormulaSyntax.GetSavedValue() != aSyntaxPos
     258           0 :          || maCbEnglishFuncName.GetSavedValue() != bEnglishFuncName
     259           0 :          || static_cast<OUString>(maEdSepFuncArg.GetSavedValue()) != aSep
     260           0 :          || static_cast<OUString>(maEdSepArrayCol.GetSavedValue()) != aSepArrayCol
     261           0 :          || static_cast<OUString>(maEdSepArrayRow.GetSavedValue()) != aSepArrayRow
     262           0 :          || maLbOOXMLRecalcOptions.GetSavedValue() != aOOXMLRecalcMode
     263           0 :          || maSavedConfig != maCurrentConfig )
     264             :     {
     265           0 :         ::formula::FormulaGrammar::Grammar eGram = ::formula::FormulaGrammar::GRAM_DEFAULT;
     266             : 
     267           0 :         switch (aSyntaxPos)
     268             :         {
     269             :         case 0:
     270           0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE;
     271           0 :         break;
     272             :         case 1:
     273           0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1;
     274           0 :         break;
     275             :         case 2:
     276           0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1;
     277           0 :         break;
     278             :         }
     279             : 
     280           0 :         ScRecalcOptions eOOXMLRecalc = RECALC_ASK;
     281           0 :         switch (aOOXMLRecalcMode)
     282             :         {
     283             :             case 0:
     284           0 :                 eOOXMLRecalc = RECALC_ALWAYS;
     285           0 :                 break;
     286             :             case 1:
     287           0 :                 eOOXMLRecalc = RECALC_ASK;
     288           0 :                 break;
     289             :             case 2:
     290           0 :                 eOOXMLRecalc = RECALC_NEVER;
     291           0 :                 break;
     292             :         };
     293             : 
     294           0 :         aOpt.SetFormulaSyntax(eGram);
     295           0 :         aOpt.SetUseEnglishFuncName(bEnglishFuncName);
     296           0 :         aOpt.SetFormulaSepArg(aSep);
     297           0 :         aOpt.SetFormulaSepArrayCol(aSepArrayCol);
     298           0 :         aOpt.SetFormulaSepArrayRow(aSepArrayRow);
     299           0 :         aOpt.SetCalcConfig(maCurrentConfig);
     300           0 :         aOpt.SetOOXMLRecalcOptions(eOOXMLRecalc);
     301             : 
     302           0 :         rCoreSet.Put( ScTpFormulaItem( SID_SCFORMULAOPTIONS, aOpt ) );
     303           0 :         bRet = true;
     304             :     }
     305           0 :     return bRet;
     306             : }
     307             : 
     308           0 : void ScTpFormulaOptions::Reset(const SfxItemSet& rCoreSet)
     309             : {
     310           0 :     ScFormulaOptions aOpt;
     311           0 :     const SfxPoolItem* pItem = NULL;
     312             : 
     313           0 :     if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCFORMULAOPTIONS, false , &pItem))
     314           0 :         aOpt = ((const ScTpFormulaItem*)pItem)->GetFormulaOptions();
     315             : 
     316             :     // formula grammar.
     317           0 :     ::formula::FormulaGrammar::Grammar eGram = aOpt.GetFormulaSyntax();
     318             : 
     319           0 :     switch (eGram)
     320             :     {
     321             :     case ::formula::FormulaGrammar::GRAM_NATIVE:
     322           0 :         maLbFormulaSyntax.SelectEntryPos(0);
     323           0 :         break;
     324             :     case ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1:
     325           0 :         maLbFormulaSyntax.SelectEntryPos(1);
     326           0 :         break;
     327             :     case ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1:
     328           0 :         maLbFormulaSyntax.SelectEntryPos(2);
     329           0 :         break;
     330             :     default:
     331           0 :         maLbFormulaSyntax.SelectEntryPos(0);
     332             :     }
     333             : 
     334           0 :     maLbFormulaSyntax.SaveValue();
     335             : 
     336           0 :     ScRecalcOptions eOOXMLRecalc = aOpt.GetOOXMLRecalcOptions();
     337             : 
     338           0 :     switch (eOOXMLRecalc)
     339             :     {
     340             :         case RECALC_ALWAYS:
     341           0 :             maLbOOXMLRecalcOptions.SelectEntryPos(0);
     342           0 :             break;
     343             :         case RECALC_ASK:
     344           0 :             maLbOOXMLRecalcOptions.SelectEntryPos(1);
     345           0 :             break;
     346             :         case RECALC_NEVER:
     347           0 :             maLbOOXMLRecalcOptions.SelectEntryPos(2);
     348           0 :             break;
     349             :     }
     350             : 
     351           0 :     maLbOOXMLRecalcOptions.SaveValue();
     352             : 
     353             :     // english function name.
     354           0 :     maCbEnglishFuncName.Check( aOpt.GetUseEnglishFuncName() );
     355           0 :     maCbEnglishFuncName.SaveValue();
     356             : 
     357             :     // Separators
     358           0 :     OUString aSep = aOpt.GetFormulaSepArg();
     359           0 :     OUString aSepArrayRow = aOpt.GetFormulaSepArrayRow();
     360           0 :     OUString aSepArrayCol = aOpt.GetFormulaSepArrayCol();
     361             : 
     362           0 :     if (aSep.getLength() == 1 && aSepArrayRow.getLength() == 1 && aSepArrayCol.getLength() == 1)
     363             :     {
     364             :         // Each separator must be one character long.
     365           0 :         maEdSepFuncArg.SetText(aSep);
     366           0 :         maEdSepArrayCol.SetText(aSepArrayCol);
     367           0 :         maEdSepArrayRow.SetText(aSepArrayRow);
     368             : 
     369           0 :         maEdSepFuncArg.SaveValue();
     370           0 :         maEdSepArrayCol.SaveValue();
     371           0 :         maEdSepArrayRow.SaveValue();
     372             :     }
     373             :     else
     374           0 :         ResetSeparators();
     375             : 
     376             :     // detailed calc settings.
     377           0 :     ScFormulaOptions aDefaults;
     378             : 
     379           0 :     maSavedConfig = aOpt.GetCalcConfig();
     380           0 :     bool bDefault = aDefaults.GetCalcConfig() == maSavedConfig;
     381           0 :     UpdateCustomCalcRadioButtons(bDefault);
     382             : 
     383           0 :     maCurrentConfig = maSavedConfig;
     384           0 : }
     385             : 
     386           0 : int ScTpFormulaOptions::DeactivatePage(SfxItemSet* /*pSet*/)
     387             : {
     388             :     // What's this method for ?
     389           0 :     return KEEP_PAGE;
     390           0 : }
     391             : 
     392             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10