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

Generated by: LCOV version 1.10