[Libreoffice-commits] core.git: include/sfx2 sc/source sfx2/source

Marco Cecchetti marco.cecchetti at collabora.com
Sat Nov 4 08:31:27 UTC 2017


 include/sfx2/viewsh.hxx        |    1 +
 sc/source/ui/app/inputhdl.cxx  |   12 ++++++++++++
 sc/source/ui/app/scmod.cxx     |    6 ++++++
 sc/source/ui/view/tabvwsh4.cxx |   26 ++++++++++++++++++++++++++
 sfx2/source/view/viewsh.cxx    |   31 +++++++++++++++++++++++++++++++
 5 files changed, 76 insertions(+)

New commits:
commit 52f2e70c9ef727a1a638d44fbabe76fc4b5a755a
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Sat Sep 30 17:51:26 2017 +0200

    lok: temporary workaround: disable formula mode for online
    
    - Start empty spreadsheet, open it with two users (let's call them A &
    B).
    - Type "=" with user A.
    - Start moving around to different cells with user B.
    
    => Cell name of user B's selected cell is entered in user A's formula.
    
    This is due to the fact that ScModel::GetInputHandler() returns always
    the input handler which is handling the edited formula and not the
    input handler of the current view.
    
    That really messes up collaborative editing, so better to disable it,
    until we implement an alternative solution.
    
    Change-Id: I6e779cba3f377d12b7a4a19a6ee53c924fc9ba20
    Reviewed-on: https://gerrit.libreoffice.org/43035
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index f186f8d4135a..d9467fb2aa47 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -168,6 +168,7 @@ protected:
 
 public:
     // Iteration
+    static size_t               GetActiveShells( bool bOnlyVisible = true );
     static SfxViewShell*        GetFirst( bool bOnlyVisible = true, const std::function<bool ( const SfxViewShell* )>& isViewShell = nullptr );
     static SfxViewShell*        GetNext( const SfxViewShell& rPrev,
                                          bool bOnlyVisible = true,
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 4d2036b2836f..aa5fec4e1a86 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -2373,6 +2373,18 @@ void ScInputHandler::UpdateFormulaMode()
             (rText[0] == '=' || rText[0] == '+' || rText[0] == '-');
     }
 
+    // formula mode in online is not usable in collaborative mode,
+    // this is a workaround for disabling formula mode in online
+    // when there is more than a single view
+    if (comphelper::LibreOfficeKit::isActive()
+        && SfxViewShell::GetActiveShells(/*only visible shells*/ false) > 1)
+    {
+        // we look for not visible shells, too, since this method can be
+        // invoked by a TabViewShell ctor and at such a stage the view
+        // is not yet visible,
+        bIsFormula = false;
+    }
+
     if ( bIsFormula )
     {
         if (!bFormulaMode)
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index c45e5d649ba9..414c8567bb93 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -1673,6 +1673,12 @@ bool ScModule::IsFormulaMode()
     //      Just keep function autopilot here for references to other documents
     bool bIsFormula = false;
 
+    // formula mode in online is not usable in collaborative mode,
+    // this is a workaround for disabling formula mode in online
+    // when there is more than a single view
+    if (comphelper::LibreOfficeKit::isActive() && SfxViewShell::GetActiveShells() > 1)
+            return false;
+
     if ( nCurRefDlgId )
     {
         SfxChildWindow* pChildWnd = lcl_GetChildWinFromAnyView( nCurRefDlgId );
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index f222d8a51019..d1f40a7bd313 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -1733,6 +1733,32 @@ ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
     //put things back as we found them
     if (bInstalledScTabViewObjAsTempController)
         GetViewData().GetDocShell()->GetModel()->setCurrentController(nullptr);
+
+    // formula mode in online is not usable in collaborative mode,
+    // this is a workaround for disabling formula mode in online
+    // when there is more than a single view
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+        // have we already one view ?
+        if (pViewShell)
+        {
+            // this view is not yet visible at this stage, so we look for not visible views, too
+            SfxViewShell* pViewShell2 = SfxViewShell::GetNext(*pViewShell, /*only visible shells*/ false);
+            // if the second view is not this one, it means that there is
+            // already more than one active view and so the formula mode
+            // has already been disabled
+            if (pViewShell2 && pViewShell2 == this)
+            {
+                ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
+                ScInputHandler* pInputHdl = pTabViewShell->GetInputHandler();
+                if (pInputHdl && pInputHdl->IsFormulaMode())
+                {
+                    pInputHdl->SetMode(SC_INPUT_NONE);
+                }
+            }
+        }
+    }
 }
 
 ScTabViewShell::~ScTabViewShell()
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 61a8d822a20c..107a27ba6899 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1308,6 +1308,37 @@ void SfxViewShell::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue
 }
 
 
+// returns the number of current available shells of spec. type viewing the specified doc.
+size_t SfxViewShell::GetActiveShells ( bool bOnlyVisible )
+{
+    size_t nShells = 0;
+
+    // search for a SfxViewShell of the specified type
+    SfxViewShellArr_Impl &rShells = SfxGetpApp()->GetViewShells_Impl();
+    SfxViewFrameArr_Impl &rFrames = SfxGetpApp()->GetViewFrames_Impl();
+    for (SfxViewShell* pShell : rShells)
+    {
+        if ( pShell )
+        {
+            // sometimes dangling SfxViewShells exist that point to a dead SfxViewFrame
+            // these ViewShells shouldn't be accessible anymore
+            // a destroyed ViewFrame is not in the ViewFrame array anymore, so checking this array helps
+            for (SfxViewFrame* pFrame : rFrames)
+            {
+                if ( pFrame == pShell->GetViewFrame() )
+                {
+                    // only ViewShells with a valid ViewFrame will be returned
+                    if ( !bOnlyVisible || pFrame->IsVisible() )
+                        ++nShells;
+                }
+            }
+        }
+    }
+
+    return nShells;
+}
+
+
 // returns the first shell of spec. type viewing the specified doc.
 SfxViewShell* SfxViewShell::GetFirst
 (


More information about the Libreoffice-commits mailing list