LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/optdlg - calcoptionsdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 168 0.0 %
Date: 2013-07-09 Functions: 0 25 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             :  */
      12             : 
      13             : #include <config_features.h>
      14             : 
      15             : #include "calcoptionsdlg.hxx"
      16             : #include "sc.hrc"
      17             : #include "scresid.hxx"
      18             : 
      19             : #include "svtools/svlbitm.hxx"
      20             : #include "svtools/treelistentry.hxx"
      21             : 
      22             : namespace {
      23             : 
      24             : typedef enum {
      25             :     CALC_OPTION_REF_SYNTAX    = 0,
      26             :     CALC_OPTION_EMPTY_AS_ZERO = 1,
      27             :     CALC_OPTION_ENABLE_OPENCL = 2
      28             : } CalcOptionOrder;
      29             : 
      30           0 : class OptionString : public SvLBoxString
      31             : {
      32             :     OUString maDesc;
      33             :     OUString maValue;
      34             : public:
      35           0 :     OptionString(const OUString& rDesc, const OUString& rValue) :
      36           0 :         maDesc(rDesc), maValue(rValue) {}
      37             : 
      38           0 :     void SetValue(const OUString &rValue) { maValue = rValue; }
      39             : 
      40             :     virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
      41             : 
      42             :     virtual void InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData);
      43             : };
      44             : 
      45           0 : void OptionString::InitViewData(
      46             :     SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
      47             : {
      48           0 :     if( !pViewData )
      49           0 :         pViewData = pView->GetViewDataItem( pEntry, this );
      50             : 
      51           0 :     OUString aDesc = maDesc + OUString(": ");
      52           0 :     Size aDescSize(pView->GetTextWidth(aDesc), pView->GetTextHeight());
      53             : 
      54           0 :     Font aOldFont = pView->GetFont();
      55           0 :     Font aFont = aOldFont;
      56           0 :     aFont.SetWeight(WEIGHT_BOLD);
      57             :     //To not make the SvTreeListBox try and recalculate all rows, call the
      58             :     //underlying SetFont, we just want to know what size this text will be
      59             :     //and are going to reset the font to the original again afterwards
      60           0 :     pView->Control::SetFont(aFont);
      61           0 :     Size aValueSize(pView->GetTextWidth(maValue), pView->GetTextHeight());
      62           0 :     pView->Control::SetFont(aOldFont);
      63             : 
      64           0 :     pViewData->maSize = Size(aDescSize.Width() + aValueSize.Width(), std::max(aDescSize.Height(), aValueSize.Height()));
      65           0 : }
      66             : 
      67           0 : void OptionString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
      68             : {
      69           0 :     Point aPos = rPos;
      70           0 :     OUString aDesc = maDesc + OUString(": ");
      71           0 :     rDev.DrawText(aPos, aDesc);
      72             : 
      73           0 :     aPos.X() += rDev.GetTextWidth(aDesc);
      74           0 :     Font aOldFont = rDev.GetFont();
      75           0 :     Font aFont = aOldFont;
      76           0 :     aFont.SetWeight(WEIGHT_BOLD);
      77             : 
      78             :     //To not make the SvTreeListBox try and recalculate all rows, call the
      79             :     //underlying SetFont, we are going to draw this string and then going to
      80             :     //reset the font to the original again afterwards
      81           0 :     rDev.Control::SetFont(aFont);
      82           0 :     rDev.DrawText(aPos, maValue);
      83           0 :     rDev.Control::SetFont(aOldFont);
      84           0 : }
      85             : 
      86           0 : formula::FormulaGrammar::AddressConvention toAddressConvention(sal_uInt16 nPos)
      87             : {
      88           0 :     switch (nPos)
      89             :     {
      90             :         case 1:
      91           0 :             return formula::FormulaGrammar::CONV_OOO;
      92             :         case 2:
      93           0 :             return formula::FormulaGrammar::CONV_XL_A1;
      94             :         case 3:
      95           0 :             return formula::FormulaGrammar::CONV_XL_R1C1;
      96             :         case 0:
      97             :         default:
      98             :             ;
      99             :     }
     100             : 
     101           0 :     return formula::FormulaGrammar::CONV_UNSPECIFIED;
     102             : }
     103             : 
     104             : }
     105             : 
     106           0 : ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rConfig)
     107             :     : ModalDialog(pParent, "FormulaCalculationOptions",
     108             :         "modules/scalc/ui/formulacalculationoptions.ui")
     109             :     , maCalcA1(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString())
     110             :     , maExcelA1(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString())
     111             :     , maExcelR1C1(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString())
     112           0 :     , maConfig(rConfig)
     113             : {
     114           0 :     get(mpLbSettings, "settings");
     115           0 :     get(mpLbOptionEdit, "edit");
     116           0 :     get(mpFtAnnotation, "annotation");
     117           0 :     get(mpBtnTrue, "true");
     118           0 :     get(mpBtnFalse, "false");
     119             : 
     120           0 :     maCaptionStringRefSyntax = get<Window>("ref_syntax_caption")->GetText();
     121           0 :     maDescStringRefSyntax = get<Window>("ref_syntax_desc")->GetText();
     122           0 :     maUseFormulaSyntax = get<Window>("use_formula_syntax")->GetText();
     123           0 :     maCaptionEmptyStringAsZero = get<Window>("empty_str_as_zero_caption")->GetText();
     124           0 :     maDescEmptyStringAsZero = get<Window>("empty_str_as_zero_desc")->GetText();
     125           0 :     maCaptionOpenCLEnabled = get<Window>("opencl_enabled")->GetText();
     126           0 :     maDescOpenCLEnabled = get<Window>("opencl_enabled_desc")->GetText();
     127             : 
     128           0 :     mpLbSettings->set_height_request(8 * mpLbSettings->GetTextHeight());
     129           0 :     mpLbSettings->SetStyle(mpLbSettings->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
     130           0 :     mpLbSettings->SetHighlightRange();
     131             : 
     132           0 :     Link aLink = LINK(this, ScCalcOptionsDialog, SettingsSelHdl);
     133           0 :     mpLbSettings->SetSelectHdl(aLink);
     134           0 :     mpLbOptionEdit->SetSelectHdl(aLink);
     135             : 
     136           0 :     aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl);
     137           0 :     mpBtnTrue->SetToggleHdl(aLink); // Set handler only to the 'True' button.
     138             : 
     139           0 :     maTrue = mpBtnTrue->GetText();
     140           0 :     maFalse = mpBtnFalse->GetText();
     141             : 
     142           0 :     FillOptionsList();
     143           0 :     SelectionChanged();
     144           0 : }
     145             : 
     146           0 : ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
     147             : 
     148           0 : const ScCalcConfig& ScCalcOptionsDialog::GetConfig() const
     149             : {
     150           0 :     return maConfig;
     151             : }
     152             : 
     153           0 : SvTreeListEntry *ScCalcOptionsDialog::createBoolItem(const OUString &rCaption, bool bValue) const
     154             : {
     155           0 :     SvTreeListEntry* pEntry = new SvTreeListEntry;
     156           0 :     pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
     157           0 :     pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     158           0 :     OptionString* pItem = new OptionString(rCaption, toString(bValue));
     159           0 :     pEntry->AddItem(pItem);
     160           0 :     return pEntry;
     161             : }
     162             : 
     163           0 : void ScCalcOptionsDialog::setValueAt(size_t nPos, const OUString &rValue)
     164             : {
     165           0 :     SvTreeList *pModel = mpLbSettings->GetModel();
     166           0 :     SvTreeListEntry* pEntry = pModel->GetEntry(NULL, nPos);
     167           0 :     if (!pEntry)
     168             :     {
     169             :         SAL_WARN("sc", "missing entry at " << nPos << " in value view");
     170           0 :         return;
     171             :     }
     172           0 :     OptionString* pOpt = dynamic_cast<OptionString *>(pEntry->GetItem(2));
     173           0 :     if (!pOpt)
     174             :     {
     175             :         SAL_WARN("sc", "missing option string item so can't set " << rValue);
     176           0 :         return;
     177             :     }
     178             : 
     179           0 :     pOpt->SetValue(rValue);
     180           0 :     pModel->InvalidateEntry(pEntry);
     181             : }
     182             : 
     183           0 : void ScCalcOptionsDialog::FillOptionsList()
     184             : {
     185           0 :     mpLbSettings->SetUpdateMode(false);
     186           0 :     mpLbSettings->Clear();
     187             : 
     188           0 :     SvTreeList* pModel = mpLbSettings->GetModel();
     189             : 
     190             :     {
     191             :         // Syntax for INDIRECT function.
     192           0 :         SvTreeListEntry* pEntry = new SvTreeListEntry;
     193           0 :         pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
     194           0 :         pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
     195             :         OptionString* pItem = new OptionString(
     196           0 :             maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
     197           0 :         pEntry->AddItem(pItem);
     198           0 :         pModel->Insert(pEntry);
     199             :     }
     200             : 
     201           0 :     pModel->Insert(createBoolItem(maCaptionEmptyStringAsZero,maConfig.mbEmptyStringAsZero));
     202             : #if HAVE_FEATURE_OPENCL
     203             :     pModel->Insert(createBoolItem(maCaptionOpenCLEnabled,maConfig.mbOpenCLEnabled));
     204             : #endif
     205             : 
     206           0 :     mpLbSettings->SetUpdateMode(true);
     207           0 : }
     208             : 
     209           0 : void ScCalcOptionsDialog::SelectionChanged()
     210             : {
     211           0 :     sal_uInt16 nSelectedPos = mpLbSettings->GetSelectEntryPos();
     212           0 :     switch ((CalcOptionOrder)nSelectedPos)
     213             :     {
     214             :         case CALC_OPTION_REF_SYNTAX:
     215             :         {
     216             :             // Formula syntax for INDIRECT function.
     217           0 :             mpBtnTrue->Hide();
     218           0 :             mpBtnFalse->Hide();
     219           0 :             mpLbOptionEdit->Show();
     220             : 
     221           0 :             mpLbOptionEdit->Clear();
     222           0 :             mpLbOptionEdit->InsertEntry(maUseFormulaSyntax);
     223           0 :             mpLbOptionEdit->InsertEntry(maCalcA1);
     224           0 :             mpLbOptionEdit->InsertEntry(maExcelA1);
     225           0 :             mpLbOptionEdit->InsertEntry(maExcelR1C1);
     226           0 :             switch (maConfig.meStringRefAddressSyntax)
     227             :             {
     228             :                 case formula::FormulaGrammar::CONV_OOO:
     229           0 :                     mpLbOptionEdit->SelectEntryPos(1);
     230           0 :                 break;
     231             :                 case formula::FormulaGrammar::CONV_XL_A1:
     232           0 :                     mpLbOptionEdit->SelectEntryPos(2);
     233           0 :                 break;
     234             :                 case formula::FormulaGrammar::CONV_XL_R1C1:
     235           0 :                     mpLbOptionEdit->SelectEntryPos(3);
     236           0 :                 break;
     237             :                 case formula::FormulaGrammar::CONV_UNSPECIFIED:
     238             :                 default:
     239           0 :                     mpLbOptionEdit->SelectEntryPos(0);
     240             :             }
     241           0 :             mpFtAnnotation->SetText(maDescStringRefSyntax);
     242             :         }
     243           0 :         break;
     244             : 
     245             :         // booleans
     246             :         case CALC_OPTION_EMPTY_AS_ZERO:
     247             :         case CALC_OPTION_ENABLE_OPENCL:
     248             :         {
     249             :             // Treat empty string as zero.
     250           0 :             mpLbOptionEdit->Hide();
     251           0 :             mpBtnTrue->Show();
     252           0 :             mpBtnFalse->Show();
     253             : 
     254           0 :             bool bValue = false;
     255           0 :             if ( nSelectedPos == CALC_OPTION_EMPTY_AS_ZERO )
     256           0 :                 bValue = maConfig.mbEmptyStringAsZero;
     257             :             else
     258           0 :                 bValue = maConfig.mbOpenCLEnabled;
     259             : 
     260           0 :             if ( bValue )
     261             :             {
     262           0 :                 mpBtnTrue->Check(true);
     263           0 :                 mpBtnFalse->Check(false);
     264             :             }
     265             :             else
     266             :             {
     267           0 :                 mpBtnTrue->Check(false);
     268           0 :                 mpBtnFalse->Check(true);
     269             :             }
     270           0 :             mpFtAnnotation->SetText(maDescEmptyStringAsZero);
     271             :         }
     272           0 :         break;
     273             :         default:
     274             :             ;
     275             :     }
     276           0 : }
     277             : 
     278           0 : void ScCalcOptionsDialog::ListOptionValueChanged()
     279             : {
     280           0 :     sal_uInt16 nSelected = mpLbSettings->GetSelectEntryPos();
     281           0 :     switch ((CalcOptionOrder) nSelected)
     282             :     {
     283             :         case CALC_OPTION_REF_SYNTAX:
     284             :         {
     285             :             // Formula syntax for INDIRECT function.
     286           0 :             sal_uInt16 nPos = mpLbOptionEdit->GetSelectEntryPos();
     287           0 :             maConfig.meStringRefAddressSyntax = toAddressConvention(nPos);
     288             : 
     289           0 :             setValueAt(nSelected, toString(maConfig.meStringRefAddressSyntax));
     290             :         }
     291           0 :         break;
     292             : 
     293             :         case CALC_OPTION_EMPTY_AS_ZERO:
     294             :         case CALC_OPTION_ENABLE_OPENCL:
     295           0 :             break;
     296             :     }
     297           0 : }
     298             : 
     299           0 : void ScCalcOptionsDialog::RadioValueChanged()
     300             : {
     301           0 :     sal_uInt16 nSelected = mpLbSettings->GetSelectEntryPos();
     302           0 :     bool bValue = mpBtnTrue->IsChecked();
     303           0 :     switch (nSelected)
     304             :     {
     305             :         case CALC_OPTION_REF_SYNTAX:
     306           0 :             return;
     307             :         case CALC_OPTION_EMPTY_AS_ZERO:
     308           0 :             maConfig.mbEmptyStringAsZero = bValue;
     309           0 :             break;
     310             :         case CALC_OPTION_ENABLE_OPENCL:
     311           0 :             maConfig.mbOpenCLEnabled = bValue;
     312           0 :             break;
     313             :     }
     314             : 
     315           0 :     setValueAt(nSelected, toString(bValue));
     316             : }
     317             : 
     318           0 : OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const
     319             : {
     320           0 :     switch (eConv)
     321             :     {
     322             :         case formula::FormulaGrammar::CONV_OOO:
     323           0 :             return maCalcA1;
     324             :         case formula::FormulaGrammar::CONV_XL_A1:
     325           0 :             return maExcelA1;
     326             :         case formula::FormulaGrammar::CONV_XL_R1C1:
     327           0 :             return maExcelR1C1;
     328             :         case formula::FormulaGrammar::CONV_UNSPECIFIED:
     329             :         default:
     330             :             ;
     331             :     }
     332           0 :     return maUseFormulaSyntax;
     333             : }
     334             : 
     335           0 : OUString ScCalcOptionsDialog::toString(bool bVal) const
     336             : {
     337           0 :     return bVal ? maTrue : maFalse;
     338             : }
     339             : 
     340           0 : IMPL_LINK(ScCalcOptionsDialog, SettingsSelHdl, Control*, pCtrl)
     341             : {
     342           0 :     if (pCtrl == mpLbSettings)
     343           0 :         SelectionChanged();
     344           0 :     else if (pCtrl == mpLbOptionEdit)
     345           0 :         ListOptionValueChanged();
     346             : 
     347           0 :     return 0;
     348             : }
     349             : 
     350           0 : IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnToggleHdl)
     351             : {
     352           0 :     RadioValueChanged();
     353           0 :     return 0;
     354           0 : }
     355             : 
     356             : 
     357             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10