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

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Oct 13 09:59:46 PDT 2010


 sc/inc/docoptio.hxx                     |   11 ---
 sc/inc/optutil.hxx                      |    3 
 sc/source/core/tool/docoptio.cxx        |    4 -
 sc/source/ui/app/scmod.cxx              |   52 ++++++++++++++
 sc/source/ui/docshell/docsh.cxx         |  116 ++++++++++++++++++++++++++++++++
 sc/source/ui/inc/docsh.hxx              |    3 
 sc/source/ui/optdlg/tpcompatibility.cxx |   12 +--
 7 files changed, 185 insertions(+), 16 deletions(-)

New commits:
commit 220a15591a371989e9fccf40c14a86a6dfc82e1a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Oct 13 12:58:52 2010 -0400

    Initial attempt to reset key bindings.
    
    This is not working yet.  For some reason only the last key binding
    gets set, while all the others get ignored...

diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index 94d2787..19e3222 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -38,15 +38,10 @@
 
 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)
+    ScOptionsUtil::KeyBindingType eKeyBindingType;
     USHORT nDay;					// Nulldatum:
     USHORT nMonth;
     USHORT nYear;
@@ -102,8 +97,8 @@ 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; }
+    ScOptionsUtil::KeyBindingType GetKeyBindingType() const { return eKeyBindingType; }
+    void        SetKeyBindingType( ScOptionsUtil::KeyBindingType e ) { eKeyBindingType = e; }
 
     BOOL	IsCalcAsShown() const		{ return bCalcAsShown; }
     void	SetCalcAsShown( BOOL bVal )	{ bCalcAsShown = bVal; }
diff --git a/sc/inc/optutil.hxx b/sc/inc/optutil.hxx
index 708db82..b8addf3 100644
--- a/sc/inc/optutil.hxx
+++ b/sc/inc/optutil.hxx
@@ -36,6 +36,9 @@
 class ScOptionsUtil
 {
 public:
+    // values must correspond with integer values stored in the configuration
+    enum KeyBindingType { KEY_DEFAULT = 0, KEY_OOO_LEGACY = 1 };
+
     static BOOL		IsMetricSystem();
 };
 
diff --git a/sc/source/core/tool/docoptio.cxx b/sc/source/core/tool/docoptio.cxx
index 06ef113..ecc2669 100644
--- a/sc/source/core/tool/docoptio.cxx
+++ b/sc/source/core/tool/docoptio.cxx
@@ -127,7 +127,7 @@ void ScDocOptions::ResetDocOptions()
     nIterCount			= 100;
     fIterEps			= 1.0E-3;
     nPrecStandardFormat = SvNumberFormatter::UNLIMITED_PRECISION;
-    eKeyBindingType     = KEY_DEFAULT;
+    eKeyBindingType     = ScOptionsUtil::KEY_DEFAULT;
     nDay				= 30;
     nMonth				= 12;
     nYear				= 1899;
@@ -553,7 +553,7 @@ ScDocCfg::ScDocCfg() :
                     else
                         fprintf(stdout, "ScDocCfg::ScDocCfg:   key binding failed to load\n");
 
-                    SetKeyBindingType(static_cast<ScDocOptions::KeyBindingType>(nIntVal));
+                    SetKeyBindingType(static_cast<ScOptionsUtil::KeyBindingType>(nIntVal));
                 }
                 break;
             }
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index 93573c6..0af48a4 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -118,6 +118,49 @@
 #define SC_IDLE_STEP	75
 #define SC_IDLE_COUNT	50
 
+
+#include <stdio.h>
+#include <string>
+#include <sys/time.h>
+
+namespace {
+
+class StackPrinter
+{
+public:
+    explicit StackPrinter(const char* msg) :
+        msMsg(msg)
+    {
+        fprintf(stdout, "%s: --begin\n", msMsg.c_str());
+        mfStartTime = getTime();
+    }
+
+    ~StackPrinter()
+    {
+        double fEndTime = getTime();
+        fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime));
+    }
+
+    void printTime(int line) const
+    {
+        double fEndTime = getTime();
+        fprintf(stdout, "%s: --(%d) (duration: %g sec)\n", msMsg.c_str(), line, (fEndTime-mfStartTime));
+    }
+
+private:
+    double getTime() const
+    {
+        timeval tv;
+        gettimeofday(&tv, NULL);
+        return tv.tv_sec + tv.tv_usec / 1000000.0;
+    }
+
+    ::std::string msMsg;
+    double mfStartTime;
+};
+
+}
+
 static USHORT nIdleCount = 0;
 
 //------------------------------------------------------------------
@@ -1021,6 +1064,7 @@ USHORT ScModule::GetOptDigitLanguage()
 
 void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
 {
+    StackPrinter __stack_printer__("ScModule::ModifyOptions");
     USHORT nOldSpellLang, nOldCjkLang, nOldCtlLang;
     BOOL bOldAutoSpell;
     GetSpellSettings( nOldSpellLang, nOldCjkLang, nOldCtlLang, bOldAutoSpell );
@@ -1152,6 +1196,14 @@ void ScModule::ModifyOptions( const SfxItemSet& rOptSet )
         if ( pDoc )
         {
             const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
+            ScOptionsUtil::KeyBindingType eKeyOld = rOldOpt.GetKeyBindingType();
+            ScOptionsUtil::KeyBindingType eKeyNew = rNewOpt.GetKeyBindingType();
+            fprintf(stdout, "ScModule::ModifyOptions:   key (old: %d  new: %d)\n", eKeyOld, eKeyNew);
+            if (eKeyOld != eKeyNew)
+            {
+                fprintf(stdout, "ScModule::ModifyOptions:   key binding base changed.  Reset the key bindings.\n");
+                pDocSh->ResetKeyBindings(eKeyNew);
+            }
 
             bRepaint = ( bRepaint || ( rOldOpt != rNewOpt )   );
             bCalcAll =   bRepaint &&
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 4426f7a..420982a 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -65,12 +65,16 @@
 #include "chgtrack.hxx"
 #include "chgviset.hxx"
 #include <sfx2/request.hxx>
+#include <com/sun/star/awt/Key.hpp>
+#include <com/sun/star/awt/KeyModifier.hpp>
 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
 #include <com/sun/star/document/UpdateDocMode.hpp>
 #include <com/sun/star/script/vba/VBAEventId.hpp>
 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
 #include <com/sun/star/task/XJob.hpp>
+#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
 #include <basic/sbstar.hxx>
 #include <basic/basmgr.hxx>
 #include <vbahelper/vbaaccesshelper.hxx>
@@ -138,11 +142,57 @@
 #include <boost/shared_ptr.hpp>
 
 using namespace com::sun::star;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::UNO_QUERY;
+using ::com::sun::star::lang::XMultiServiceFactory;
 using ::rtl::OUString;
 using ::rtl::OUStringBuffer;
 using ::boost::shared_ptr;
 using ::std::vector;
 
+
+#include <stdio.h>
+#include <string>
+#include <sys/time.h>
+
+namespace {
+
+class StackPrinter
+{
+public:
+    explicit StackPrinter(const char* msg) :
+        msMsg(msg)
+    {
+        fprintf(stdout, "%s: --begin\n", msMsg.c_str());
+        mfStartTime = getTime();
+    }
+
+    ~StackPrinter()
+    {
+        double fEndTime = getTime();
+        fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime));
+    }
+
+    void printTime(int line) const
+    {
+        double fEndTime = getTime();
+        fprintf(stdout, "%s: --(%d) (duration: %g sec)\n", msMsg.c_str(), line, (fEndTime-mfStartTime));
+    }
+
+private:
+    double getTime() const
+    {
+        timeval tv;
+        gettimeofday(&tv, NULL);
+        return tv.tv_sec + tv.tv_usec / 1000000.0;
+    }
+
+    ::std::string msMsg;
+    double mfStartTime;
+};
+
+}
+
 // STATIC DATA -----------------------------------------------------------
 
 //	Stream-Namen im Storage
@@ -2795,6 +2845,72 @@ ScSheetSaveData* ScDocShell::GetSheetSaveData()
     return pSheetSaveData;
 }
 
+void ScDocShell::ResetKeyBindings( ScOptionsUtil::KeyBindingType eType )
+{
+    using namespace ::com::sun::star::ui;
+
+    StackPrinter __stack_printer__("ScDocShell::ResetKeyBindings");
+    Reference<XMultiServiceFactory> xServiceManager = ::comphelper::getProcessServiceFactory();
+    if (!xServiceManager.is())
+        return;
+
+    Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgSupplier(
+        xServiceManager->createInstance(
+            OUString::createFromAscii("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")), UNO_QUERY);
+
+    if (!xModuleCfgSupplier.is())
+        return;
+
+    // Grab the Calc configuration.
+    Reference<XUIConfigurationManager> xConfigMgr =
+        xModuleCfgSupplier->getUIConfigurationManager(
+            OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument"));
+
+    if (!xConfigMgr.is())
+        return;
+
+    // shortcut manager
+    Reference<XAcceleratorConfiguration> xScAccel(
+        xConfigMgr->getShortCutManager(), UNO_QUERY);
+
+    if (!xScAccel.is())
+        return;
+
+    // Backsapce key
+    awt::KeyEvent aBackEv;
+    aBackEv.KeyCode = awt::Key::BACKSPACE;
+    aBackEv.Modifiers = 0;
+
+    // Delete key
+    awt::KeyEvent aDeleteEv;
+    aDeleteEv.KeyCode = awt::Key::DELETE;
+    aDeleteEv.Modifiers = 0;
+
+    // Ctrl-D
+    awt::KeyEvent aCtrlD;
+    aCtrlD.KeyCode = awt::Key::D;
+    aCtrlD.Modifiers = awt::KeyModifier::MOD1;
+
+    switch (eType)
+    {
+        case ScOptionsUtil::KEY_DEFAULT:
+            fprintf(stdout, "ScDocShell::ResetKeyBindings:   default\n");
+            xScAccel->setKeyEvent(aDeleteEv, OUString::createFromAscii(".uno:ClearContents"));
+            xScAccel->setKeyEvent(aBackEv, OUString::createFromAscii(".uno:Delete"));
+        break;
+        case ScOptionsUtil::KEY_OOO_LEGACY:
+            fprintf(stdout, "ScDocShell::ResetKeyBindings:   ooo legacy\n");
+            xScAccel->setKeyEvent(aDeleteEv, OUString::createFromAscii(".uno:Delete"));
+            xScAccel->setKeyEvent(aBackEv, OUString::createFromAscii(".uno:ClearContents"));
+        break;
+        default:
+            ;
+    }
+
+    xScAccel->store();
+    fprintf(stdout, "ScDocShell::ResetKeyBindings:   stored\n");
+}
+
 void ScDocShell::UseSheetSaveEntries()
 {
     if (pSheetSaveData)
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index e021e9a..e8e8563 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -40,6 +40,7 @@
 #include "document.hxx"
 #include "shellids.hxx"
 #include "refreshtimer.hxx"
+#include "optutil.hxx"
 
 #include <hash_map>
 
@@ -425,6 +426,8 @@ public:
     //-->Added by PengYunQuan for Validity Cell Range Picker
     ScSheetSaveData* GetSheetSaveData();
 
+    void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
+
     // passwword protection for Calc (derived from SfxObjectShell)
     // see also:    FID_CHG_RECORD, SID_CHG_PROTECT
     virtual bool    IsChangeRecording() const;
diff --git a/sc/source/ui/optdlg/tpcompatibility.cxx b/sc/source/ui/optdlg/tpcompatibility.cxx
index c9853f3..1dfcafb 100644
--- a/sc/source/ui/optdlg/tpcompatibility.cxx
+++ b/sc/source/ui/optdlg/tpcompatibility.cxx
@@ -60,14 +60,14 @@ SfxTabPage* ScTpCompatOptions::Create(Window *pParent, const SfxItemSet &rCoreAt
 
 BOOL ScTpCompatOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 {
-    ScDocOptions::KeyBindingType eKeyB = ScDocOptions::KEY_DEFAULT;
+    ScOptionsUtil::KeyBindingType eKeyB = ScOptionsUtil::KEY_DEFAULT;
     switch (maLbKeyBindings.GetSelectEntryPos())
     {
         case 0:
-            eKeyB = ScDocOptions::KEY_DEFAULT;
+            eKeyB = ScOptionsUtil::KEY_DEFAULT;
         break;
         case 1:
-            eKeyB = ScDocOptions::KEY_OOO_LEGACY;
+            eKeyB = ScOptionsUtil::KEY_OOO_LEGACY;
         break;
         default:
             ;
@@ -85,13 +85,13 @@ BOOL ScTpCompatOptions::FillItemSet(SfxItemSet &rCoreAttrs)
 
 void ScTpCompatOptions::Reset(const SfxItemSet &rCoreAttrs)
 {
-    ScDocOptions::KeyBindingType eKeyB = mpOldOptions->GetKeyBindingType();
+    ScOptionsUtil::KeyBindingType eKeyB = mpOldOptions->GetKeyBindingType();
     switch (eKeyB)
     {
-        case ScDocOptions::KEY_DEFAULT:
+        case ScOptionsUtil::KEY_DEFAULT:
             maLbKeyBindings.SelectEntryPos(0);
         break;
-        case ScDocOptions::KEY_OOO_LEGACY:
+        case ScOptionsUtil::KEY_OOO_LEGACY:
             maLbKeyBindings.SelectEntryPos(1);
         break;
         default:


More information about the Libreoffice-commits mailing list