[Libreoffice-commits] .: Branch 'feature/calc-key-binding-compat' - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Oct 12 12:46:39 PDT 2010


 sc/inc/docoptio.hxx                     |   40 ++++++------------
 sc/source/core/tool/docoptio.cxx        |   71 +++++++++++++++++++++++++++++++-
 sc/source/ui/inc/tpcompatibility.hxx    |    6 ++
 sc/source/ui/optdlg/tpcompatibility.cxx |   40 +++++++++++++++++-
 4 files changed, 129 insertions(+), 28 deletions(-)

New commits:
commit 0d82cea0ed9b9e80d04d61cc2b5e4a50e10e2d4c
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Oct 12 15:44:56 2010 -0400

    Took care of loading and saving of the new option value.
    
    The new option value is now persistent with the Options dialog, but
    key bindings don't get reset yet.

diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index 3609eb4..94d2787 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -38,9 +38,15 @@
 
 class SC_DLLPUBLIC ScDocOptions
 {
+public:
+    // values must correspond with integer values stored in the configuration
+    enum KeyBindingType { KEY_DEFAULT = 0, KEY_OOO_LEGACY = 1 };
+
+private:
     double fIterEps;				// Epsilon-Wert dazu
     USHORT nIterCount;				// Anzahl
     sal_uInt16 nPrecStandardFormat; // precision for standard format
+    KeyBindingType eKeyBindingType; // key binding type: Default (0), OOo legacy (1)
     USHORT nDay;					// Nulldatum:
     USHORT nMonth;
     USHORT nYear;
@@ -88,7 +94,6 @@ public:
     void   SetTabDistance( USHORT nTabDist ) {nTabDistance = nTabDist;}
 
     void		ResetDocOptions();
-    inline void		CopyTo(ScDocOptions& rOpt);
 
     inline const ScDocOptions&	operator=( const ScDocOptions& rOpt );
     inline int					operator==( const ScDocOptions& rOpt ) const;
@@ -97,6 +102,9 @@ public:
     sal_uInt16  GetStdPrecision() const { return nPrecStandardFormat; }
     void        SetStdPrecision( sal_uInt16 n ) { nPrecStandardFormat = n; }
 
+    KeyBindingType GetKeyBindingType() const { return eKeyBindingType; }
+    void        SetKeyBindingType( KeyBindingType e ) { eKeyBindingType = e; }
+
     BOOL	IsCalcAsShown() const		{ return bCalcAsShown; }
     void	SetCalcAsShown( BOOL bVal )	{ bCalcAsShown = bVal; }
 
@@ -125,31 +133,6 @@ public:
     static const LocaleDataWrapper& GetLocaleDataWrapper();
 };
 
-
-inline void ScDocOptions::CopyTo(ScDocOptions& rOpt)
-{
-    rOpt.bIsIgnoreCase			= bIsIgnoreCase;
-    rOpt.bIsIter 				= bIsIter;
-    rOpt.nIterCount 			= nIterCount;
-    rOpt.fIterEps 				= fIterEps;
-    rOpt.nPrecStandardFormat 	= nPrecStandardFormat;
-    rOpt.nDay 					= nDay;
-    rOpt.nMonth 				= nMonth;
-    rOpt.nYear2000				= nYear2000;
-    rOpt.nYear 					= nYear;
-    rOpt.nTabDistance			= nTabDistance;
-    rOpt.bCalcAsShown			= bCalcAsShown;
-    rOpt.bMatchWholeCell		= bMatchWholeCell;
-    rOpt.bDoAutoSpell			= bDoAutoSpell;
-    rOpt.bLookUpColRowNames		= bLookUpColRowNames;
-    rOpt.bFormulaRegexEnabled   = bFormulaRegexEnabled;
-    rOpt.bUseEnglishFuncName    = bUseEnglishFuncName;
-    rOpt.eFormulaGrammar        = eFormulaGrammar;
-    rOpt.aFormulaSepArg         = aFormulaSepArg;
-    rOpt.aFormulaSepArrayRow    = aFormulaSepArrayRow;
-    rOpt.aFormulaSepArrayCol    = aFormulaSepArrayCol;
-}
-
 inline const ScDocOptions& ScDocOptions::operator=( const ScDocOptions& rCpy )
 {
     bIsIgnoreCase		= rCpy.bIsIgnoreCase;
@@ -157,6 +140,7 @@ inline const ScDocOptions& ScDocOptions::operator=( const ScDocOptions& rCpy )
     nIterCount			= rCpy.nIterCount;
     fIterEps			= rCpy.fIterEps;
     nPrecStandardFormat = rCpy.nPrecStandardFormat;
+    eKeyBindingType     = rCpy.eKeyBindingType;
     nDay				= rCpy.nDay;
     nMonth				= rCpy.nMonth;
     nYear				= rCpy.nYear;
@@ -184,6 +168,7 @@ inline int ScDocOptions::operator==( const ScDocOptions& rOpt ) const
             &&	rOpt.nIterCount 			== nIterCount
             &&	rOpt.fIterEps 				== fIterEps
             &&	rOpt.nPrecStandardFormat 	== nPrecStandardFormat
+            &&  rOpt.eKeyBindingType        == eKeyBindingType
             &&	rOpt.nDay 					== nDay
             &&	rOpt.nMonth 				== nMonth
             &&	rOpt.nYear 					== nYear
@@ -239,14 +224,17 @@ class ScDocCfg : public ScDocOptions
     ScLinkConfigItem	aCalcItem;
     ScLinkConfigItem    aFormulaItem;
     ScLinkConfigItem	aLayoutItem;
+    ScLinkConfigItem    aCompatItem;
 
     DECL_LINK( CalcCommitHdl, void* );
     DECL_LINK( FormulaCommitHdl, void* );
     DECL_LINK( LayoutCommitHdl, void* );
+    DECL_LINK( CompatCommitHdl, void* );
 
     com::sun::star::uno::Sequence<rtl::OUString> GetCalcPropertyNames();
     com::sun::star::uno::Sequence<rtl::OUString> GetFormulaPropertyNames();
     com::sun::star::uno::Sequence<rtl::OUString> GetLayoutPropertyNames();
+    com::sun::star::uno::Sequence<rtl::OUString> GetCompatPropertyNames();
 
 public:
             ScDocCfg();
diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx
index 83c204c..06ef113 100644
--- a/sc/source/core/tool/docoptio.cxx
+++ b/sc/source/core/tool/docoptio.cxx
@@ -91,6 +91,7 @@ ScDocOptions::ScDocOptions( const ScDocOptions& rCpy )
         :   fIterEps( rCpy.fIterEps ),
             nIterCount( rCpy.nIterCount ),
             nPrecStandardFormat( rCpy.nPrecStandardFormat ),
+            eKeyBindingType( rCpy.eKeyBindingType ),
             nDay( rCpy.nDay ),
             nMonth( rCpy.nMonth ),
             nYear( rCpy.nYear ),
@@ -126,6 +127,7 @@ void ScDocOptions::ResetDocOptions()
     nIterCount			= 100;
     fIterEps			= 1.0E-3;
     nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
+    eKeyBindingType     = KEY_DEFAULT;
     nDay				= 30;
     nMonth				= 12;
     nYear				= 1899;
@@ -283,6 +285,9 @@ SfxPoolItem* __EXPORT ScTpCalcItem::Clone( SfxItemPool * ) const
 #define SCDOCLAYOUTOPT_TABSTOP		0
 #define SCDOCLAYOUTOPT_COUNT		1
 
+#define CFGPATH_COMPAT      "Office.Calc/Compatibility"
+#define SCCOMPATOPT_KEY_BINDING     0
+#define SCCOMPATOPT_COUNT           1
 
 Sequence<OUString> ScDocCfg::GetCalcPropertyNames()
 {
@@ -345,10 +350,25 @@ Sequence<OUString> ScDocCfg::GetLayoutPropertyNames()
     return aNames;
 }
 
+Sequence<OUString> ScDocCfg::GetCompatPropertyNames()
+{
+    static const char* aPropNames[] =
+    {
+        "KeyBindings/BaseGroup"             // SCCOMPATOPT_KEY_BINDING
+    };
+    Sequence<OUString> aNames(SCCOMPATOPT_COUNT);
+    OUString* pNames = aNames.getArray();
+    for (int i = 0; i < SCCOMPATOPT_COUNT; ++i)
+        pNames[i] = OUString::createFromAscii(aPropNames[i]);
+
+    return aNames;
+}
+
 ScDocCfg::ScDocCfg() :
     aCalcItem( OUString::createFromAscii( CFGPATH_CALC ) ),
     aFormulaItem(OUString::createFromAscii(CFGPATH_FORMULA)),
-    aLayoutItem( OUString::createFromAscii( CFGPATH_DOCLAYOUT ) )
+    aLayoutItem(OUString::createFromAscii(CFGPATH_DOCLAYOUT)),
+    aCompatItem(OUString::createFromAscii(CFGPATH_COMPAT))
 {
     sal_Int32 nIntVal = 0;
     double fDoubleVal = 0;
@@ -513,6 +533,33 @@ ScDocCfg::ScDocCfg() :
         }
     }
     aLayoutItem.SetCommitLink( LINK( this, ScDocCfg, LayoutCommitHdl ) );
+
+    aNames = GetCompatPropertyNames();
+    aValues = aCompatItem.GetProperties(aNames);
+    aCompatItem.EnableNotification(aNames);
+    pValues = aValues.getConstArray();
+    if (aValues.getLength() == aNames.getLength())
+    {
+        for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
+        {
+            switch (nProp)
+            {
+                case SCCOMPATOPT_KEY_BINDING:
+                {
+                    fprintf(stdout, "ScDocCfg::ScDocCfg:   SCCOMPATOPT_KEY_BINDING\n");
+                    nIntVal = 0;
+                    if (pValues[nProp] >>= nIntVal)
+                        fprintf(stdout, "ScDocCfg::ScDocCfg:   key binding = %ld\n", nIntVal);
+                    else
+                        fprintf(stdout, "ScDocCfg::ScDocCfg:   key binding failed to load\n");
+
+                    SetKeyBindingType(static_cast<ScDocOptions::KeyBindingType>(nIntVal));
+                }
+                break;
+            }
+        }
+    }
+    aCompatItem.SetCommitLink( LINK(this, ScDocCfg, CompatCommitHdl) );
 }
 
 IMPL_LINK( ScDocCfg, CalcCommitHdl, void *, EMPTYARG )
@@ -637,6 +684,27 @@ IMPL_LINK( ScDocCfg, LayoutCommitHdl, void *, EMPTYARG )
     return 0;
 }
 
+IMPL_LINK( ScDocCfg, CompatCommitHdl, void *, EMPTYARG )
+{
+    Sequence<OUString> aNames = GetCompatPropertyNames();
+    Sequence<Any> aValues(aNames.getLength());
+    Any* pValues = aValues.getArray();
+
+    for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
+    {
+        switch(nProp)
+        {
+            case SCCOMPATOPT_KEY_BINDING:
+            {
+                fprintf(stdout, "IMPL_LINK:   pushing key binding type (%d)\n", GetKeyBindingType());
+                pValues[nProp] <<= static_cast<sal_Int32>(GetKeyBindingType());
+            }
+            break;
+        }
+    }
+    aCompatItem.PutProperties(aNames, aValues);
+    return 0;
+}
 
 void ScDocCfg::SetOptions( const ScDocOptions& rNew )
 {
@@ -645,6 +713,7 @@ void ScDocCfg::SetOptions( const ScDocOptions& rNew )
     aCalcItem.SetModified();
     aFormulaItem.SetModified();
     aLayoutItem.SetModified();
+    aCompatItem.SetModified();
 }
 
 
diff --git a/sc/source/ui/inc/tpcompatibility.hxx b/sc/source/ui/inc/tpcompatibility.hxx
index 75942c7..423ac2e 100644
--- a/sc/source/ui/inc/tpcompatibility.hxx
+++ b/sc/source/ui/inc/tpcompatibility.hxx
@@ -32,6 +32,10 @@
 #include <vcl/fixed.hxx>
 #include <vcl/lstbox.hxx>
 
+#include <boost/shared_ptr.hpp>
+
+class ScDocOptions;
+
 class ScTpCompatOptions : public SfxTabPage
 {
 public:
@@ -50,6 +54,8 @@ private:
     FixedText maFtKeyBindings;
     ListBox   maLbKeyBindings;
 
+    ::boost::shared_ptr<ScDocOptions> mpOldOptions;
+    ::boost::shared_ptr<ScDocOptions> mpNewOptions;
 };
 
 #endif
diff --git a/sc/source/ui/optdlg/tpcompatibility.cxx b/sc/source/ui/optdlg/tpcompatibility.cxx
index 7820dc4..c9853f3 100644
--- a/sc/source/ui/optdlg/tpcompatibility.cxx
+++ b/sc/source/ui/optdlg/tpcompatibility.cxx
@@ -33,6 +33,7 @@
 #include "tpcompatibility.hxx"
 #include "optdlg.hrc"
 #include "scresid.hxx"
+#include "docoptio.hxx"
 
 ScTpCompatOptions::ScTpCompatOptions(Window *pParent, const SfxItemSet &rCoreAttrs) :
     SfxTabPage(pParent, ScResId(RID_SCPAGE_COMPATIBILITY), rCoreAttrs),
@@ -41,6 +42,11 @@ ScTpCompatOptions::ScTpCompatOptions(Window *pParent, const SfxItemSet &rCoreAtt
     maLbKeyBindings(this, ScResId(LB_KEY_BINDINGS))
 {
     FreeResource();
+
+    const ScTpCalcItem& rItem = static_cast<const ScTpCalcItem&>(
+        rCoreAttrs.Get(GetWhich(SID_SCDOCOPTIONS)));
+    mpOldOptions.reset(new ScDocOptions(rItem.GetDocOptions()));
+    mpNewOptions.reset(new ScDocOptions(rItem.GetDocOptions()));
 }
 
 ScTpCompatOptions::~ScTpCompatOptions()
@@ -54,11 +60,43 @@ SfxTabPage* ScTpCompatOptions::Create(Window *pParent, const SfxItemSet &rCoreAt
 
 BOOL ScTpCompatOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 {
-    return false;
+    ScDocOptions::KeyBindingType eKeyB = ScDocOptions::KEY_DEFAULT;
+    switch (maLbKeyBindings.GetSelectEntryPos())
+    {
+        case 0:
+            eKeyB = ScDocOptions::KEY_DEFAULT;
+        break;
+        case 1:
+            eKeyB = ScDocOptions::KEY_OOO_LEGACY;
+        break;
+        default:
+            ;
+    }
+    mpNewOptions->SetKeyBindingType(eKeyB);
+
+    if (*mpNewOptions != *mpOldOptions)
+    {
+        rCoreAttrs.Put(ScTpCalcItem(GetWhich(SID_SCDOCOPTIONS), *mpNewOptions));
+        return true;
+    }
+    else
+        return false;
 }
 
 void ScTpCompatOptions::Reset(const SfxItemSet &rCoreAttrs)
 {
+    ScDocOptions::KeyBindingType eKeyB = mpOldOptions->GetKeyBindingType();
+    switch (eKeyB)
+    {
+        case ScDocOptions::KEY_DEFAULT:
+            maLbKeyBindings.SelectEntryPos(0);
+        break;
+        case ScDocOptions::KEY_OOO_LEGACY:
+            maLbKeyBindings.SelectEntryPos(1);
+        break;
+        default:
+            ;
+    }
 }
 
 int ScTpCompatOptions::DeactivatePage(SfxItemSet* /*pSet*/)


More information about the Libreoffice-commits mailing list