[Libreoffice-commits] core.git: sc/inc sc/source sc/uiconfig

Katarina Behrens Katarina.Behrens at cib.de
Fri Oct 16 15:16:15 PDT 2015


 sc/inc/docoptio.hxx                               |    5 +
 sc/inc/formulaopt.hxx                             |    4 +
 sc/source/core/tool/docoptio.cxx                  |    4 +
 sc/source/core/tool/formulaopt.cxx                |   63 ++++++++++++++++------
 sc/source/ui/inc/tpformula.hxx                    |    4 +
 sc/source/ui/optdlg/calcoptionsdlg.cxx            |   12 +++-
 sc/source/ui/optdlg/calcoptionsdlg.hxx            |    6 +-
 sc/source/ui/optdlg/tpformula.cxx                 |   16 ++++-
 sc/uiconfig/scalc/ui/formulacalculationoptions.ui |   15 +++++
 9 files changed, 108 insertions(+), 21 deletions(-)

New commits:
commit 313df729a3b6a94275ac992e74b18256fd286f93
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Mon Oct 12 11:43:46 2015 +0200

    tdf#92256, c#19: Implement "current doc only" switch
    
    that'll save calculation settings into current document only, not
    into global user profile
    
    Change-Id: I50ab31b679f712ff512f85a2cd58319d356462ea
    Reviewed-on: https://gerrit.libreoffice.org/19318
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index 1a54a3e..d8ff785 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -46,6 +46,7 @@ class SC_DLLPUBLIC ScDocOptions
     bool       bDoAutoSpell;            ///< auto-spelling
     bool       bLookUpColRowNames;      ///< determine column-/row titles automagically
     bool       bFormulaRegexEnabled;    ///< regular expressions in formulas enabled
+    bool       bWriteCalcConfig;        ///< (subset of) Calc config will be written to user's profile
 public:
                 ScDocOptions();
                 ScDocOptions( const ScDocOptions& rCpy );
@@ -91,6 +92,8 @@ public:
     void    SetFormulaRegexEnabled( bool bVal ) { bFormulaRegexEnabled = bVal; }
     bool    IsFormulaRegexEnabled() const       { return bFormulaRegexEnabled; }
 
+    void    SetWriteCalcConfig( bool bVal ) { bWriteCalcConfig = bVal; }
+    bool    IsWriteCalcConfig() const       { return bWriteCalcConfig; }
 };
 
 inline const ScDocOptions& ScDocOptions::operator=( const ScDocOptions& rCpy )
@@ -110,6 +113,7 @@ inline const ScDocOptions& ScDocOptions::operator=( const ScDocOptions& rCpy )
     bDoAutoSpell        = rCpy.bDoAutoSpell;
     bLookUpColRowNames  = rCpy.bLookUpColRowNames;
     bFormulaRegexEnabled= rCpy.bFormulaRegexEnabled;
+    bWriteCalcConfig    = rCpy.bWriteCalcConfig;
 
     return *this;
 }
@@ -132,6 +136,7 @@ inline bool ScDocOptions::operator==( const ScDocOptions& rOpt ) const
             &&  rOpt.bDoAutoSpell           == bDoAutoSpell
             &&  rOpt.bLookUpColRowNames     == bLookUpColRowNames
             &&  rOpt.bFormulaRegexEnabled   == bFormulaRegexEnabled
+            &&  rOpt.bWriteCalcConfig       == bWriteCalcConfig
             );
 }
 
diff --git a/sc/inc/formulaopt.hxx b/sc/inc/formulaopt.hxx
index ce56f20..8a903d2 100644
--- a/sc/inc/formulaopt.hxx
+++ b/sc/inc/formulaopt.hxx
@@ -25,6 +25,7 @@ private:
     bool bUseEnglishFuncName;     // use English function name even if the locale is not English.
     formula::FormulaGrammar::Grammar eFormulaGrammar;  // formula grammar used to switch different formula syntax
     ScCalcConfig aCalcConfig;
+    bool mbWriteCalcConfig;
 
     OUString aFormulaSepArg;
     OUString aFormulaSepArrayRow;
@@ -50,6 +51,9 @@ public:
     void SetUseEnglishFuncName( bool bVal ) { bUseEnglishFuncName = bVal; }
     bool GetUseEnglishFuncName() const { return bUseEnglishFuncName; }
 
+    void SetWriteCalcConfig( bool bVal ) { mbWriteCalcConfig = bVal; }
+    bool GetWriteCalcConfig() const { return mbWriteCalcConfig; }
+
     void SetFormulaSepArg(const OUString& rSep) { aFormulaSepArg = rSep; }
     OUString GetFormulaSepArg() const { return aFormulaSepArg; }
 
diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx
index c90bd94..656be6e 100644
--- a/sc/source/core/tool/docoptio.cxx
+++ b/sc/source/core/tool/docoptio.cxx
@@ -71,7 +71,8 @@ ScDocOptions::ScDocOptions( const ScDocOptions& rCpy )
             bMatchWholeCell( rCpy.bMatchWholeCell ),
             bDoAutoSpell( rCpy.bDoAutoSpell ),
             bLookUpColRowNames( rCpy.bLookUpColRowNames ),
-            bFormulaRegexEnabled( rCpy.bFormulaRegexEnabled )
+            bFormulaRegexEnabled( rCpy.bFormulaRegexEnabled ),
+            bWriteCalcConfig( rCpy.bWriteCalcConfig )
 {
 }
 
@@ -96,6 +97,7 @@ void ScDocOptions::ResetDocOptions()
     bDoAutoSpell        = false;
     bLookUpColRowNames  = true;
     bFormulaRegexEnabled= true;
+    bWriteCalcConfig    = true;
 }
 
 //      ScTpCalcItem - Daten fuer die CalcOptions-TabPage
diff --git a/sc/source/core/tool/formulaopt.cxx b/sc/source/core/tool/formulaopt.cxx
index 166429f..db1bc0b 100644
--- a/sc/source/core/tool/formulaopt.cxx
+++ b/sc/source/core/tool/formulaopt.cxx
@@ -36,6 +36,7 @@ ScFormulaOptions::ScFormulaOptions( const ScFormulaOptions& rCpy ) :
     bUseEnglishFuncName ( rCpy.bUseEnglishFuncName ),
     eFormulaGrammar     ( rCpy.eFormulaGrammar ),
     aCalcConfig(rCpy.aCalcConfig),
+    mbWriteCalcConfig   (rCpy.mbWriteCalcConfig),
     aFormulaSepArg      ( rCpy.aFormulaSepArg ),
     aFormulaSepArrayRow ( rCpy.aFormulaSepArrayRow ),
     aFormulaSepArrayCol ( rCpy.aFormulaSepArrayCol ),
@@ -52,6 +53,7 @@ void ScFormulaOptions::SetDefaults()
 {
     bUseEnglishFuncName = false;
     eFormulaGrammar     = ::formula::FormulaGrammar::GRAM_NATIVE;
+    mbWriteCalcConfig = true;
     meOOXMLRecalc = RECALC_ASK;
     meODFRecalc = RECALC_ASK;
 
@@ -129,6 +131,7 @@ ScFormulaOptions& ScFormulaOptions::operator=( const ScFormulaOptions& rCpy )
     bUseEnglishFuncName = rCpy.bUseEnglishFuncName;
     eFormulaGrammar     = rCpy.eFormulaGrammar;
     aCalcConfig = rCpy.aCalcConfig;
+    mbWriteCalcConfig = rCpy.mbWriteCalcConfig;
     aFormulaSepArg      = rCpy.aFormulaSepArg;
     aFormulaSepArrayRow = rCpy.aFormulaSepArrayRow;
     aFormulaSepArrayCol = rCpy.aFormulaSepArrayCol;
@@ -142,6 +145,7 @@ bool ScFormulaOptions::operator==( const ScFormulaOptions& rOpt ) const
     return bUseEnglishFuncName == rOpt.bUseEnglishFuncName
         && eFormulaGrammar     == rOpt.eFormulaGrammar
         && aCalcConfig == rOpt.aCalcConfig
+        && mbWriteCalcConfig   == rOpt.mbWriteCalcConfig
         && aFormulaSepArg      == rOpt.aFormulaSepArg
         && aFormulaSepArrayRow == rOpt.aFormulaSepArrayRow
         && aFormulaSepArrayCol == rOpt.aFormulaSepArrayCol
@@ -510,6 +514,10 @@ void ScFormulaCfg::ImplCommit()
     Sequence<OUString> aNames = GetPropertyNames();
     Sequence<Any> aValues(aNames.getLength());
     Any* pValues = aValues.getArray();
+
+    Sequence<Any> aOldValues = GetProperties(aNames);
+    Any* pOldValues = aOldValues.getArray();
+
     bool bSetOpenCL = false;
 
     for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
@@ -546,34 +554,57 @@ void ScFormulaCfg::ImplCommit()
             case SCFORMULAOPT_STRING_REF_SYNTAX:
             {
                 sal_Int32 nVal = -1;
-                switch (GetCalcConfig().meStringRefAddressSyntax)
+
+                if (GetWriteCalcConfig())
                 {
-                    case ::formula::FormulaGrammar::CONV_OOO:     nVal = 0; break;
-                    case ::formula::FormulaGrammar::CONV_XL_A1:   nVal = 1; break;
-                    case ::formula::FormulaGrammar::CONV_XL_R1C1: nVal = 2; break;
-                    case ::formula::FormulaGrammar::CONV_A1_XL_A1: nVal = 3; break;
-                    default: break;
+                    switch (GetCalcConfig().meStringRefAddressSyntax)
+                    {
+                        case ::formula::FormulaGrammar::CONV_OOO:     nVal = 0; break;
+                        case ::formula::FormulaGrammar::CONV_XL_A1:   nVal = 1; break;
+                        case ::formula::FormulaGrammar::CONV_XL_R1C1: nVal = 2; break;
+                        case ::formula::FormulaGrammar::CONV_A1_XL_A1: nVal = 3; break;
+                        default: break;
+                    }
+                    pValues[nProp] <<= nVal;
+                }
+                else
+                {
+                    pValues[nProp] = pOldValues[nProp];
                 }
-                pValues[nProp] <<= nVal;
             }
             break;
             case SCFORMULAOPT_STRING_CONVERSION:
             {
-                sal_Int32 nVal = 3;
-                switch (GetCalcConfig().meStringConversion)
+                if (GetWriteCalcConfig())
                 {
-                case ScCalcConfig::StringConversion::ILLEGAL:     nVal = 0; break;
-                case ScCalcConfig::StringConversion::ZERO:        nVal = 1; break;
-                case ScCalcConfig::StringConversion::UNAMBIGUOUS: nVal = 2; break;
-                case ScCalcConfig::StringConversion::LOCALE:      nVal = 3; break;
+                    sal_Int32 nVal = 3;
+
+                    switch (GetCalcConfig().meStringConversion)
+                    {
+                        case ScCalcConfig::StringConversion::ILLEGAL:     nVal = 0; break;
+                        case ScCalcConfig::StringConversion::ZERO:        nVal = 1; break;
+                        case ScCalcConfig::StringConversion::UNAMBIGUOUS: nVal = 2; break;
+                        case ScCalcConfig::StringConversion::LOCALE:      nVal = 3; break;
+                    }
+                    pValues[nProp] <<= nVal;
+                }
+                else
+                {
+                    pValues[nProp] = pOldValues[nProp];
                 }
-                pValues[nProp] <<= nVal;
             }
             break;
             case SCFORMULAOPT_EMPTY_OUSTRING_AS_ZERO:
             {
-                bool bVal = GetCalcConfig().mbEmptyStringAsZero;
-                pValues[nProp] <<= bVal;
+                if (GetWriteCalcConfig())
+                {
+                    bool bVal = GetCalcConfig().mbEmptyStringAsZero;
+                    pValues[nProp] <<= bVal;
+                }
+                else
+                {
+                    pValues[nProp] = pOldValues[nProp];
+                }
             }
             break;
             case SCFORMULAOPT_OOXML_RECALC:
diff --git a/sc/source/ui/inc/tpformula.hxx b/sc/source/ui/inc/tpformula.hxx
index 098a158..3c7ed8c 100644
--- a/sc/source/ui/inc/tpformula.hxx
+++ b/sc/source/ui/inc/tpformula.hxx
@@ -27,6 +27,7 @@
 #include <vcl/button.hxx>
 
 #include "calcconfig.hxx"
+#include "docoptio.hxx"
 
 class ScTpFormulaOptions : public SfxTabPage
 {
@@ -79,6 +80,9 @@ private:
     ScCalcConfig maSavedConfig;
     ScCalcConfig maCurrentConfig;
 
+    ScDocOptions maSavedDocOptions;
+    ScDocOptions maCurrentDocOptions;
+
     sal_Unicode mnDecSep;
 };
 
diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index fb213fc..7ddc4c8 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -76,11 +76,12 @@ sal_Int32 toSelectedItem( formula::FormulaGrammar::AddressConvention eConv )
 
 }
 
-ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfig& rConfig)
+ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfig& rConfig, bool bWriteConfig)
     : ModalDialog(pParent, "FormulaCalculationOptions",
         "modules/scalc/ui/formulacalculationoptions.ui")
     , maConfig(rConfig)
     , mbSelectedEmptyStringAsZero(rConfig.mbEmptyStringAsZero)
+    , mbWriteConfig(bWriteConfig)
 {
     get(mpTestButton, "test");
     get(mpOpenclInfoList, "opencl_list");
@@ -103,6 +104,10 @@ ScCalcOptionsDialog::ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfi
     mpSyntax->SelectEntryPos( toSelectedItem(rConfig.meStringRefAddressSyntax) );
     mpSyntax->SetSelectHdl(LINK(this, ScCalcOptionsDialog, SyntaxModifiedHdl));
 
+    get(mpCurrentDocOnly,"current_doc");
+    mpCurrentDocOnly->Check(!mbWriteConfig);
+    mpCurrentDocOnly->SetClickHdl(LINK(this, ScCalcOptionsDialog, CurrentDocOnlyHdl));
+
     get(mpUseOpenCL,"CBUseOpenCL");
     mpUseOpenCL->Check(rConfig.mbOpenCLSubsetOnly);
     mpUseOpenCL->SetClickHdl(LINK(this, ScCalcOptionsDialog, CBUseOpenCLHdl));
@@ -233,6 +238,11 @@ IMPL_LINK_TYPED(ScCalcOptionsDialog, SyntaxModifiedHdl, ListBox&, rSyntax, void)
     maConfig.SetStringRefSyntax(toAddressConvention(rSyntax.GetSelectEntryPos()));
 }
 
+IMPL_LINK_TYPED(ScCalcOptionsDialog, CurrentDocOnlyHdl, Button*, pCheckBox, void)
+{
+    mbWriteConfig = !(static_cast<CheckBox*>(pCheckBox)->IsChecked());
+}
+
 IMPL_LINK_TYPED(ScCalcOptionsDialog, CBUseOpenCLHdl, Button*, pCheckBox, void)
 {
     maConfig.mbOpenCLSubsetOnly = static_cast<CheckBox*>(pCheckBox)->IsChecked();
diff --git a/sc/source/ui/optdlg/calcoptionsdlg.hxx b/sc/source/ui/optdlg/calcoptionsdlg.hxx
index fe810fc..1d06251 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.hxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.hxx
@@ -34,7 +34,7 @@
 class ScCalcOptionsDialog : public ModalDialog
 {
 public:
-    ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfig& rConfig);
+    ScCalcOptionsDialog(vcl::Window* pParent, const ScCalcConfig& rConfig, bool bWriteConfig);
     virtual ~ScCalcOptionsDialog();
     virtual void dispose() override;
 
@@ -45,10 +45,12 @@ public:
     DECL_LINK_TYPED( AsZeroModifiedHdl, Button*, void);
     DECL_LINK_TYPED( ConversionModifiedHdl, ListBox&, void);
     DECL_LINK_TYPED( SyntaxModifiedHdl, ListBox&, void);
+    DECL_LINK_TYPED( CurrentDocOnlyHdl, Button*, void);
     DECL_LINK_TYPED( CBUseOpenCLHdl, Button*, void);
     DECL_LINK_TYPED( SpinOpenCLMinSizeHdl, Edit&, void);
 
     const ScCalcConfig& GetConfig() const { return maConfig;}
+    bool GetWriteCalcConfig() const { return mbWriteConfig;}
 
 private:
     void OpenCLAutomaticSelectionChanged();
@@ -59,6 +61,7 @@ private:
     VclPtr<CheckBox> mpEmptyAsZero;
     VclPtr<ListBox> mpConversion;
     VclPtr<ListBox> mpSyntax;
+    VclPtr<CheckBox> mpCurrentDocOnly;
 
     VclPtr<CheckBox> mpUseOpenCL;
     VclPtr<NumericField> mpSpinButton;
@@ -81,6 +84,7 @@ private:
 #endif
 
     bool mbSelectedEmptyStringAsZero;
+    bool mbWriteConfig;
 };
 
 #endif
diff --git a/sc/source/ui/optdlg/tpformula.cxx b/sc/source/ui/optdlg/tpformula.cxx
index e4817d1..789555d 100644
--- a/sc/source/ui/optdlg/tpformula.cxx
+++ b/sc/source/ui/optdlg/tpformula.cxx
@@ -77,6 +77,10 @@ ScTpFormulaOptions::ScTpFormulaOptions(vcl::Window* pParent, const SfxItemSet& r
     // Get the decimal separator for current locale.
     OUString aSep = ScGlobal::GetpLocaleData()->getNumDecimalSep();
     mnDecSep = aSep.isEmpty() ? sal_Unicode('.') : aSep[0];
+
+    maSavedDocOptions = ScDocOptions(
+        static_cast<const ScTpCalcItem&>(rCoreAttrs.Get(
+            GetWhich(SID_SCDOCOPTIONS))).GetDocOptions());
 }
 
 ScTpFormulaOptions::~ScTpFormulaOptions()
@@ -139,10 +143,12 @@ void ScTpFormulaOptions::UpdateCustomCalcRadioButtons(bool bDefault)
 
 void ScTpFormulaOptions::LaunchCustomCalcSettings()
 {
-    ScopedVclPtrInstance< ScCalcOptionsDialog > aDlg(this, maCurrentConfig);
+    ScopedVclPtrInstance< ScCalcOptionsDialog > aDlg(this, maCurrentConfig,
+                                                     maCurrentDocOptions.IsWriteCalcConfig());
     if (aDlg->Execute() == RET_OK)
     {
         maCurrentConfig = aDlg->GetConfig();
+        maCurrentDocOptions.SetWriteCalcConfig( aDlg->GetWriteCalcConfig());
     }
 }
 
@@ -260,7 +266,8 @@ bool ScTpFormulaOptions::FillItemSet(SfxItemSet* rCoreSet)
          || static_cast<OUString>(mpEdSepArrayRow->GetSavedValue()) != aSepArrayRow
          || mpLbOOXMLRecalcOptions->GetSavedValue() != nOOXMLRecalcMode
          || mpLbODFRecalcOptions->GetSavedValue() != nODFRecalcMode
-         || maSavedConfig != maCurrentConfig )
+         || maSavedConfig != maCurrentConfig
+         || maSavedDocOptions != maCurrentDocOptions )
     {
         ::formula::FormulaGrammar::Grammar eGram = ::formula::FormulaGrammar::GRAM_DEFAULT;
 
@@ -288,8 +295,11 @@ bool ScTpFormulaOptions::FillItemSet(SfxItemSet* rCoreSet)
         aOpt.SetCalcConfig(maCurrentConfig);
         aOpt.SetOOXMLRecalcOptions(eOOXMLRecalc);
         aOpt.SetODFRecalcOptions(eODFRecalc);
+        aOpt.SetWriteCalcConfig( maCurrentDocOptions.IsWriteCalcConfig());
 
         rCoreSet->Put( ScTpFormulaItem( SID_SCFORMULAOPTIONS, aOpt ) );
+        rCoreSet->Put( ScTpCalcItem( SID_SCDOCOPTIONS, maCurrentDocOptions ) );
+
         bRet = true;
     }
     return bRet;
@@ -362,6 +372,8 @@ void ScTpFormulaOptions::Reset(const SfxItemSet* rCoreSet)
     UpdateCustomCalcRadioButtons(bDefault);
 
     maCurrentConfig = maSavedConfig;
+
+    maCurrentDocOptions = maSavedDocOptions;
 }
 
 SfxTabPage::sfxpg ScTpFormulaOptions::DeactivatePage(SfxItemSet* /*pSet*/)
diff --git a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui
index 59641e6..bf1c6b0 100644
--- a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui
+++ b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui
@@ -110,6 +110,21 @@
                         <property name="top_attach">0</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkCheckButton" id="current_doc">
+                        <property name="label" translatable="yes">Apply those settings to current document only</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">3</property>
+                        <property name="width">2</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
               </object>


More information about the Libreoffice-commits mailing list