LCOV - code coverage report
Current view: top level - sc/source/ui/optdlg - tpformula.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 167 0.0 %
Date: 2012-08-25 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2010 Novell, Inc.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #undef SC_DLLIMPLEMENTATION
      31                 :            : 
      32                 :            : 
      33                 :            : 
      34                 :            : //------------------------------------------------------------------
      35                 :            : 
      36                 :            : #include <scmod.hxx>
      37                 :            : #include <svl/eitem.hxx>
      38                 :            : #include <svl/stritem.hxx>
      39                 :            : #include "tpformula.hxx"
      40                 :            : #include "formulaopt.hxx"
      41                 :            : #include "optdlg.hrc"
      42                 :            : #include "scresid.hxx"
      43                 :            : #include "formula/grammar.hxx"
      44                 :            : #include "calcoptionsdlg.hxx"
      45                 :            : #include "vcl/msgbox.hxx"
      46                 :            : 
      47                 :            : #include <unotools/localedatawrapper.hxx>
      48                 :            : 
      49                 :            : #include <com/sun/star/lang/Locale.hpp>
      50                 :            : #include <com/sun/star/i18n/LocaleDataItem.hpp>
      51                 :            : 
      52                 :            : using ::rtl::OUString;
      53                 :            : using ::com::sun::star::lang::Locale;
      54                 :            : using ::com::sun::star::i18n::LocaleDataItem;
      55                 :            : 
      56                 :          0 : ScTpFormulaOptions::ScTpFormulaOptions(Window* pParent, const SfxItemSet& rCoreAttrs) :
      57                 :            :     SfxTabPage(pParent, ScResId(RID_SCPAGE_FORMULA), rCoreAttrs),
      58                 :            : 
      59                 :            :     maFlFormulaOpt(this, ScResId(FL_FORMULA_OPTIONS)),
      60                 :            :     maFtFormulaSyntax(this, ScResId(FT_FORMULA_SYNTAX)),
      61                 :            :     maLbFormulaSyntax(this, ScResId(LB_FORMULA_SYNTAX)),
      62                 :            :     maCbEnglishFuncName(this, ScResId(CB_ENGLISH_FUNC_NAME)),
      63                 :            :     maFlFormulaSeps(this, ScResId(FL_FORMULA_SEPS)),
      64                 :            :     maFtSepFuncArg(this, ScResId(FT_FORMULA_SEP_ARG)),
      65                 :            :     maEdSepFuncArg(this, ScResId(ED_FORMULA_SEP_ARG)),
      66                 :            :     maFtSepArrayCol(this, ScResId(FT_FORMULA_SEP_ARRAY_C)),
      67                 :            :     maEdSepArrayCol(this, ScResId(ED_FORMULA_SEP_ARRAY_C)),
      68                 :            :     maFtSepArrayRow(this, ScResId(FT_FORMULA_SEP_ARRAY_R)),
      69                 :            :     maEdSepArrayRow(this, ScResId(ED_FORMULA_SEP_ARRAY_R)),
      70                 :            :     maBtnSepReset(this, ScResId(BTN_FORMULA_SEP_RESET)),
      71                 :            :     maFlCustomCalcOpt(this, ScResId(FL_CUSTOM_CALC_OPTIONS)),
      72                 :            :     maBtnCustomCalcDefault(this, ScResId(BTN_CUSTOM_CALC_DEFAULT)),
      73                 :            :     maBtnCustomCalcCustom(this, ScResId(BTN_CUSTOM_CALC_CUSTOM)),
      74                 :            :     maBtnCustomCalcDetails(this, ScResId(BTN_CUSTOM_CALC_DETAILS)),
      75                 :            : 
      76                 :          0 :     mnDecSep(0)
      77                 :            : {
      78                 :          0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString());
      79                 :          0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString());
      80                 :          0 :     maLbFormulaSyntax.InsertEntry(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString());
      81                 :            : 
      82                 :          0 :     FreeResource();
      83                 :            : 
      84                 :          0 :     Link aLink = LINK( this, ScTpFormulaOptions, ButtonHdl );
      85                 :          0 :     maBtnSepReset.SetClickHdl(aLink);
      86                 :          0 :     maBtnCustomCalcDefault.SetClickHdl(aLink);
      87                 :          0 :     maBtnCustomCalcCustom.SetClickHdl(aLink);
      88                 :          0 :     maBtnCustomCalcDetails.SetClickHdl(aLink);
      89                 :            : 
      90                 :          0 :     aLink = LINK( this, ScTpFormulaOptions, SepModifyHdl );
      91                 :          0 :     maEdSepFuncArg.SetModifyHdl(aLink);
      92                 :          0 :     maEdSepArrayCol.SetModifyHdl(aLink);
      93                 :          0 :     maEdSepArrayRow.SetModifyHdl(aLink);
      94                 :            : 
      95                 :          0 :     aLink = LINK( this, ScTpFormulaOptions, SepEditOnFocusHdl );
      96                 :          0 :     maEdSepFuncArg.SetGetFocusHdl(aLink);
      97                 :          0 :     maEdSepArrayCol.SetGetFocusHdl(aLink);
      98                 :          0 :     maEdSepArrayRow.SetGetFocusHdl(aLink);
      99                 :            : 
     100                 :            :     // Get the decimal separator for current locale.
     101                 :          0 :     rtl::OUString aSep = ScGlobal::GetpLocaleData()->getNumDecimalSep();
     102                 :          0 :     mnDecSep = aSep.isEmpty() ? sal_Unicode('.') : aSep[0];
     103                 :          0 : }
     104                 :            : 
     105                 :          0 : ScTpFormulaOptions::~ScTpFormulaOptions()
     106                 :            : {
     107                 :          0 : }
     108                 :            : 
     109                 :          0 : void ScTpFormulaOptions::ResetSeparators()
     110                 :            : {
     111                 :          0 :     rtl::OUString aFuncArg, aArrayCol, aArrayRow;
     112                 :          0 :     ScFormulaOptions::GetDefaultFormulaSeparators(aFuncArg, aArrayCol, aArrayRow);
     113                 :          0 :     maEdSepFuncArg.SetText(aFuncArg);
     114                 :          0 :     maEdSepArrayCol.SetText(aArrayCol);
     115                 :          0 :     maEdSepArrayRow.SetText(aArrayRow);
     116                 :          0 : }
     117                 :            : 
     118                 :          0 : void ScTpFormulaOptions::OnFocusSeparatorInput(Edit* pEdit)
     119                 :            : {
     120                 :          0 :     if (!pEdit)
     121                 :          0 :         return;
     122                 :            : 
     123                 :            :     // Make sure the entire text is selected.
     124                 :          0 :     xub_StrLen nLen = pEdit->GetText().Len();
     125                 :          0 :     Selection aSel(0, nLen);
     126                 :          0 :     pEdit->SetSelection(aSel);
     127                 :          0 :     maOldSepValue = pEdit->GetText();
     128                 :            : }
     129                 :            : 
     130                 :          0 : void ScTpFormulaOptions::UpdateCustomCalcRadioButtons(bool bDefault)
     131                 :            : {
     132                 :          0 :     if (bDefault)
     133                 :            :     {
     134                 :          0 :         maBtnCustomCalcDefault.Check(true);
     135                 :          0 :         maBtnCustomCalcCustom.Check(false);
     136                 :          0 :         maBtnCustomCalcDetails.Disable();
     137                 :            :     }
     138                 :            :     else
     139                 :            :     {
     140                 :          0 :         maBtnCustomCalcDefault.Check(false);
     141                 :          0 :         maBtnCustomCalcCustom.Check(true);
     142                 :          0 :         maBtnCustomCalcDetails.Enable();
     143                 :            :     }
     144                 :          0 : }
     145                 :            : 
     146                 :          0 : void ScTpFormulaOptions::LaunchCustomCalcSettings()
     147                 :            : {
     148                 :          0 :     ScCalcOptionsDialog aDlg(this, maCurrentConfig);
     149                 :          0 :     if (aDlg.Execute() == RET_OK)
     150                 :            :     {
     151                 :          0 :         maCurrentConfig = aDlg.GetConfig();
     152                 :          0 :     }
     153                 :          0 : }
     154                 :            : 
     155                 :          0 : bool ScTpFormulaOptions::IsValidSeparator(const OUString& rSep) const
     156                 :            : {
     157                 :          0 :     if (rSep.getLength() != 1)
     158                 :            :         // Must be one-character long.
     159                 :          0 :         return false;
     160                 :            : 
     161                 :          0 :     if (rSep.compareToAscii("a") >= 0 && rSep.compareToAscii("z") <= 0)
     162                 :          0 :         return false;
     163                 :            : 
     164                 :          0 :     if (rSep.compareToAscii("A") >= 0 && rSep.compareToAscii("Z") <= 0)
     165                 :          0 :         return false;
     166                 :            : 
     167                 :          0 :     sal_Unicode c = rSep.getStr()[0];
     168                 :          0 :     switch (c)
     169                 :            :     {
     170                 :            :         case '+':
     171                 :            :         case '-':
     172                 :            :         case '/':
     173                 :            :         case '*':
     174                 :            :         case '<':
     175                 :            :         case '>':
     176                 :            :         case '[':
     177                 :            :         case ']':
     178                 :            :         case '(':
     179                 :            :         case ')':
     180                 :            :         case '"':
     181                 :            :         case '\'':
     182                 :            :             // Disallowed characters.  Anything else we want to disallow ?
     183                 :          0 :             return false;
     184                 :            :     }
     185                 :            : 
     186                 :          0 :     if (c == mnDecSep)
     187                 :            :         // decimal separator is not allowed.
     188                 :          0 :         return false;
     189                 :            : 
     190                 :          0 :     return true;
     191                 :            : }
     192                 :            : 
     193                 :          0 : bool ScTpFormulaOptions::IsValidSeparatorSet() const
     194                 :            : {
     195                 :            :     // Make sure the column and row separators are different.
     196                 :          0 :     String aColStr = maEdSepArrayCol.GetText();
     197                 :          0 :     String aRowStr = maEdSepArrayRow.GetText();
     198                 :          0 :     if (aColStr == aRowStr)
     199                 :          0 :         return false;
     200                 :            : 
     201                 :          0 :     return true;
     202                 :            : }
     203                 :            : 
     204                 :          0 : IMPL_LINK( ScTpFormulaOptions, ButtonHdl, Button*, pBtn )
     205                 :            : {
     206                 :          0 :     if (pBtn == &maBtnSepReset)
     207                 :          0 :         ResetSeparators();
     208                 :          0 :     else if (pBtn == &maBtnCustomCalcDefault)
     209                 :          0 :         UpdateCustomCalcRadioButtons(true);
     210                 :          0 :     else if (pBtn == &maBtnCustomCalcCustom)
     211                 :          0 :         UpdateCustomCalcRadioButtons(false);
     212                 :          0 :     else if (pBtn == &maBtnCustomCalcDetails)
     213                 :          0 :         LaunchCustomCalcSettings();
     214                 :            : 
     215                 :          0 :     return 0;
     216                 :            : }
     217                 :            : 
     218                 :          0 : IMPL_LINK( ScTpFormulaOptions, SepModifyHdl, Edit*, pEdit )
     219                 :            : {
     220                 :          0 :     if (!pEdit)
     221                 :          0 :         return 0;
     222                 :            : 
     223                 :          0 :     String aStr = pEdit->GetText();
     224                 :          0 :     if (aStr.Len() > 1)
     225                 :            :     {
     226                 :            :         // In case the string is more than one character long, only grab the
     227                 :            :         // first character.
     228                 :          0 :         aStr = aStr.Copy(0, 1);
     229                 :          0 :         pEdit->SetText(aStr);
     230                 :            :     }
     231                 :            : 
     232                 :          0 :     if ((!IsValidSeparator(aStr) || !IsValidSeparatorSet()) && !maOldSepValue.isEmpty())
     233                 :            :         // Invalid separator.  Restore the old value.
     234                 :          0 :         pEdit->SetText(maOldSepValue);
     235                 :            : 
     236                 :          0 :     OnFocusSeparatorInput(pEdit);
     237                 :          0 :     return 0;
     238                 :            : }
     239                 :            : 
     240                 :          0 : IMPL_LINK( ScTpFormulaOptions, SepEditOnFocusHdl, Edit*, pEdit )
     241                 :            : {
     242                 :          0 :     OnFocusSeparatorInput(pEdit);
     243                 :          0 :     return 0;
     244                 :            : }
     245                 :            : 
     246                 :          0 : SfxTabPage* ScTpFormulaOptions::Create(Window* pParent, const SfxItemSet& rCoreSet)
     247                 :            : {
     248                 :          0 :     return new ScTpFormulaOptions(pParent, rCoreSet);
     249                 :            : }
     250                 :            : 
     251                 :          0 : sal_Bool ScTpFormulaOptions::FillItemSet(SfxItemSet& rCoreSet)
     252                 :            : {
     253                 :          0 :     bool bRet = false;
     254                 :          0 :     ScFormulaOptions aOpt;
     255                 :          0 :     sal_Bool bEnglishFuncName = maCbEnglishFuncName.IsChecked();
     256                 :          0 :     sal_Int16 aSyntaxPos      = maLbFormulaSyntax.GetSelectEntryPos();
     257                 :          0 :     OUString aSep             = maEdSepFuncArg.GetText();
     258                 :          0 :     OUString aSepArrayCol     = maEdSepArrayCol.GetText();
     259                 :          0 :     OUString aSepArrayRow     = maEdSepArrayRow.GetText();
     260                 :            : 
     261                 :          0 :     if (maBtnCustomCalcDefault.IsChecked())
     262                 :            :     {
     263                 :            :         // When Default is selected, reset all the calc config settings to default.
     264                 :          0 :         maCurrentConfig.reset();
     265                 :            :     }
     266                 :            : 
     267                 :          0 :     if ( maLbFormulaSyntax.GetSavedValue() != aSyntaxPos
     268                 :          0 :          || maCbEnglishFuncName.GetSavedValue() != bEnglishFuncName
     269                 :          0 :          || static_cast<OUString>(maEdSepFuncArg.GetSavedValue()) != aSep
     270                 :          0 :          || static_cast<OUString>(maEdSepArrayCol.GetSavedValue()) != aSepArrayCol
     271                 :          0 :          || static_cast<OUString>(maEdSepArrayRow.GetSavedValue()) != aSepArrayRow
     272                 :          0 :          || maSavedConfig != maCurrentConfig )
     273                 :            :     {
     274                 :          0 :         ::formula::FormulaGrammar::Grammar eGram = ::formula::FormulaGrammar::GRAM_DEFAULT;
     275                 :            : 
     276                 :          0 :         switch (aSyntaxPos)
     277                 :            :         {
     278                 :            :         case 0:
     279                 :          0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE;
     280                 :          0 :         break;
     281                 :            :         case 1:
     282                 :          0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1;
     283                 :          0 :         break;
     284                 :            :         case 2:
     285                 :          0 :             eGram = ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1;
     286                 :          0 :         break;
     287                 :            :         }
     288                 :            : 
     289                 :          0 :         aOpt.SetFormulaSyntax(eGram);
     290                 :          0 :         aOpt.SetUseEnglishFuncName(bEnglishFuncName);
     291                 :          0 :         aOpt.SetFormulaSepArg(aSep);
     292                 :          0 :         aOpt.SetFormulaSepArrayCol(aSepArrayCol);
     293                 :          0 :         aOpt.SetFormulaSepArrayRow(aSepArrayRow);
     294                 :          0 :         aOpt.SetCalcConfig(maCurrentConfig);
     295                 :            : 
     296                 :          0 :         rCoreSet.Put( ScTpFormulaItem( SID_SCFORMULAOPTIONS, aOpt ) );
     297                 :          0 :         bRet = true;
     298                 :            :     }
     299                 :          0 :     return bRet;
     300                 :            : }
     301                 :            : 
     302                 :          0 : void ScTpFormulaOptions::Reset(const SfxItemSet& rCoreSet)
     303                 :            : {
     304                 :          0 :     ScFormulaOptions aOpt;
     305                 :          0 :     const SfxPoolItem* pItem = NULL;
     306                 :            : 
     307                 :          0 :     if(SFX_ITEM_SET == rCoreSet.GetItemState(SID_SCFORMULAOPTIONS, false , &pItem))
     308                 :          0 :         aOpt = ((const ScTpFormulaItem*)pItem)->GetFormulaOptions();
     309                 :            : 
     310                 :            :     // formula grammar.
     311                 :          0 :     ::formula::FormulaGrammar::Grammar eGram = aOpt.GetFormulaSyntax();
     312                 :            : 
     313                 :          0 :     switch (eGram)
     314                 :            :     {
     315                 :            :     case ::formula::FormulaGrammar::GRAM_NATIVE:
     316                 :          0 :         maLbFormulaSyntax.SelectEntryPos(0);
     317                 :          0 :         break;
     318                 :            :     case ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1:
     319                 :          0 :         maLbFormulaSyntax.SelectEntryPos(1);
     320                 :          0 :         break;
     321                 :            :     case ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1:
     322                 :          0 :         maLbFormulaSyntax.SelectEntryPos(2);
     323                 :          0 :         break;
     324                 :            :     default:
     325                 :          0 :         maLbFormulaSyntax.SelectEntryPos(0);
     326                 :            :     }
     327                 :            : 
     328                 :          0 :     maLbFormulaSyntax.SaveValue();
     329                 :            : 
     330                 :            :     // english function name.
     331                 :          0 :     maCbEnglishFuncName.Check( aOpt.GetUseEnglishFuncName() );
     332                 :          0 :     maCbEnglishFuncName.SaveValue();
     333                 :            : 
     334                 :            :     // Separators
     335                 :          0 :     OUString aSep = aOpt.GetFormulaSepArg();
     336                 :          0 :     OUString aSepArrayRow = aOpt.GetFormulaSepArrayRow();
     337                 :          0 :     OUString aSepArrayCol = aOpt.GetFormulaSepArrayCol();
     338                 :            : 
     339                 :          0 :     if (aSep.getLength() == 1 && aSepArrayRow.getLength() == 1 && aSepArrayCol.getLength() == 1)
     340                 :            :     {
     341                 :            :         // Each separator must be one character long.
     342                 :          0 :         maEdSepFuncArg.SetText(aSep);
     343                 :          0 :         maEdSepArrayCol.SetText(aSepArrayCol);
     344                 :          0 :         maEdSepArrayRow.SetText(aSepArrayRow);
     345                 :            : 
     346                 :          0 :         maEdSepFuncArg.SaveValue();
     347                 :          0 :         maEdSepArrayCol.SaveValue();
     348                 :          0 :         maEdSepArrayRow.SaveValue();
     349                 :            :     }
     350                 :            :     else
     351                 :          0 :         ResetSeparators();
     352                 :            : 
     353                 :            :     // detailed calc settings.
     354                 :          0 :     ScFormulaOptions aDefaults;
     355                 :            : 
     356                 :          0 :     maSavedConfig = aOpt.GetCalcConfig();
     357                 :          0 :     bool bDefault = aDefaults.GetCalcConfig() == maSavedConfig;
     358                 :          0 :     UpdateCustomCalcRadioButtons(bDefault);
     359                 :            : 
     360                 :          0 :     maCurrentConfig = maSavedConfig;
     361                 :          0 : }
     362                 :            : 
     363                 :          0 : int ScTpFormulaOptions::DeactivatePage(SfxItemSet* /*pSet*/)
     364                 :            : {
     365                 :            :     // What's this method for ?
     366                 :          0 :     return KEEP_PAGE;
     367                 :            : }
     368                 :            : 
     369                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10