LCOV - code coverage report
Current view: top level - sc/source/ui/optdlg - calcoptionsdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 133 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                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  *   Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "calcoptionsdlg.hxx"
      30                 :            : #include "calcoptionsdlg.hrc"
      31                 :            : #include "scresid.hxx"
      32                 :            : 
      33                 :            : #include "svtools/svlbitm.hxx"
      34                 :            : 
      35                 :            : namespace {
      36                 :            : 
      37                 :          0 : class OptionString : public SvLBoxString
      38                 :            : {
      39                 :            :     rtl::OUString maDesc;
      40                 :            :     rtl::OUString maValue;
      41                 :            : public:
      42                 :          0 :     OptionString(const rtl::OUString& rDesc, const rtl::OUString& rValue) :
      43                 :          0 :         maDesc(rDesc), maValue(rValue) {}
      44                 :            : 
      45                 :            :     virtual void Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
      46                 :            : };
      47                 :            : 
      48                 :          0 : void OptionString::Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 /*nFlags*/, SvLBoxEntry* /*pEntry*/)
      49                 :            : {
      50                 :          0 :     Point aPos = rPos;
      51                 :          0 :     rtl::OUString aDesc = maDesc + rtl::OUString(": ");
      52                 :          0 :     rDev.DrawText(aPos, aDesc);
      53                 :            : 
      54                 :          0 :     aPos.X() += rDev.GetTextWidth(aDesc);
      55                 :          0 :     Font aOldFont = rDev.GetFont();
      56                 :          0 :     Font aFont = aOldFont;
      57                 :          0 :     aFont.SetWeight(WEIGHT_BOLD);
      58                 :            : 
      59                 :          0 :     rDev.SetFont(aFont);
      60                 :          0 :     rDev.DrawText(aPos, maValue);
      61                 :            : 
      62                 :          0 :     rDev.SetFont(aOldFont);
      63                 :          0 : }
      64                 :            : 
      65                 :          0 : formula::FormulaGrammar::AddressConvention toAddressConvention(sal_uInt16 nPos)
      66                 :            : {
      67                 :          0 :     switch (nPos)
      68                 :            :     {
      69                 :            :         case 1:
      70                 :          0 :             return formula::FormulaGrammar::CONV_OOO;
      71                 :            :         case 2:
      72                 :          0 :             return formula::FormulaGrammar::CONV_XL_A1;
      73                 :            :         case 3:
      74                 :          0 :             return formula::FormulaGrammar::CONV_XL_R1C1;
      75                 :            :         case 0:
      76                 :            :         default:
      77                 :            :             ;
      78                 :            :     }
      79                 :            : 
      80                 :          0 :     return formula::FormulaGrammar::CONV_UNSPECIFIED;
      81                 :            : }
      82                 :            : 
      83                 :            : }
      84                 :            : 
      85                 :          0 : ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rConfig) :
      86                 :            :     ModalDialog(pParent, ScResId(RID_SCDLG_FORMULA_CALCOPTIONS)),
      87                 :            :     maLbSettings(this, ScResId(LB_SETTINGS)),
      88                 :            :     maFtOptionEditCaption(this, ScResId(FT_OPTION_EDIT_CAPTION)),
      89                 :            :     maLbOptionEdit(this, ScResId(LB_OPTION_EDIT)),
      90                 :            :     maBtnTrue(this, ScResId(BTN_OPTION_TRUE)),
      91                 :            :     maBtnFalse(this, ScResId(BTN_OPTION_FALSE)),
      92                 :            :     maFlAnnotation(this, ScResId(FL_ANNOTATION)),
      93                 :            :     maFtAnnotation(this, ScResId(FT_ANNOTATION)),
      94                 :            :     maBtnOK(this, ScResId(BTN_OK)),
      95                 :            :     maBtnCancel(this, ScResId(BTN_CANCEL)),
      96                 :            :     maTrue(ScResId(STR_TRUE).toString()),
      97                 :            :     maFalse(ScResId(STR_FALSE).toString()),
      98                 :            :     maCalcA1(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString()),
      99                 :            :     maExcelA1(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString()),
     100                 :            :     maExcelR1C1(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString()),
     101                 :            :     maCaptionStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_CAPTION).toString()),
     102                 :            :     maDescStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_DESC).toString()),
     103                 :            :     maUseFormulaSyntax(ScResId(STR_USE_FORMULA_SYNTAX).toString()),
     104                 :            :     maCaptionEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_CAPTION).toString()),
     105                 :            :     maDescEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_DESC).toString()),
     106                 :          0 :     maConfig(rConfig)
     107                 :            : {
     108                 :          0 :     maLbSettings.SetStyle(maLbSettings.GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
     109                 :          0 :     maLbSettings.SetHighlightRange();
     110                 :            : 
     111                 :          0 :     Link aLink = LINK(this, ScCalcOptionsDialog, SettingsSelHdl);
     112                 :          0 :     maLbSettings.SetSelectHdl(aLink);
     113                 :          0 :     maLbOptionEdit.SetSelectHdl(aLink);
     114                 :            : 
     115                 :          0 :     aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl);
     116                 :          0 :     maBtnTrue.SetToggleHdl(aLink); // Set handler only to the 'True' button.
     117                 :            : 
     118                 :          0 :     maBtnTrue.SetText(maTrue);
     119                 :          0 :     maBtnFalse.SetText(maFalse);
     120                 :            : 
     121                 :          0 :     FillOptionsList();
     122                 :          0 :     FreeResource();
     123                 :          0 :     SelectionChanged();
     124                 :          0 : }
     125                 :            : 
     126                 :          0 : ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
     127                 :            : 
     128                 :          0 : const ScCalcConfig& ScCalcOptionsDialog::GetConfig() const
     129                 :            : {
     130                 :          0 :     return maConfig;
     131                 :            : }
     132                 :            : 
     133                 :          0 : void ScCalcOptionsDialog::FillOptionsList()
     134                 :            : {
     135                 :          0 :     maLbSettings.SetUpdateMode(false);
     136                 :          0 :     maLbSettings.Clear();
     137                 :            : 
     138                 :          0 :     SvLBoxTreeList* pModel = maLbSettings.GetModel();
     139                 :            : 
     140                 :            :     {
     141                 :            :         // Syntax for INDIRECT function.
     142                 :          0 :         SvLBoxEntry* pEntry = new SvLBoxEntry;
     143                 :          0 :         pEntry->AddItem(new SvLBoxString(pEntry, 0, rtl::OUString()));
     144                 :          0 :         pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     145                 :            :         OptionString* pItem = new OptionString(
     146                 :          0 :             maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
     147                 :          0 :         pEntry->AddItem(pItem);
     148                 :          0 :         pModel->Insert(pEntry);
     149                 :            :     }
     150                 :            : 
     151                 :            :     {
     152                 :            :         // Treat empty string as zero.
     153                 :          0 :         SvLBoxEntry* pEntry = new SvLBoxEntry;
     154                 :          0 :         pEntry->AddItem(new SvLBoxString(pEntry, 0, rtl::OUString()));
     155                 :          0 :         pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     156                 :            :         OptionString* pItem = new OptionString(
     157                 :          0 :             maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
     158                 :          0 :         pEntry->AddItem(pItem);
     159                 :          0 :         pModel->Insert(pEntry);
     160                 :            :     }
     161                 :            : 
     162                 :          0 :     maLbSettings.SetUpdateMode(true);
     163                 :          0 : }
     164                 :            : 
     165                 :          0 : void ScCalcOptionsDialog::SelectionChanged()
     166                 :            : {
     167                 :          0 :     sal_uInt16 nSelectedPos = maLbSettings.GetSelectEntryPos();
     168                 :          0 :     switch (nSelectedPos)
     169                 :            :     {
     170                 :            :         case 0:
     171                 :            :         {
     172                 :            :             // Formula syntax for INDIRECT function.
     173                 :          0 :             maBtnTrue.Hide();
     174                 :          0 :             maBtnFalse.Hide();
     175                 :          0 :             maLbOptionEdit.Show();
     176                 :            : 
     177                 :          0 :             maLbOptionEdit.Clear();
     178                 :          0 :             maLbOptionEdit.InsertEntry(maUseFormulaSyntax);
     179                 :          0 :             maLbOptionEdit.InsertEntry(maCalcA1);
     180                 :          0 :             maLbOptionEdit.InsertEntry(maExcelA1);
     181                 :          0 :             maLbOptionEdit.InsertEntry(maExcelR1C1);
     182                 :          0 :             switch (maConfig.meStringRefAddressSyntax)
     183                 :            :             {
     184                 :            :                 case formula::FormulaGrammar::CONV_OOO:
     185                 :          0 :                     maLbOptionEdit.SelectEntryPos(1);
     186                 :          0 :                 break;
     187                 :            :                 case formula::FormulaGrammar::CONV_XL_A1:
     188                 :          0 :                     maLbOptionEdit.SelectEntryPos(2);
     189                 :          0 :                 break;
     190                 :            :                 case formula::FormulaGrammar::CONV_XL_R1C1:
     191                 :          0 :                     maLbOptionEdit.SelectEntryPos(3);
     192                 :          0 :                 break;
     193                 :            :                 case formula::FormulaGrammar::CONV_UNSPECIFIED:
     194                 :            :                 default:
     195                 :          0 :                     maLbOptionEdit.SelectEntryPos(0);
     196                 :            :             }
     197                 :          0 :             maFtAnnotation.SetText(maDescStringRefSyntax);
     198                 :            :         }
     199                 :          0 :         break;
     200                 :            :         case 1:
     201                 :            :         {
     202                 :            :             // Treat empty string as zero.
     203                 :          0 :             maLbOptionEdit.Hide();
     204                 :          0 :             maBtnTrue.Show();
     205                 :          0 :             maBtnFalse.Show();
     206                 :            : 
     207                 :          0 :             if (maConfig.mbEmptyStringAsZero)
     208                 :            :             {
     209                 :          0 :                 maBtnTrue.Check(true);
     210                 :          0 :                 maBtnFalse.Check(false);
     211                 :            :             }
     212                 :            :             else
     213                 :            :             {
     214                 :          0 :                 maBtnTrue.Check(false);
     215                 :          0 :                 maBtnFalse.Check(true);
     216                 :            :             }
     217                 :          0 :             maFtAnnotation.SetText(maDescEmptyStringAsZero);
     218                 :            :         }
     219                 :          0 :         break;
     220                 :            :         default:
     221                 :            :             ;
     222                 :            :     }
     223                 :          0 : }
     224                 :            : 
     225                 :          0 : void ScCalcOptionsDialog::ListOptionValueChanged()
     226                 :            : {
     227                 :          0 :     sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
     228                 :          0 :     switch (nSelected)
     229                 :            :     {
     230                 :            :         case 0:
     231                 :            :         {
     232                 :            :             // Formula syntax for INDIRECT function.
     233                 :          0 :             sal_uInt16 nPos = maLbOptionEdit.GetSelectEntryPos();
     234                 :          0 :             maConfig.meStringRefAddressSyntax = toAddressConvention(nPos);
     235                 :            : 
     236                 :          0 :             maLbSettings.SetUpdateMode(false);
     237                 :            : 
     238                 :          0 :             SvLBoxTreeList* pModel = maLbSettings.GetModel();
     239                 :          0 :             SvLBoxEntry* pEntry = pModel->GetEntry(NULL, 0);
     240                 :          0 :             if (!pEntry)
     241                 :          0 :                 return;
     242                 :            : 
     243                 :            :             OptionString* pItem = new OptionString(
     244                 :          0 :                 maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
     245                 :          0 :             pEntry->ReplaceItem(pItem, 2);
     246                 :            : 
     247                 :          0 :             maLbSettings.SetUpdateMode(true);
     248                 :            :         }
     249                 :          0 :         break;
     250                 :            :         default:
     251                 :            :             ;
     252                 :            :     }
     253                 :            : }
     254                 :            : 
     255                 :          0 : void ScCalcOptionsDialog::RadioValueChanged()
     256                 :            : {
     257                 :          0 :     sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
     258                 :          0 :     switch (nSelected)
     259                 :            :     {
     260                 :            :         case 1:
     261                 :            :         {
     262                 :            :             // Treat empty string as zero.
     263                 :          0 :             maConfig.mbEmptyStringAsZero = maBtnTrue.IsChecked();
     264                 :          0 :             maLbSettings.SetUpdateMode(false);
     265                 :            : 
     266                 :          0 :             SvLBoxTreeList* pModel = maLbSettings.GetModel();
     267                 :          0 :             SvLBoxEntry* pEntry = pModel->GetEntry(NULL, 1);
     268                 :          0 :             if (!pEntry)
     269                 :          0 :                 return;
     270                 :            : 
     271                 :            :             OptionString* pItem = new OptionString(
     272                 :          0 :                 maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
     273                 :          0 :             pEntry->ReplaceItem(pItem, 2);
     274                 :            : 
     275                 :          0 :             maLbSettings.SetUpdateMode(true);
     276                 :            :         }
     277                 :          0 :         break;
     278                 :            :         default:
     279                 :            :             ;
     280                 :            :     }
     281                 :            : }
     282                 :            : 
     283                 :          0 : rtl::OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const
     284                 :            : {
     285                 :          0 :     switch (eConv)
     286                 :            :     {
     287                 :            :         case formula::FormulaGrammar::CONV_OOO:
     288                 :          0 :             return maCalcA1;
     289                 :            :         case formula::FormulaGrammar::CONV_XL_A1:
     290                 :          0 :             return maExcelA1;
     291                 :            :         case formula::FormulaGrammar::CONV_XL_R1C1:
     292                 :          0 :             return maExcelR1C1;
     293                 :            :         case formula::FormulaGrammar::CONV_UNSPECIFIED:
     294                 :            :         default:
     295                 :            :             ;
     296                 :            :     }
     297                 :          0 :     return maUseFormulaSyntax;
     298                 :            : }
     299                 :            : 
     300                 :          0 : rtl::OUString ScCalcOptionsDialog::toString(bool bVal) const
     301                 :            : {
     302                 :          0 :     return bVal ? maTrue : maFalse;
     303                 :            : }
     304                 :            : 
     305                 :          0 : IMPL_LINK(ScCalcOptionsDialog, SettingsSelHdl, Control*, pCtrl)
     306                 :            : {
     307                 :          0 :     if (pCtrl == &maLbSettings)
     308                 :          0 :         SelectionChanged();
     309                 :          0 :     else if (pCtrl == &maLbOptionEdit)
     310                 :          0 :         ListOptionValueChanged();
     311                 :            : 
     312                 :          0 :     return 0;
     313                 :            : }
     314                 :            : 
     315                 :          0 : IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnToggleHdl)
     316                 :            : {
     317                 :          0 :     RadioValueChanged();
     318                 :          0 :     return 0;
     319                 :            : }
     320                 :            : 
     321                 :            : 
     322                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10