LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/optdlg - calcoptionsdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 133 0.0 %
Date: 2012-12-17 Functions: 0 19 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             :  * 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             : #include "svtools/treelistentry.hxx"
      35             : 
      36             : namespace {
      37             : 
      38           0 : class OptionString : public SvLBoxString
      39             : {
      40             :     rtl::OUString maDesc;
      41             :     rtl::OUString maValue;
      42             : public:
      43           0 :     OptionString(const rtl::OUString& rDesc, const rtl::OUString& rValue) :
      44           0 :         maDesc(rDesc), maValue(rValue) {}
      45             : 
      46             :     virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
      47             : };
      48             : 
      49           0 : void OptionString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
      50             : {
      51           0 :     Point aPos = rPos;
      52           0 :     rtl::OUString aDesc = maDesc + rtl::OUString(": ");
      53           0 :     rDev.DrawText(aPos, aDesc);
      54             : 
      55           0 :     aPos.X() += rDev.GetTextWidth(aDesc);
      56           0 :     Font aOldFont = rDev.GetFont();
      57           0 :     Font aFont = aOldFont;
      58           0 :     aFont.SetWeight(WEIGHT_BOLD);
      59             : 
      60           0 :     rDev.SetFont(aFont);
      61           0 :     rDev.DrawText(aPos, maValue);
      62             : 
      63           0 :     rDev.SetFont(aOldFont);
      64           0 : }
      65             : 
      66           0 : formula::FormulaGrammar::AddressConvention toAddressConvention(sal_uInt16 nPos)
      67             : {
      68           0 :     switch (nPos)
      69             :     {
      70             :         case 1:
      71           0 :             return formula::FormulaGrammar::CONV_OOO;
      72             :         case 2:
      73           0 :             return formula::FormulaGrammar::CONV_XL_A1;
      74             :         case 3:
      75           0 :             return formula::FormulaGrammar::CONV_XL_R1C1;
      76             :         case 0:
      77             :         default:
      78             :             ;
      79             :     }
      80             : 
      81           0 :     return formula::FormulaGrammar::CONV_UNSPECIFIED;
      82             : }
      83             : 
      84             : }
      85             : 
      86           0 : ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rConfig) :
      87             :     ModalDialog(pParent, ScResId(RID_SCDLG_FORMULA_CALCOPTIONS)),
      88             :     maLbSettings(this, ScResId(LB_SETTINGS)),
      89             :     maFtOptionEditCaption(this, ScResId(FT_OPTION_EDIT_CAPTION)),
      90             :     maLbOptionEdit(this, ScResId(LB_OPTION_EDIT)),
      91             :     maBtnTrue(this, ScResId(BTN_OPTION_TRUE)),
      92             :     maBtnFalse(this, ScResId(BTN_OPTION_FALSE)),
      93             :     maFlAnnotation(this, ScResId(FL_ANNOTATION)),
      94             :     maFtAnnotation(this, ScResId(FT_ANNOTATION)),
      95             :     maBtnOK(this, ScResId(BTN_OK)),
      96             :     maBtnCancel(this, ScResId(BTN_CANCEL)),
      97             :     maTrue(ScResId(STR_TRUE).toString()),
      98             :     maFalse(ScResId(STR_FALSE).toString()),
      99             :     maCalcA1(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString()),
     100             :     maExcelA1(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString()),
     101             :     maExcelR1C1(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString()),
     102             :     maCaptionStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_CAPTION).toString()),
     103             :     maDescStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_DESC).toString()),
     104             :     maUseFormulaSyntax(ScResId(STR_USE_FORMULA_SYNTAX).toString()),
     105             :     maCaptionEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_CAPTION).toString()),
     106             :     maDescEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_DESC).toString()),
     107           0 :     maConfig(rConfig)
     108             : {
     109           0 :     maLbSettings.SetStyle(maLbSettings.GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
     110           0 :     maLbSettings.SetHighlightRange();
     111             : 
     112           0 :     Link aLink = LINK(this, ScCalcOptionsDialog, SettingsSelHdl);
     113           0 :     maLbSettings.SetSelectHdl(aLink);
     114           0 :     maLbOptionEdit.SetSelectHdl(aLink);
     115             : 
     116           0 :     aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl);
     117           0 :     maBtnTrue.SetToggleHdl(aLink); // Set handler only to the 'True' button.
     118             : 
     119           0 :     maBtnTrue.SetText(maTrue);
     120           0 :     maBtnFalse.SetText(maFalse);
     121             : 
     122           0 :     FillOptionsList();
     123           0 :     FreeResource();
     124           0 :     SelectionChanged();
     125           0 : }
     126             : 
     127           0 : ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
     128             : 
     129           0 : const ScCalcConfig& ScCalcOptionsDialog::GetConfig() const
     130             : {
     131           0 :     return maConfig;
     132             : }
     133             : 
     134           0 : void ScCalcOptionsDialog::FillOptionsList()
     135             : {
     136           0 :     maLbSettings.SetUpdateMode(false);
     137           0 :     maLbSettings.Clear();
     138             : 
     139           0 :     SvTreeList* pModel = maLbSettings.GetModel();
     140             : 
     141             :     {
     142             :         // Syntax for INDIRECT function.
     143           0 :         SvTreeListEntry* pEntry = new SvTreeListEntry;
     144           0 :         pEntry->AddItem(new SvLBoxString(pEntry, 0, rtl::OUString()));
     145           0 :         pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     146             :         OptionString* pItem = new OptionString(
     147           0 :             maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
     148           0 :         pEntry->AddItem(pItem);
     149           0 :         pModel->Insert(pEntry);
     150             :     }
     151             : 
     152             :     {
     153             :         // Treat empty string as zero.
     154           0 :         SvTreeListEntry* pEntry = new SvTreeListEntry;
     155           0 :         pEntry->AddItem(new SvLBoxString(pEntry, 0, rtl::OUString()));
     156           0 :         pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     157             :         OptionString* pItem = new OptionString(
     158           0 :             maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
     159           0 :         pEntry->AddItem(pItem);
     160           0 :         pModel->Insert(pEntry);
     161             :     }
     162             : 
     163           0 :     maLbSettings.SetUpdateMode(true);
     164           0 : }
     165             : 
     166           0 : void ScCalcOptionsDialog::SelectionChanged()
     167             : {
     168           0 :     sal_uInt16 nSelectedPos = maLbSettings.GetSelectEntryPos();
     169           0 :     switch (nSelectedPos)
     170             :     {
     171             :         case 0:
     172             :         {
     173             :             // Formula syntax for INDIRECT function.
     174           0 :             maBtnTrue.Hide();
     175           0 :             maBtnFalse.Hide();
     176           0 :             maLbOptionEdit.Show();
     177             : 
     178           0 :             maLbOptionEdit.Clear();
     179           0 :             maLbOptionEdit.InsertEntry(maUseFormulaSyntax);
     180           0 :             maLbOptionEdit.InsertEntry(maCalcA1);
     181           0 :             maLbOptionEdit.InsertEntry(maExcelA1);
     182           0 :             maLbOptionEdit.InsertEntry(maExcelR1C1);
     183           0 :             switch (maConfig.meStringRefAddressSyntax)
     184             :             {
     185             :                 case formula::FormulaGrammar::CONV_OOO:
     186           0 :                     maLbOptionEdit.SelectEntryPos(1);
     187           0 :                 break;
     188             :                 case formula::FormulaGrammar::CONV_XL_A1:
     189           0 :                     maLbOptionEdit.SelectEntryPos(2);
     190           0 :                 break;
     191             :                 case formula::FormulaGrammar::CONV_XL_R1C1:
     192           0 :                     maLbOptionEdit.SelectEntryPos(3);
     193           0 :                 break;
     194             :                 case formula::FormulaGrammar::CONV_UNSPECIFIED:
     195             :                 default:
     196           0 :                     maLbOptionEdit.SelectEntryPos(0);
     197             :             }
     198           0 :             maFtAnnotation.SetText(maDescStringRefSyntax);
     199             :         }
     200           0 :         break;
     201             :         case 1:
     202             :         {
     203             :             // Treat empty string as zero.
     204           0 :             maLbOptionEdit.Hide();
     205           0 :             maBtnTrue.Show();
     206           0 :             maBtnFalse.Show();
     207             : 
     208           0 :             if (maConfig.mbEmptyStringAsZero)
     209             :             {
     210           0 :                 maBtnTrue.Check(true);
     211           0 :                 maBtnFalse.Check(false);
     212             :             }
     213             :             else
     214             :             {
     215           0 :                 maBtnTrue.Check(false);
     216           0 :                 maBtnFalse.Check(true);
     217             :             }
     218           0 :             maFtAnnotation.SetText(maDescEmptyStringAsZero);
     219             :         }
     220           0 :         break;
     221             :         default:
     222             :             ;
     223             :     }
     224           0 : }
     225             : 
     226           0 : void ScCalcOptionsDialog::ListOptionValueChanged()
     227             : {
     228           0 :     sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
     229           0 :     switch (nSelected)
     230             :     {
     231             :         case 0:
     232             :         {
     233             :             // Formula syntax for INDIRECT function.
     234           0 :             sal_uInt16 nPos = maLbOptionEdit.GetSelectEntryPos();
     235           0 :             maConfig.meStringRefAddressSyntax = toAddressConvention(nPos);
     236             : 
     237           0 :             maLbSettings.SetUpdateMode(false);
     238             : 
     239           0 :             SvTreeList* pModel = maLbSettings.GetModel();
     240           0 :             SvTreeListEntry* pEntry = pModel->GetEntry(NULL, 0);
     241           0 :             if (!pEntry)
     242           0 :                 return;
     243             : 
     244             :             OptionString* pItem = new OptionString(
     245           0 :                 maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
     246           0 :             pEntry->ReplaceItem(pItem, 2);
     247             : 
     248           0 :             maLbSettings.SetUpdateMode(true);
     249             :         }
     250           0 :         break;
     251             :         default:
     252             :             ;
     253             :     }
     254             : }
     255             : 
     256           0 : void ScCalcOptionsDialog::RadioValueChanged()
     257             : {
     258           0 :     sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
     259           0 :     switch (nSelected)
     260             :     {
     261             :         case 1:
     262             :         {
     263             :             // Treat empty string as zero.
     264           0 :             maConfig.mbEmptyStringAsZero = maBtnTrue.IsChecked();
     265           0 :             maLbSettings.SetUpdateMode(false);
     266             : 
     267           0 :             SvTreeList* pModel = maLbSettings.GetModel();
     268           0 :             SvTreeListEntry* pEntry = pModel->GetEntry(NULL, 1);
     269           0 :             if (!pEntry)
     270           0 :                 return;
     271             : 
     272             :             OptionString* pItem = new OptionString(
     273           0 :                 maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
     274           0 :             pEntry->ReplaceItem(pItem, 2);
     275             : 
     276           0 :             maLbSettings.SetUpdateMode(true);
     277             :         }
     278           0 :         break;
     279             :         default:
     280             :             ;
     281             :     }
     282             : }
     283             : 
     284           0 : rtl::OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const
     285             : {
     286           0 :     switch (eConv)
     287             :     {
     288             :         case formula::FormulaGrammar::CONV_OOO:
     289           0 :             return maCalcA1;
     290             :         case formula::FormulaGrammar::CONV_XL_A1:
     291           0 :             return maExcelA1;
     292             :         case formula::FormulaGrammar::CONV_XL_R1C1:
     293           0 :             return maExcelR1C1;
     294             :         case formula::FormulaGrammar::CONV_UNSPECIFIED:
     295             :         default:
     296             :             ;
     297             :     }
     298           0 :     return maUseFormulaSyntax;
     299             : }
     300             : 
     301           0 : rtl::OUString ScCalcOptionsDialog::toString(bool bVal) const
     302             : {
     303           0 :     return bVal ? maTrue : maFalse;
     304             : }
     305             : 
     306           0 : IMPL_LINK(ScCalcOptionsDialog, SettingsSelHdl, Control*, pCtrl)
     307             : {
     308           0 :     if (pCtrl == &maLbSettings)
     309           0 :         SelectionChanged();
     310           0 :     else if (pCtrl == &maLbOptionEdit)
     311           0 :         ListOptionValueChanged();
     312             : 
     313           0 :     return 0;
     314             : }
     315             : 
     316           0 : IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnToggleHdl)
     317             : {
     318           0 :     RadioValueChanged();
     319           0 :     return 0;
     320             : }
     321             : 
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10